8000 Update chrono (#5220) · moreal/RustPython@3f691de · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f691de

Browse files
authored
Update chrono (RustPython#5220)
1 parent 2475728 commit 3f691de

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ atty = "0.2.14"
4747
bitflags = "2.4.1"
4848
bstr = "0.2.17"
4949
cfg-if = "1.0"
50-
chrono = "0.4.31"
50+
chrono = "0.4.37"
5151
crossbeam-utils = "0.8.16"
5252
flame = "0.2.2"
5353
glob = "0.3"

vm/src/stdlib/time.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod time {
1414
};
1515
use chrono::{
1616
naive::{NaiveDate, NaiveDateTime, NaiveTime},
17-
Datelike, Timelike,
17+
DateTime, Datelike, Timelike,
1818
};
1919
use std::time::Duration;
2020

@@ -110,17 +110,17 @@ mod time {
110110
Ok(get_perf_time(vm)?.as_nanos())
111111
}
112112

113-
fn pyobj_to_naive_date_time(
113+
fn pyobj_to_date_time(
114114
value: Either<f64, i64>,
115115
vm: &VirtualMachine,
116-
) -> PyResult<NaiveDateTime> {
116+
) -> PyResult<DateTime<chrono::offset::Utc>> {
117117
let timestamp = match value {
118118
Either::A(float) => {
119119
let secs = float.trunc() as i64;
120120
let nsecs = (float.fract() * 1e9) as u32;
121-
NaiveDateTime::from_timestamp_opt(secs, nsecs)
121+
DateTime::<chrono::offset::Utc>::from_timestamp(secs, nsecs)
122122
}
123-
Either::B(int) => NaiveDateTime::from_timestamp_opt(int, 0),
123+
Either::B(int) => DateTime::<chrono::offset::Utc>::from_timestamp(int, 0),
124124
};
125125
timestamp.ok_or_else(|| {
126126
vm.new_overflow_error("timestamp out of range for platform time_t".to_owned())
@@ -131,14 +131,14 @@ mod time {
131131
/// Construct a localtime from the optional seconds, or get the current local time.
132132
fn naive_or_local(self, vm: &VirtualMachine) -> PyResult<NaiveDateTime> {
133133
Ok(match self {
134-
OptionalArg::Present(secs) => pyobj_to_naive_date_time(secs, vm)?,
134+
OptionalArg::Present(secs) => pyobj_to_date_time(secs, vm)?.naive_utc(),
135135
OptionalArg::Missing => chrono::offset::Local::now().naive_local(),
136136
})
137137
}
138138

139139
fn naive_or_utc(self, vm: &VirtualMachine) -> PyResult<NaiveDateTime> {
140140
Ok(match self {
141-
OptionalArg::Present(secs) => pyobj_to_naive_date_time(secs, vm)?,
141+
OptionalArg::Present(secs) => pyobj_to_date_time(secs, vm)?.naive_utc(),
142142
OptionalArg::Missing => chrono::offset::Utc::now().naive_utc(),
143143
})
144144
}
@@ -174,7 +174,7 @@ mod time {
174174
#[pyfunction]
175175
fn mktime(t: PyStructTime, vm: &VirtualMachine) -> PyResult<f64> {
176176
let datetime = t.to_date_time(vm)?;
177-
let seconds_since_epoch = datetime.timestamp() as f64;
177+
let seconds_since_epoch = datetime.and_utc().timestamp() as f64;
178178
Ok(seconds_since_epoch)
179179
}
180180

0 commit comments

Comments
 (0)
0