From 82dbee4bbb495c7144ff6a0685bf049843699acf Mon Sep 17 00:00:00 2001 From: TheAwiteb Date: Thu, 7 Sep 2023 21:43:55 +0300 Subject: [PATCH] Fix deprecation error Use `DateTime::from_naive_utc_and_offset` instead of `DateTime::from_utc` --- crates/teloxide-core/src/types.rs | 8 +++++--- crates/teloxide-core/src/types/update.rs | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 371ab4c4..890dfb1a 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -269,7 +269,7 @@ pub(crate) fn serde_timestamp( NaiveDateTime::from_timestamp_opt(timestamp, 0) .ok_or_else(|| E::custom("invalid timestump")) - .map(|naive| DateTime::from_utc(naive, Utc)) + .map(|naive| DateTime::from_naive_utc_and_offset(naive, Utc)) } pub(crate) mod serde_opt_date_from_unix_timestamp { @@ -305,8 +305,10 @@ pub(crate) mod serde_opt_date_from_unix_timestamp { { let json = r#"{"date":1}"#; - let expected = - DateTime::from_utc(chrono::NaiveDateTime::from_timestamp_opt(1, 0).unwrap(), Utc); + let expected = DateTime::from_naive_utc_and_offset( + chrono::NaiveDateTime::from_timestamp_opt(1, 0).unwrap(), + Utc, + ); let Struct { date } = serde_json::from_str(json).unwrap(); assert_eq!(date, Some(expected)); diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 344ee63f..44a2eeeb 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -395,8 +395,10 @@ mod test { #[test] fn message() { let timestamp = 1_569_518_342; - let date = - DateTime::from_utc(NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(), Utc); + let date = DateTime::from_naive_utc_and_offset( + NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(), + Utc, + ); let json = r#"{ "update_id":892252934,