Skip to content

Commit

Permalink
fix:(driver): format timestamp & date as naive (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Apr 17, 2023
1 parent 3b4a450 commit 5ec418c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion driver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "databend-driver"
version = "0.2.12"
version = "0.2.13"
edition = "2021"
license = "Apache-2.0"
description = "Databend Driver for Rust"
Expand Down
13 changes: 11 additions & 2 deletions driver/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,17 @@ impl std::fmt::Display for Value {
Value::Boolean(b) => write!(f, "{}", b),
Value::Number(n) => write!(f, "{}", n),
Value::String(s) => write!(f, "{}", s),
Value::Timestamp(t) => write!(f, "{}", t),
Value::Date(d) => write!(f, "{}", d),
Value::Timestamp(i) => {
let secs = i / 1_000_000;
let nanos = ((i % 1_000_000) * 1000) as u32;
let t = NaiveDateTime::from_timestamp_opt(secs, nanos).unwrap_or_default();
write!(f, "{}", t)
}
Value::Date(i) => {
let days = i + 719_163;
let d = NaiveDate::from_num_days_from_ce_opt(days).unwrap_or_default();
write!(f, "{}", d)
}
}
}
}

0 comments on commit 5ec418c

Please sign in to comment.