Skip to content

Navigation Menu

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 2fe44af

Browse filesBrowse files
committed
time.{tzname,timezone,daylight}
1 parent 515f0bf commit 2fe44af
Copy full SHA for 2fe44af

File tree

1 file changed

+60
-4
lines changed
Filter options

1 file changed

+60
-4
lines changed

‎vm/src/stdlib/time.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/time.rs
+60-4Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22
33
// See also:
44
// https://docs.python.org/3/library/time.html
5-
pub use time::*;
5+
use crate::{builtins::PyModule, PyRef, VirtualMachine};
6+
7+
pub use decl::time;
8+
9+
pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
10+
#[cfg(not(target_env = "msvc"))]
11+
#[cfg(not(target_arch = "wasm32"))]
12+
unsafe {
13+
c_tzset()
14+
};
15+
decl::make_module(vm)
16+
}
17+
18+
#[cfg(not(target_env = "msvc"))]
19+
#[cfg(not(target_arch = "wasm32"))]
20+
extern "C" {
21+
#[link_name = "daylight"]
22+
static c_daylight: std::ffi::c_int;
23+
// pub static dstbias: std::ffi::c_int;
24+
#[link_name = "timezone"]
25+
static c_timezone: std::ffi::c_long;
26+
#[link_name = "tzname"]
27+
static c_tzname: [*const std::ffi::c_char; 2];
28+
#[link_name = "tzset"]
29+
fn c_tzset();
30+
}
631

732
#[pymodule(name = "time", with(platform))]
8-
mod time {
33+
mod decl {
934
use crate::{
1035
builtins::{PyStrRef, PyTypeRef},
1136
function::{Either, FuncArgs, OptionalArg},
@@ -110,6 +135,37 @@ mod time {
110135
Ok(get_perf_time(vm)?.as_nanos())
111136
}
112137

138+
// #[pyfunction]
139+
// fn tzset() {
140+
// unsafe { super::_tzset() };
141+
// }
142+
143+
#[cfg(not(target_env = "msvc"))]
144+
#[cfg(not(target_arch = "wasm32"))]
145+
#[pyattr]
146+
fn timezone(_vm: &VirtualMachine) -> std::ffi::c_long {
147+
unsafe { super::c_timezone }
148+
}
149+
150+
#[cfg(not(target_env = "msvc"))]
151+
#[cfg(not(target_arch = "wasm32"))]
152+
#[pyattr]
153+
fn daylight(_vm: &VirtualMachine) -> std::ffi::c_int {
154+
unsafe { super::c_daylight }
155+
}
156+
157+
#[cfg(not(target_env = "msvc"))]
158+
#[cfg(not(target_arch = "wasm32"))]
159+
#[pyattr]
160+
fn tzname(vm: &VirtualMachine) -> crate::builtins::PyTupleRef {
161+
use crate::builtins::tuple::IntoPyTuple;
162+
163+
unsafe fn to_str(s: *const std::ffi::c_char) -> String {
164+
std::ffi::CStr::from_ptr(s).to_string_lossy().into_owned()
165+
}
166+
unsafe { (to_str(super::c_tzname[0]), to_str(super::c_tzname[1])) }.into_pytuple(vm)
167+
}
168+
113169
fn pyobj_to_date_time(
114170
value: Either<f64, i64>,
115171
vm: &VirtualMachine,
@@ -384,7 +440,7 @@ mod time {
384440
#[pymodule(sub)]
385441
mod platform {
386442
#[allow(unused_imports)]
387-
use super::{SEC_TO_NS, US_TO_NS};
443+
use super::decl::{SEC_TO_NS, US_TO_NS};
388444
#[cfg_attr(target_os = "macos", allow(unused_imports))]
389445
use crate::{
390446
builtins::{PyNamespace, PyStrRef},
@@ -621,7 +677,7 @@ mod platform {
621677
#[cfg(windows)]
622678
#[pymodule]
623679
mod platform {
624-
use super::{time_muldiv, MS_TO_NS, SEC_TO_NS};
680+
use super::decl::{time_muldiv, MS_TO_NS, SEC_TO_NS};
625681
use crate::{
626682
builtins::{PyNamespace, PyStrRef},
627683
stdlib::os::errno_err,

0 commit comments

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