summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-10-30 08:45:45 -0700
committerGitHub <noreply@github.com>2023-10-30 11:45:45 -0400
commit1acef755ca8a0a0433a98e4a66433c63ee0a3b09 (patch)
tree015ce439d800e8e35916d498de3780e6ee03e0df
parent02cc37e05494e576ea8e120b9fe21b447da9546b (diff)
chore: remove usage of chrono::Utc::now() (#20995)
Remove usage of Chrono's clock feature which pulls in iana-time-zone -> core-foundation
-rw-r--r--Cargo.lock50
-rw-r--r--Cargo.toml4
-rw-r--r--cli/tools/jupyter/jupyter_msg.rs5
-rw-r--r--ext/kv/lib.rs4
-rw-r--r--ext/kv/remote.rs2
-rw-r--r--ext/kv/time.rs19
6 files changed, 28 insertions, 56 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c5fb440f1..ea7e774f3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -136,21 +136,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
[[package]]
-name = "android-tzdata"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
-
-[[package]]
-name = "android_system_properties"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
-dependencies = [
- "libc",
-]
-
-[[package]]
name = "anstream"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -553,11 +538,8 @@ version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [
- "android-tzdata",
- "iana-time-zone",
"num-traits",
"serde",
- "windows-targets",
]
[[package]]
@@ -2841,29 +2823,6 @@ dependencies = [
]
[[package]]
-name = "iana-time-zone"
-version = "0.1.57"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"
-dependencies = [
- "android_system_properties",
- "core-foundation-sys",
- "iana-time-zone-haiku",
- "js-sys",
- "wasm-bindgen",
- "windows",
-]
-
-[[package]]
-name = "iana-time-zone-haiku"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
-dependencies = [
- "cc",
-]
-
-[[package]]
name = "idna"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -6543,15 +6502,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
-name = "windows"
-version = "0.48.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
-dependencies = [
- "windows-targets",
-]
-
-[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 7b967a16f..c2765ab66 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -78,7 +78,9 @@ brotli = "3.3.4"
bytes = "1.4.0"
cache_control = "=0.2.0"
cbc = { version = "=0.1.2", features = ["alloc"] }
-chrono = { version = "0.4", default-features = false, features = ["std", "serde", "clock"] }
+# Note: Do not use the "clock" feature of chrono, as it links us to CoreFoundation on macOS.
+# Instead use util::time::utc_now()
+chrono = { version = "0.4", default-features = false, features = ["std", "serde"] }
console_static_text = "=0.8.1"
data-url = "=0.3.0"
data-encoding = "2.3.3"
diff --git a/cli/tools/jupyter/jupyter_msg.rs b/cli/tools/jupyter/jupyter_msg.rs
index da6654cae..8540a7f37 100644
--- a/cli/tools/jupyter/jupyter_msg.rs
+++ b/cli/tools/jupyter/jupyter_msg.rs
@@ -4,7 +4,6 @@
// Copyright 2020 The Evcxr Authors. MIT license.
use bytes::Bytes;
-use chrono::Utc;
use data_encoding::HEXLOWER;
use deno_core::anyhow::anyhow;
use deno_core::anyhow::bail;
@@ -15,6 +14,8 @@ use ring::hmac;
use std::fmt;
use uuid::Uuid;
+use crate::util::time::utc_now;
+
pub(crate) struct Connection<S> {
pub(crate) socket: S,
/// Will be None if our key was empty (digest authentication disabled).
@@ -177,7 +178,7 @@ impl JupyterMessage {
header["msg_type"] = serde_json::Value::String(msg_type.to_owned());
header["username"] = serde_json::Value::String("kernel".to_owned());
header["msg_id"] = serde_json::Value::String(Uuid::new_v4().to_string());
- header["date"] = serde_json::Value::String(Utc::now().to_rfc3339());
+ header["date"] = serde_json::Value::String(utc_now().to_rfc3339());
JupyterMessage {
zmq_identities: Vec::new(),
diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs
index 20f774033..fb68596fa 100644
--- a/ext/kv/lib.rs
+++ b/ext/kv/lib.rs
@@ -6,6 +6,7 @@ mod interface;
mod proto;
pub mod remote;
pub mod sqlite;
+mod time;
use std::borrow::Cow;
use std::cell::RefCell;
@@ -14,7 +15,6 @@ use std::rc::Rc;
use base64::prelude::BASE64_URL_SAFE;
use base64::Engine;
-use chrono::Utc;
use codec::decode_key;
use codec::encode_key;
use deno_core::anyhow::Context;
@@ -610,7 +610,7 @@ async fn op_kv_atomic_write<DBH>(
where
DBH: DatabaseHandler + 'static,
{
- let current_timestamp = Utc::now().timestamp_millis() as u64;
+ let current_timestamp = time::utc_now().timestamp_millis() as u64;
let db = {
let state = state.borrow();
let resource =
diff --git a/ext/kv/remote.rs b/ext/kv/remote.rs
index 38b233cc3..0a061b35b 100644
--- a/ext/kv/remote.rs
+++ b/ext/kv/remote.rs
@@ -426,7 +426,7 @@ async fn metadata_refresh_task(
metadata
.expires_at
.timestamp_millis()
- .saturating_sub(Utc::now().timestamp_millis()),
+ .saturating_sub(crate::time::utc_now().timestamp_millis()),
)
.unwrap_or_default();
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)
+}