diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/cron/lib.rs | 1 | ||||
-rw-r--r-- | ext/cron/local.rs | 10 | ||||
-rw-r--r-- | ext/cron/time.rs | 15 | ||||
-rw-r--r-- | ext/kv/Cargo.toml | 2 | ||||
-rw-r--r-- | ext/kv/lib.rs | 4 | ||||
-rw-r--r-- | ext/kv/time.rs | 15 |
6 files changed, 7 insertions, 40 deletions
diff --git a/ext/cron/lib.rs b/ext/cron/lib.rs index 4f4d0e05c..a0f1c44e1 100644 --- a/ext/cron/lib.rs +++ b/ext/cron/lib.rs @@ -2,7 +2,6 @@ mod interface; pub mod local; -mod time; use std::borrow::Cow; use std::cell::RefCell; diff --git a/ext/cron/local.rs b/ext/cron/local.rs index 945df0796..dd60e750a 100644 --- a/ext/cron/local.rs +++ b/ext/cron/local.rs @@ -91,7 +91,7 @@ impl LocalCronHandler { .copied(); let sleep_fut = if let Some(earliest_deadline) = earliest_deadline { - let now = crate::time::utc_now().timestamp_millis() as u64; + let now = chrono::Utc::now().timestamp_millis() as u64; if let Some(delta) = earliest_deadline.checked_sub(now) { tokio::time::sleep(std::time::Duration::from_millis(delta)).boxed() } else { @@ -121,7 +121,7 @@ impl LocalCronHandler { { let backoff_ms = backoff_schedule[cron.current_execution_retries as usize]; - let now = crate::time::utc_now().timestamp_millis() as u64; + let now = chrono::Utc::now().timestamp_millis() as u64; cron.current_execution_retries += 1; now + backoff_ms as u64 } else { @@ -155,7 +155,7 @@ impl RuntimeState { fn get_ready_crons( &mut self, ) -> Result<Vec<(String, WeakSender<()>)>, AnyError> { - let now = crate::time::utc_now().timestamp_millis() as u64; + let now = chrono::Utc::now().timestamp_millis() as u64; let ready = { let to_remove = self @@ -301,7 +301,7 @@ impl CronHandle for CronExecutionHandle { } fn compute_next_deadline(cron_expression: &str) -> Result<u64, AnyError> { - let now = crate::time::utc_now(); + let now = chrono::Utc::now(); if let Ok(test_schedule) = env::var("DENO_CRON_TEST_SCHEDULE_OFFSET") { if let Ok(offset) = test_schedule.parse::<u64>() { @@ -334,7 +334,7 @@ mod tests { #[test] fn test_compute_next_deadline() { - let now = crate::time::utc_now().timestamp_millis() as u64; + let now = chrono::Utc::now().timestamp_millis() as u64; assert!(compute_next_deadline("*/1 * * * *").unwrap() > now); assert!(compute_next_deadline("* * * * *").unwrap() > now); assert!(compute_next_deadline("bogus").is_err()); diff --git a/ext/cron/time.rs b/ext/cron/time.rs deleted file mode 100644 index 3a5565332..000000000 --- a/ext/cron/time.rs +++ /dev/null @@ -1,15 +0,0 @@ -// 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() -} diff --git a/ext/kv/Cargo.toml b/ext/kv/Cargo.toml index 12a0e2c90..7349d5841 100644 --- a/ext/kv/Cargo.toml +++ b/ext/kv/Cargo.toml @@ -17,7 +17,7 @@ path = "lib.rs" anyhow.workspace = true async-trait.workspace = true base64.workspace = true -chrono.workspace = true +chrono = { workspace = true, features = ["now"] } deno_core.workspace = true deno_fetch.workspace = true deno_node.workspace = true diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs index 72e1cab30..285614389 100644 --- a/ext/kv/lib.rs +++ b/ext/kv/lib.rs @@ -4,7 +4,6 @@ pub mod dynamic; mod interface; pub mod remote; pub mod sqlite; -mod time; use std::borrow::Cow; use std::cell::RefCell; @@ -56,7 +55,6 @@ use denokv_proto::WatchStream; use log::debug; use serde::Deserialize; use serde::Serialize; -use time::utc_now; pub use crate::interface::*; @@ -772,7 +770,7 @@ async fn op_kv_atomic_write<DBH>( where DBH: DatabaseHandler + 'static, { - let current_timestamp = utc_now(); + let current_timestamp = chrono::Utc::now(); let db = { let state = state.borrow(); let resource = diff --git a/ext/kv/time.rs b/ext/kv/time.rs deleted file mode 100644 index 3a5565332..000000000 --- a/ext/kv/time.rs +++ /dev/null @@ -1,15 +0,0 @@ -// 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() -} |