@@ -39,7 +39,7 @@ mod decl {
39
39
types:: PyStructSequence ,
40
40
} ;
41
41
use chrono:: {
42
- DateTime , Datelike , Timelike ,
42
+ DateTime , Datelike , TimeZone , Timelike ,
43
43
naive:: { NaiveDate , NaiveDateTime , NaiveTime } ,
44
44
} ;
45
45
use std:: time:: Duration ;
@@ -451,6 +451,8 @@ mod decl {
451
451
tm_wday : PyObjectRef ,
452
452
tm_yday : PyObjectRef ,
453
453
tm_isdst : PyObjectRef ,
454
+ tm_gmtoff : PyObjectRef ,
455
+ tm_zone : PyObjectRef ,
454
456
}
455
457
456
458
impl std:: fmt:: Debug for PyStructTime {
@@ -462,6 +464,11 @@ mod decl {
462
464
#[ pyclass( with( PyStructSequence ) ) ]
463
465
impl PyStructTime {
464
466
fn new ( vm : & VirtualMachine , tm : NaiveDateTime , isdst : i32 ) -> Self {
467
+ let local_time = chrono:: Local . from_local_datetime ( & tm) . unwrap ( ) ;
468
+ let offset_seconds =
469
+ local_time. offset ( ) . local_minus_utc ( ) + if isdst == 1 { 3600 } else { 0 } ;
470
+ let tz_abbr = local_time. format ( "%Z" ) . to_string ( ) ;
471
+
465
472
PyStructTime {
466
473
tm_year : vm. ctx . new_int ( tm. year ( ) ) . into ( ) ,
467
474
tm_mon : vm. ctx . new_int ( tm. month ( ) ) . into ( ) ,
@@ -472,6 +479,8 @@ mod decl {
472
479
tm_wday : vm. ctx . new_int ( tm. weekday ( ) . num_days_from_monday ( ) ) . into ( ) ,
473
480
tm_yday : vm. ctx . new_int ( tm. ordinal ( ) ) . into ( ) ,
474
481
tm_isdst : vm. ctx . new_int ( isdst) . into ( ) ,
482
+ tm_gmtoff : vm. ctx . new_int ( offset_seconds) . into ( ) ,
483
+ tm_zone : vm. ctx . new_str ( tz_abbr) . into ( ) ,
475
484
}
476
485
}
477
486
0 commit comments