2
2
3
3
// See also:
4
4
// 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
+ unsafe {
12
+ c_tzset ( )
13
+ } ;
14
+ decl:: make_module ( vm)
15
+ }
16
+
17
+ #[ cfg( not( target_env = "msvc" ) ) ]
18
+ extern "C" {
19
+ #[ link_name = "daylight" ]
20
+ static c_daylight: std:: ffi:: c_int ;
21
+ // pub static dstbias: std::ffi::c_int;
22
+ #[ link_name = "timezone" ]
23
+ static c_timezone: std:: ffi:: c_long ;
24
+ #[ link_name = "tzname" ]
25
+ static c_tzname: [ * const std:: ffi:: c_char ; 2 ] ;
26
+ #[ link_name = "tzset" ]
27
+ fn c_tzset ( ) ;
28
+ }
6
29
7
30
#[ pymodule( name = "time" , with( platform) ) ]
8
- mod time {
31
+ mod decl {
9
32
use crate :: {
10
33
builtins:: { PyStrRef , PyTypeRef } ,
11
34
function:: { Either , FuncArgs , OptionalArg } ,
@@ -110,6 +133,34 @@ mod time {
110
133
Ok ( get_perf_time ( vm) ?. as_nanos ( ) )
111
134
}
112
135
136
+ // #[pyfunction]
137
+ // fn tzset() {
138
+ // unsafe { super::_tzset() };
139
+ // }
140
+
141
+ #[ cfg( not( target_env = "msvc" ) ) ]
142
+ #[ pyattr]
143
+ fn timezone ( _vm : & VirtualMachine ) -> std:: ffi:: c_long {
144
+ unsafe { super :: c_timezone }
145
+ }
146
+
147
+ #[ cfg( not( target_env = "msvc" ) ) ]
148
+ #[ pyattr]
149
+ fn daylight ( _vm : & VirtualMachine ) -> std:: ffi:: c_int {
150
+ unsafe { super :: c_daylight }
151
+ }
152
+
153
+ #[ cfg( not( target_env = "msvc" ) ) ]
154
+ #[ pyattr]
155
+ fn tzname ( vm : & VirtualMachine ) -> crate :: builtins:: PyTupleRef {
156
+ use crate :: builtins:: tuple:: IntoPyTuple ;
157
+
158
+ unsafe fn to_str ( s : * const std:: ffi:: c_char ) -> String {
159
+ std:: ffi:: CStr :: from_ptr ( s) . to_string_lossy ( ) . into_owned ( )
160
+ }
161
+ unsafe { ( to_str ( super :: c_tzname[ 0 ] ) , to_str ( super :: c_tzname[ 1 ] ) ) } . into_pytuple ( vm)
162
+ }
163
+
113
164
fn pyobj_to_date_time (
114
165
value : Either < f64 , i64 > ,
115
166
vm : & VirtualMachine ,
@@ -384,7 +435,7 @@ mod time {
384
435
#[ pymodule( sub) ]
385
436
mod platform {
386
437
#[ allow( unused_imports) ]
387
- use super :: { SEC_TO_NS , US_TO_NS } ;
438
+ use super :: decl :: { SEC_TO_NS , US_TO_NS } ;
388
439
#[ cfg_attr( target_os = "macos" , allow( unused_imports) ) ]
389
440
use crate :: {
390
441
builtins:: { PyNamespace , PyStrRef } ,
@@ -621,7 +672,7 @@ mod platform {
621
672
#[ cfg( windows) ]
622
673
#[ pymodule]
623
674
mod platform {
624
- use super :: { time_muldiv, MS_TO_NS , SEC_TO_NS } ;
675
+ use super :: decl :: { time_muldiv, MS_TO_NS , SEC_TO_NS } ;
625
676
use crate :: {
626
677
builtins:: { PyNamespace , PyStrRef } ,
627
678
stdlib:: os:: errno_err,
0 commit comments