@@ -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 ;
@@ -447,6 +447,8 @@ mod decl {
447
447
tm_wday : PyObjectRef ,
448
448
tm_yday : PyObjectRef ,
449
449
tm_isdst : PyObjectRef ,
450
+ tm_gmtoff : PyObjectRef ,
451
+ tm_zone : PyObjectRef ,
450
452
}
451
453
452
454
impl std:: fmt:: Debug for PyStructTime {
@@ -458,6 +460,11 @@ mod decl {
458
460
#[ pyclass( with( PyStructSequence ) ) ]
459
461
impl PyStructTime {
460
462
fn new ( vm : & VirtualMachine , tm : NaiveDateTime , isdst : i32 ) -> Self {
463
+ let local_time = chrono:: Local . from_local_datetime ( & tm) . unwrap ( ) ;
464
+ let offset_seconds =
465
+ local_time. offset ( ) . local_minus_utc ( ) + if isdst == 1 { 3600 } else { 0 } ;
466
+ let tz_abbr = local_time. format ( "%Z" ) . to_string ( ) ;
467
+
461
468
PyStructTime {
462
469
tm_year : vm. ctx . new_int ( tm. year ( ) ) . into ( ) ,
463
470
tm_mon : vm. ctx . new_int ( tm. month ( ) ) . into ( ) ,
@@ -468,6 +475,8 @@ mod decl {
468
475
tm_wday : vm. ctx . new_int ( tm. weekday ( ) . num_days_from_monday ( ) ) . into ( ) ,
469
476
tm_yday : vm. ctx . new_int ( tm. ordinal ( ) ) . into ( ) ,
470
477
tm_isdst : vm. ctx . new_int ( isdst) . into ( ) ,
478
+ tm_gmtoff : vm. ctx . new_int ( offset_seconds) . into ( ) ,
479
+ tm_zone : vm. ctx . new_str ( tz_abbr) . into ( ) ,
471
480
}
472
481
}
473
482
0 commit comments