mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update chrono (#5220)
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -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]]
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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<f64, i64>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<NaiveDateTime> {
|
||||
) -> PyResult<DateTime<chrono::offset::Utc>> {
|
||||
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::<chrono::offset::Utc>::from_timestamp(secs, nsecs)
|
||||
}
|
||||
Either::B(int) => NaiveDateTime::from_timestamp_opt(int, 0),
|
||||
Either::B(int) => DateTime::<chrono::offset::Utc>::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<NaiveDateTime> {
|
||||
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<NaiveDateTime> {
|
||||
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<f64> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user