From 3f691de7a367d09424e443f15ebf01d75a6a0570 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Tue, 9 Apr 2024 04:13:39 +0900 Subject: [PATCH] Update chrono (#5220) --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- vm/src/stdlib/time.rs | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e220b1d5..f837c901f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,16 +229,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7d6c23a10..e3e470e9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ atty = "0.2.14" bitflags = "2.4.1" bstr = "0.2.17" cfg-if = "1.0" -chrono = "0.4.31" +chrono = "0.4.37" crossbeam-utils = "0.8.16" flame = "0.2.2" glob = "0.3" diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index 9717a6966..f023f6945 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -14,7 +14,7 @@ mod time { }; use chrono::{ naive::{NaiveDate, NaiveDateTime, NaiveTime}, - Datelike, Timelike, + DateTime, Datelike, Timelike, }; use std::time::Duration; @@ -110,17 +110,17 @@ mod time { Ok(get_perf_time(vm)?.as_nanos()) } - fn pyobj_to_naive_date_time( + fn pyobj_to_date_time( value: Either, vm: &VirtualMachine, - ) -> PyResult { + ) -> PyResult> { let timestamp = match value { Either::A(float) => { let secs = float.trunc() as i64; let nsecs = (float.fract() * 1e9) as u32; - NaiveDateTime::from_timestamp_opt(secs, nsecs) + DateTime::::from_timestamp(secs, nsecs) } - Either::B(int) => NaiveDateTime::from_timestamp_opt(int, 0), + Either::B(int) => DateTime::::from_timestamp(int, 0), }; timestamp.ok_or_else(|| { vm.new_overflow_error("timestamp out of range for platform time_t".to_owned()) @@ -131,14 +131,14 @@ mod time { /// Construct a localtime from the optional seconds, or get the current local time. fn naive_or_local(self, vm: &VirtualMachine) -> PyResult { Ok(match self { - OptionalArg::Present(secs) => pyobj_to_naive_date_time(secs, vm)?, + OptionalArg::Present(secs) => pyobj_to_date_time(secs, vm)?.naive_utc(), OptionalArg::Missing => chrono::offset::Local::now().naive_local(), }) } fn naive_or_utc(self, vm: &VirtualMachine) -> PyResult { Ok(match self { - OptionalArg::Present(secs) => pyobj_to_naive_date_time(secs, vm)?, + OptionalArg::Present(secs) => pyobj_to_date_time(secs, vm)?.naive_utc(), OptionalArg::Missing => chrono::offset::Utc::now().naive_utc(), }) } @@ -174,7 +174,7 @@ mod time { #[pyfunction] fn mktime(t: PyStructTime, vm: &VirtualMachine) -> PyResult { let datetime = t.to_date_time(vm)?; - let seconds_since_epoch = datetime.timestamp() as f64; + let seconds_since_epoch = datetime.and_utc().timestamp() as f64; Ok(seconds_since_epoch) }