Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c9efd4b

Browse filesBrowse files
JazzGlobalyouknowone
authored andcommitted
implement tm_gmtoff and tm_zone
1 parent 549cce2 commit c9efd4b
Copy full SHA for c9efd4b

File tree

1 file changed

+10
-1
lines changed
Filter options

1 file changed

+10
-1
lines changed

‎vm/src/stdlib/time.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/time.rs
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mod decl {
3939
types::PyStructSequence,
4040
};
4141
use chrono::{
42-
DateTime, Datelike, Timelike,
42+
DateTime, Datelike, TimeZone, Timelike,
4343
naive::{NaiveDate, NaiveDateTime, NaiveTime},
4444
};
4545
use std::time::Duration;
@@ -447,6 +447,8 @@ mod decl {
447447
tm_wday: PyObjectRef,
448448
tm_yday: PyObjectRef,
449449
tm_isdst: PyObjectRef,
450+
tm_gmtoff: PyObjectRef,
451+
tm_zone: PyObjectRef,
450452
}
451453

452454
impl std::fmt::Debug for PyStructTime {
@@ -458,6 +460,11 @@ mod decl {
458460
#[pyclass(with(PyStructSequence))]
459461
impl PyStructTime {
460462
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+
461468
PyStructTime {
462469
tm_year: vm.ctx.new_int(tm.year()).into(),
463470
tm_mon: vm.ctx.new_int(tm.month()).into(),
@@ -468,6 +475,8 @@ mod decl {
468475
tm_wday: vm.ctx.new_int(tm.weekday().num_days_from_monday()).into(),
469476
tm_yday: vm.ctx.new_int(tm.ordinal()).into(),
470477
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(),
471480
}
472481
}
473482

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.