@@ -14,7 +14,7 @@ mod time {
14
14
} ;
15
15
use chrono:: {
16
16
naive:: { NaiveDate , NaiveDateTime , NaiveTime } ,
17
- Datelike , Timelike ,
17
+ DateTime , Datelike , Timelike ,
18
18
} ;
19
19
use std:: time:: Duration ;
20
20
@@ -110,17 +110,17 @@ mod time {
110
110
Ok ( get_perf_time ( vm) ?. as_nanos ( ) )
111
111
}
112
112
113
- fn pyobj_to_naive_date_time (
113
+ fn pyobj_to_date_time (
114
114
value : Either < f64 , i64 > ,
115
115
vm : & VirtualMachine ,
116
- ) -> PyResult < NaiveDateTime > {
116
+ ) -> PyResult < DateTime < chrono :: offset :: Utc > > {
117
117
let timestamp = match value {
118
118
Either :: A ( float) => {
119
119
let secs = float. trunc ( ) as i64 ;
120
120
let nsecs = ( float. fract ( ) * 1e9 ) as u32 ;
121
- NaiveDateTime :: from_timestamp_opt ( secs, nsecs)
121
+ DateTime :: < chrono :: offset :: Utc > :: from_timestamp ( secs, nsecs)
122
122
}
123
- Either :: B ( int) => NaiveDateTime :: from_timestamp_opt ( int, 0 ) ,
123
+ Either :: B ( int) => DateTime :: < chrono :: offset :: Utc > :: from_timestamp ( int, 0 ) ,
124
124
} ;
125
125
timestamp. ok_or_else ( || {
126
126
vm. new_overflow_error ( "timestamp out of range for platform time_t" . to_owned ( ) )
@@ -131,14 +131,14 @@ mod time {
131
131
/// Construct a localtime from the optional seconds, or get the current local time.
132
132
fn naive_or_local ( self , vm : & VirtualMachine ) -> PyResult < NaiveDateTime > {
133
133
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 ( ) ,
135
135
OptionalArg :: Missing => chrono:: offset:: Local :: now ( ) . naive_local ( ) ,
136
136
} )
137
137
}
138
138
139
139
fn naive_or_utc ( self , vm : & VirtualMachine ) -> PyResult < NaiveDateTime > {
140
140
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 ( ) ,
142
142
OptionalArg :: Missing => chrono:: offset:: Utc :: now ( ) . naive_utc ( ) ,
143
143
} )
144
144
}
@@ -174,7 +174,7 @@ mod time {
174
174
#[ pyfunction]
175
175
fn mktime ( t : PyStructTime , vm : & VirtualMachine ) -> PyResult < f64 > {
176
176
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 ;
178
178
Ok ( seconds_since_epoch)
179
179
}
180
180
0 commit comments