1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/cli/util/time.rs
Divy Srivastava 51649272bd
perf: do not depend on iana-time-zone (#18088)
Chrono's `clock` feature pulls in `iana-time-zone` which links to macOS
core_foundation. This PR itself is not enough to get rid of
CoreFoundation. Removal depends on getting rid of security framework,
see #18071
2023-03-15 07:14:22 +00:00

22 lines
842 B
Rust

// Copyright 2018-2023 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.
///
/// You can simply include this file in your project using
/// `include!("path/to/cli/util/time.rs"))` and use it
/// as a drop-in replacement for chrono::Utc::now().
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(
now.as_secs() as i64,
now.subsec_nanos(),
);
chrono::DateTime::from_utc(naive, chrono::Utc)
}