From 29fdb4533f220f0d31cf23c05c2a1c174143071c Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 9 Apr 2024 07:46:54 +1000 Subject: [PATCH] refactor: use `chrono::DateTime::from_timestamp` (#23273) `chrono::NaiveDateTime::from_timestamp_opt()` was deprecated in https://github.com/chronotope/chrono/pull/1473. Prerequisite for #23272. --- cli/util/time.rs | 8 ++------ ext/cron/time.rs | 8 ++------ ext/kv/time.rs | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/cli/util/time.rs b/cli/util/time.rs index 2ecc35da6f7156..47306c1265424b 100644 --- a/cli/util/time.rs +++ b/cli/util/time.rs @@ -14,10 +14,6 @@ pub fn utc_now() -> chrono::DateTime { let now = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .expect("system time before Unix epoch"); - let naive = chrono::NaiveDateTime::from_timestamp_opt( - now.as_secs() as i64, - now.subsec_nanos(), - ) - .unwrap(); - chrono::DateTime::from_naive_utc_and_offset(naive, chrono::Utc) + chrono::DateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos()) + .unwrap() } diff --git a/ext/cron/time.rs b/ext/cron/time.rs index c39882f7b39988..3a5565332a06e8 100644 --- a/ext/cron/time.rs +++ b/ext/cron/time.rs @@ -10,10 +10,6 @@ pub fn utc_now() -> chrono::DateTime { let now = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .expect("system time before Unix epoch"); - let naive = chrono::NaiveDateTime::from_timestamp_opt( - now.as_secs() as i64, - now.subsec_nanos(), - ) - .unwrap(); - chrono::DateTime::from_naive_utc_and_offset(naive, chrono::Utc) + chrono::DateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos()) + .unwrap() } diff --git a/ext/kv/time.rs b/ext/kv/time.rs index c39882f7b39988..3a5565332a06e8 100644 --- a/ext/kv/time.rs +++ b/ext/kv/time.rs @@ -10,10 +10,6 @@ pub fn utc_now() -> chrono::DateTime { let now = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .expect("system time before Unix epoch"); - let naive = chrono::NaiveDateTime::from_timestamp_opt( - now.as_secs() as i64, - now.subsec_nanos(), - ) - .unwrap(); - chrono::DateTime::from_naive_utc_and_offset(naive, chrono::Utc) + chrono::DateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos()) + .unwrap() }