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.
This commit is contained in:
Asher Gomez 2024-04-09 07:46:54 +10:00 committed by GitHub
parent 214bfa37aa
commit 6157c85634
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 18 deletions

View File

@ -14,10 +14,6 @@ pub fn utc_now() -> chrono::DateTime<chrono::Utc> {
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()
}

View File

@ -10,10 +10,6 @@ pub fn utc_now() -> chrono::DateTime<chrono::Utc> {
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()
}

View File

@ -10,10 +10,6 @@ pub fn utc_now() -> chrono::DateTime<chrono::Utc> {
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()
}