mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
chore: remove usage of chrono::Utc::now() (#20995)
Remove usage of Chrono's clock feature which pulls in iana-time-zone -> core-foundation
This commit is contained in:
parent
02cc37e054
commit
1acef755ca
6 changed files with 28 additions and 56 deletions
50
Cargo.lock
generated
50
Cargo.lock
generated
|
@ -135,21 +135,6 @@ version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
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]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
|
@ -553,11 +538,8 @@ version = "0.4.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
|
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
|
||||||
"iana-time-zone",
|
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"serde",
|
"serde",
|
||||||
"windows-targets",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2840,29 +2822,6 @@ dependencies = [
|
||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[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]]
|
[[package]]
|
||||||
name = "idna"
|
name = "idna"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
|
@ -6542,15 +6501,6 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
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]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.48.0"
|
version = "0.48.0"
|
||||||
|
|
|
@ -78,7 +78,9 @@ brotli = "3.3.4"
|
||||||
bytes = "1.4.0"
|
bytes = "1.4.0"
|
||||||
cache_control = "=0.2.0"
|
cache_control = "=0.2.0"
|
||||||
cbc = { version = "=0.1.2", features = ["alloc"] }
|
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"
|
console_static_text = "=0.8.1"
|
||||||
data-url = "=0.3.0"
|
data-url = "=0.3.0"
|
||||||
data-encoding = "2.3.3"
|
data-encoding = "2.3.3"
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
// Copyright 2020 The Evcxr Authors. MIT license.
|
// Copyright 2020 The Evcxr Authors. MIT license.
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use chrono::Utc;
|
|
||||||
use data_encoding::HEXLOWER;
|
use data_encoding::HEXLOWER;
|
||||||
use deno_core::anyhow::anyhow;
|
use deno_core::anyhow::anyhow;
|
||||||
use deno_core::anyhow::bail;
|
use deno_core::anyhow::bail;
|
||||||
|
@ -15,6 +14,8 @@ use ring::hmac;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::util::time::utc_now;
|
||||||
|
|
||||||
pub(crate) struct Connection<S> {
|
pub(crate) struct Connection<S> {
|
||||||
pub(crate) socket: S,
|
pub(crate) socket: S,
|
||||||
/// Will be None if our key was empty (digest authentication disabled).
|
/// 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["msg_type"] = serde_json::Value::String(msg_type.to_owned());
|
||||||
header["username"] = serde_json::Value::String("kernel".to_owned());
|
header["username"] = serde_json::Value::String("kernel".to_owned());
|
||||||
header["msg_id"] = serde_json::Value::String(Uuid::new_v4().to_string());
|
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 {
|
JupyterMessage {
|
||||||
zmq_identities: Vec::new(),
|
zmq_identities: Vec::new(),
|
||||||
|
|
|
@ -6,6 +6,7 @@ mod interface;
|
||||||
mod proto;
|
mod proto;
|
||||||
pub mod remote;
|
pub mod remote;
|
||||||
pub mod sqlite;
|
pub mod sqlite;
|
||||||
|
mod time;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -14,7 +15,6 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use base64::prelude::BASE64_URL_SAFE;
|
use base64::prelude::BASE64_URL_SAFE;
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use chrono::Utc;
|
|
||||||
use codec::decode_key;
|
use codec::decode_key;
|
||||||
use codec::encode_key;
|
use codec::encode_key;
|
||||||
use deno_core::anyhow::Context;
|
use deno_core::anyhow::Context;
|
||||||
|
@ -610,7 +610,7 @@ async fn op_kv_atomic_write<DBH>(
|
||||||
where
|
where
|
||||||
DBH: DatabaseHandler + 'static,
|
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 db = {
|
||||||
let state = state.borrow();
|
let state = state.borrow();
|
||||||
let resource =
|
let resource =
|
||||||
|
|
|
@ -426,7 +426,7 @@ async fn metadata_refresh_task(
|
||||||
metadata
|
metadata
|
||||||
.expires_at
|
.expires_at
|
||||||
.timestamp_millis()
|
.timestamp_millis()
|
||||||
.saturating_sub(Utc::now().timestamp_millis()),
|
.saturating_sub(crate::time::utc_now().timestamp_millis()),
|
||||||
)
|
)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
|
19
ext/kv/time.rs
Normal file
19
ext/kv/time.rs
Normal file
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in a new issue