diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-10-30 08:45:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-30 11:45:45 -0400 |
commit | 1acef755ca8a0a0433a98e4a66433c63ee0a3b09 (patch) | |
tree | 015ce439d800e8e35916d498de3780e6ee03e0df /ext/kv/time.rs | |
parent | 02cc37e05494e576ea8e120b9fe21b447da9546b (diff) |
chore: remove usage of chrono::Utc::now() (#20995)
Remove usage of Chrono's clock feature which pulls in iana-time-zone ->
core-foundation
Diffstat (limited to 'ext/kv/time.rs')
-rw-r--r-- | ext/kv/time.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/kv/time.rs b/ext/kv/time.rs new file mode 100644 index 000000000..60375818b --- /dev/null +++ b/ext/kv/time.rs @@ -0,0 +1,19 @@ +// 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. +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) +} |