mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
refactor: remove custom utc_now
in favor of chrono::Utc:now
feature (#23888)
This PR removes the use of the custom `utc_now` function in favor of the `chrono` implementation. It resolves #22864. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
fa27350977
commit
fa1ba256d2
14 changed files with 15 additions and 73 deletions
|
@ -86,7 +86,7 @@ base64.workspace = true
|
||||||
bincode = "=1.3.3"
|
bincode = "=1.3.3"
|
||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
cache_control.workspace = true
|
cache_control.workspace = true
|
||||||
chrono.workspace = true
|
chrono = { workspace = true, features = ["now"] }
|
||||||
clap = { version = "=4.4.17", features = ["env", "string"] }
|
clap = { version = "=4.4.17", features = ["env", "string"] }
|
||||||
clap_complete = "=4.4.7"
|
clap_complete = "=4.4.7"
|
||||||
clap_complete_fig = "=4.4.2"
|
clap_complete_fig = "=4.4.2"
|
||||||
|
|
|
@ -17,8 +17,6 @@ use std::process::Stdio;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use test_util::PathRef;
|
use test_util::PathRef;
|
||||||
|
|
||||||
include!("../util/time.rs");
|
|
||||||
|
|
||||||
mod http;
|
mod http;
|
||||||
mod lsp;
|
mod lsp;
|
||||||
|
|
||||||
|
@ -442,7 +440,8 @@ async fn main() -> Result<()> {
|
||||||
env::set_current_dir(test_util::root_path())?;
|
env::set_current_dir(test_util::root_path())?;
|
||||||
|
|
||||||
let mut new_data = BenchResult {
|
let mut new_data = BenchResult {
|
||||||
created_at: utc_now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
created_at: chrono::Utc::now()
|
||||||
|
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
||||||
sha1: test_util::run_collect(
|
sha1: test_util::run_collect(
|
||||||
&["git", "rev-parse", "HEAD"],
|
&["git", "rev-parse", "HEAD"],
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -399,7 +399,7 @@ impl CoverageReporter for HtmlCoverageReporter {
|
||||||
|
|
||||||
fn done(&mut self, coverage_root: &Path) {
|
fn done(&mut self, coverage_root: &Path) {
|
||||||
let summary = self.collect_summary(&self.file_reports);
|
let summary = self.collect_summary(&self.file_reports);
|
||||||
let now = crate::util::time::utc_now().to_rfc2822();
|
let now = chrono::Utc::now().to_rfc2822();
|
||||||
|
|
||||||
for (node, stats) in &summary {
|
for (node, stats) in &summary {
|
||||||
let report_path =
|
let report_path =
|
||||||
|
|
|
@ -10,7 +10,6 @@ use crate::http_util::HttpClient;
|
||||||
use crate::standalone::binary::unpack_into_dir;
|
use crate::standalone::binary::unpack_into_dir;
|
||||||
use crate::util::progress_bar::ProgressBar;
|
use crate::util::progress_bar::ProgressBar;
|
||||||
use crate::util::progress_bar::ProgressBarStyle;
|
use crate::util::progress_bar::ProgressBarStyle;
|
||||||
use crate::util::time;
|
|
||||||
use crate::version;
|
use crate::version;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
@ -60,7 +59,7 @@ impl RealUpdateCheckerEnvironment {
|
||||||
Self {
|
Self {
|
||||||
cache_file_path,
|
cache_file_path,
|
||||||
// cache the current time
|
// cache the current time
|
||||||
current_time: time::utc_now(),
|
current_time: chrono::Utc::now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -785,7 +784,7 @@ mod test {
|
||||||
current_version: Default::default(),
|
current_version: Default::default(),
|
||||||
is_canary: Default::default(),
|
is_canary: Default::default(),
|
||||||
latest_version: Rc::new(RefCell::new(Ok("".to_string()))),
|
latest_version: Rc::new(RefCell::new(Ok("".to_string()))),
|
||||||
time: Rc::new(RefCell::new(crate::util::time::utc_now())),
|
time: Rc::new(RefCell::new(chrono::Utc::now())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ pub mod progress_bar;
|
||||||
pub mod result;
|
pub mod result;
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
pub mod text_encoding;
|
pub mod text_encoding;
|
||||||
pub mod time;
|
|
||||||
pub mod unix;
|
pub mod unix;
|
||||||
pub mod v8;
|
pub mod v8;
|
||||||
pub mod windows;
|
pub mod windows;
|
||||||
|
|
|
@ -1,19 +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.
|
|
||||||
///
|
|
||||||
/// 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");
|
|
||||||
chrono::DateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos())
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
mod interface;
|
mod interface;
|
||||||
pub mod local;
|
pub mod local;
|
||||||
mod time;
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl LocalCronHandler {
|
||||||
.copied();
|
.copied();
|
||||||
|
|
||||||
let sleep_fut = if let Some(earliest_deadline) = earliest_deadline {
|
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) {
|
if let Some(delta) = earliest_deadline.checked_sub(now) {
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(delta)).boxed()
|
tokio::time::sleep(std::time::Duration::from_millis(delta)).boxed()
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,7 +121,7 @@ impl LocalCronHandler {
|
||||||
{
|
{
|
||||||
let backoff_ms =
|
let backoff_ms =
|
||||||
backoff_schedule[cron.current_execution_retries as usize];
|
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;
|
cron.current_execution_retries += 1;
|
||||||
now + backoff_ms as u64
|
now + backoff_ms as u64
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,7 +155,7 @@ impl RuntimeState {
|
||||||
fn get_ready_crons(
|
fn get_ready_crons(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Result<Vec<(String, WeakSender<()>)>, AnyError> {
|
) -> 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 ready = {
|
||||||
let to_remove = self
|
let to_remove = self
|
||||||
|
@ -301,7 +301,7 @@ impl CronHandle for CronExecutionHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_next_deadline(cron_expression: &str) -> Result<u64, AnyError> {
|
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(test_schedule) = env::var("DENO_CRON_TEST_SCHEDULE_OFFSET") {
|
||||||
if let Ok(offset) = test_schedule.parse::<u64>() {
|
if let Ok(offset) = test_schedule.parse::<u64>() {
|
||||||
|
@ -334,7 +334,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_compute_next_deadline() {
|
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("*/1 * * * *").unwrap() > now);
|
||||||
assert!(compute_next_deadline("* * * * *").unwrap() > now);
|
assert!(compute_next_deadline("* * * * *").unwrap() > now);
|
||||||
assert!(compute_next_deadline("bogus").is_err());
|
assert!(compute_next_deadline("bogus").is_err());
|
||||||
|
|
|
@ -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()
|
|
||||||
}
|
|
|
@ -17,7 +17,7 @@ path = "lib.rs"
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
base64.workspace = true
|
base64.workspace = true
|
||||||
chrono.workspace = true
|
chrono = { workspace = true, features = ["now"] }
|
||||||
deno_core.workspace = true
|
deno_core.workspace = true
|
||||||
deno_fetch.workspace = true
|
deno_fetch.workspace = true
|
||||||
deno_node.workspace = true
|
deno_node.workspace = true
|
||||||
|
|
|
@ -4,7 +4,6 @@ pub mod dynamic;
|
||||||
mod interface;
|
mod interface;
|
||||||
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;
|
||||||
|
@ -56,7 +55,6 @@ use denokv_proto::WatchStream;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use time::utc_now;
|
|
||||||
|
|
||||||
pub use crate::interface::*;
|
pub use crate::interface::*;
|
||||||
|
|
||||||
|
@ -772,7 +770,7 @@ async fn op_kv_atomic_write<DBH>(
|
||||||
where
|
where
|
||||||
DBH: DatabaseHandler + 'static,
|
DBH: DatabaseHandler + 'static,
|
||||||
{
|
{
|
||||||
let current_timestamp = utc_now();
|
let current_timestamp = chrono::Utc::now();
|
||||||
let db = {
|
let db = {
|
||||||
let state = state.borrow();
|
let state = state.borrow();
|
||||||
let resource =
|
let resource =
|
||||||
|
|
|
@ -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()
|
|
||||||
}
|
|
|
@ -33,7 +33,7 @@ required-features = ["run"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
chrono.workspace = true
|
chrono = { workspace = true, features = ["now"] }
|
||||||
deno_ast.workspace = true
|
deno_ast.workspace = true
|
||||||
deno_bench_util.workspace = true
|
deno_bench_util.workspace = true
|
||||||
deno_cache_dir = { workspace = true }
|
deno_cache_dir = { workspace = true }
|
||||||
|
|
|
@ -25,9 +25,6 @@ use zeromq::SocketRecv;
|
||||||
use zeromq::SocketSend;
|
use zeromq::SocketSend;
|
||||||
use zeromq::ZmqMessage;
|
use zeromq::ZmqMessage;
|
||||||
|
|
||||||
// for the `utc_now` function
|
|
||||||
include!("../../cli/util/time.rs");
|
|
||||||
|
|
||||||
/// Jupyter connection file format
|
/// Jupyter connection file format
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct ConnectionSpec {
|
struct ConnectionSpec {
|
||||||
|
@ -138,7 +135,7 @@ impl Default for MsgHeader {
|
||||||
Self {
|
Self {
|
||||||
msg_id: Uuid::new_v4(),
|
msg_id: Uuid::new_v4(),
|
||||||
session: Uuid::new_v4(),
|
session: Uuid::new_v4(),
|
||||||
date: utc_now(),
|
date: chrono::Utc::now(),
|
||||||
username: "test".into(),
|
username: "test".into(),
|
||||||
msg_type: "kernel_info_request".into(),
|
msg_type: "kernel_info_request".into(),
|
||||||
version: "5.3".into(),
|
version: "5.3".into(),
|
||||||
|
|
Loading…
Reference in a new issue