Skip to content

Commit 6cda0f2

Browse files
committed
Add support for time::UtcDateTime
This was not a thing at the time this PR was opened, but was added in time 0.3.38
1 parent 13968a1 commit 6cda0f2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

influxdb/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ serde_derive = { version = "1.0.186", optional = true }
2828
serde_json = { version = "1.0.48", optional = true }
2929
surf = { version = "2.2.0", default-features = false, optional = true }
3030
thiserror = "1.0"
31-
time = { version = "0.3.34", optional = true }
31+
time = { version = "0.3.39", optional = true }
3232

3333
[features]
3434
default = ["serde", "reqwest-client-rustls"]

influxdb/src/query/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ where
8787
}
8888
}
8989

90+
#[cfg(feature = "time")]
91+
impl From<Timestamp> for time::UtcDateTime {
92+
fn from(value: Timestamp) -> Self {
93+
time::UtcDateTime::from_unix_timestamp_nanos(value.nanos() as i128).unwrap()
94+
}
95+
}
96+
97+
#[cfg(feature = "time")]
98+
impl From<time::UtcDateTime> for Timestamp {
99+
fn from(value: time::UtcDateTime) -> Self {
100+
Timestamp::Nanoseconds(value.unix_timestamp_nanos() as u128)
101+
}
102+
}
103+
90104
#[cfg(feature = "time")]
91105
impl From<Timestamp> for time::OffsetDateTime {
92106
fn from(value: Timestamp) -> Self {

0 commit comments

Comments
 (0)