1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/ext/cron/time.rs
Asher Gomez 6157c85634
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.
2024-04-08 21:46:54 +00:00

15 lines
605 B
Rust

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/// Identical to chrono::Utc::now() but without the system "clock"
/// feature flag.
///
/// The "clock" feature flag pulls in the "iana-time-zone" crate
/// which links to macOS's "CoreFoundation" framework which increases
/// startup time for the CLI.
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");
chrono::DateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos())
.unwrap()
}