From 94eb1d5ec55f8874ea71e00ccfded5ef1be96a6b Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:31:51 +0100 Subject: [PATCH] build(deps): update chrono and replace deprecated fn calls --- proto/Cargo.toml | 2 +- proto/src/serializers/timestamp.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 430b464..3a7f060 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -33,7 +33,7 @@ time = { version = "0.3", default-features = false, features = [ "parsing", ] } flex-error = { version = "0.4.4", default-features = false } -chrono = { version = "0.4.24", default-features = false } +chrono = { version = "0.4.35", default-features = false } derive_more = { version = "0.99.17" } diff --git a/proto/src/serializers/timestamp.rs b/proto/src/serializers/timestamp.rs index 945f881..41bf1f0 100644 --- a/proto/src/serializers/timestamp.rs +++ b/proto/src/serializers/timestamp.rs @@ -47,8 +47,9 @@ pub trait ToMilis { impl ToMilis for Timestamp { /// Convert protobuf timestamp into miliseconds since epoch fn to_milis(&self) -> u64 { - chrono::NaiveDateTime::from_timestamp_opt(self.seconds, self.nanos as u32) + chrono::DateTime::from_timestamp(self.seconds, self.nanos as u32) .unwrap() + .to_utc() .timestamp_millis() .try_into() .expect("timestamp value out of u64 range") @@ -75,12 +76,13 @@ impl FromMilis for Timestamp { /// /// Panics when `millis` don't fit `i64` type fn from_milis(millis: u64) -> Self { - let dt = chrono::NaiveDateTime::from_timestamp_millis( + let dt = chrono::DateTime::from_timestamp_millis( millis .try_into() .expect("milliseconds timestamp out of i64 range"), ) - .expect("cannot parse timestamp"); + .expect("cannot parse timestamp") + .to_utc(); Self { nanos: dt.timestamp_subsec_nanos() as i32,