@@ -41,6 +41,7 @@ mod decl {
4141 naive:: { NaiveDate , NaiveDateTime , NaiveTime } ,
4242 } ;
4343 use core:: time:: Duration ;
44+ use rustpython_host_env:: time:: { self as host_time, asctime_from_tm} ;
4445 #[ cfg( target_env = "msvc" ) ]
4546 #[ cfg( not( target_arch = "wasm32" ) ) ]
4647 use windows_sys:: Win32 :: System :: Time :: { GetTimeZoneInformation , TIME_ZONE_INFORMATION } ;
@@ -56,27 +57,24 @@ mod decl {
5657 }
5758
5859 #[ allow( dead_code) ]
59- pub ( super ) const SEC_TO_MS : i64 = 1000 ;
60+ pub ( super ) const SEC_TO_MS : i64 = host_time :: SEC_TO_MS ;
6061 #[ allow( dead_code) ]
61- pub ( super ) const MS_TO_US : i64 = 1000 ;
62+ pub ( super ) const MS_TO_US : i64 = host_time :: MS_TO_US ;
6263 #[ allow( dead_code) ]
63- pub ( super ) const SEC_TO_US : i64 = SEC_TO_MS * MS_TO_US ;
64+ pub ( super ) const SEC_TO_US : i64 = host_time :: SEC_TO_US ;
6465 #[ allow( dead_code) ]
65- pub ( super ) const US_TO_NS : i64 = 1000 ;
66+ pub ( super ) const US_TO_NS : i64 = host_time :: US_TO_NS ;
6667 #[ allow( dead_code) ]
67- pub ( super ) const MS_TO_NS : i64 = MS_TO_US * US_TO_NS ;
68+ pub ( super ) const MS_TO_NS : i64 = host_time :: MS_TO_NS ;
6869 #[ allow( dead_code) ]
69- pub ( super ) const SEC_TO_NS : i64 = SEC_TO_MS * MS_TO_NS ;
70+ pub ( super ) const SEC_TO_NS : i64 = host_time :: SEC_TO_NS ;
7071 #[ allow( dead_code) ]
71- pub ( super ) const NS_TO_MS : i64 = 1000 * 1000 ;
72+ pub ( super ) const NS_TO_MS : i64 = host_time :: NS_TO_MS ;
7273 #[ allow( dead_code) ]
73- pub ( super ) const NS_TO_US : i64 = 1000 ;
74+ pub ( super ) const NS_TO_US : i64 = host_time :: NS_TO_US ;
7475
7576 fn duration_since_system_now ( vm : & VirtualMachine ) -> PyResult < Duration > {
76- use std:: time:: { SystemTime , UNIX_EPOCH } ;
77-
78- SystemTime :: now ( )
79- . duration_since ( UNIX_EPOCH )
77+ host_time:: duration_since_system_now ( )
8078 . map_err ( |e| vm. new_value_error ( format ! ( "Time error: {e:?}" ) ) )
8179 }
8280
@@ -486,24 +484,6 @@ mod decl {
486484 }
487485 }
488486
489- #[ cfg( any( unix, windows) ) ]
490- fn asctime_from_tm ( tm : & libc:: tm ) -> String {
491- const WDAY_NAME : [ & str ; 7 ] = [ "Sun" , "Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" ] ;
492- const MON_NAME : [ & str ; 12 ] = [
493- "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" ,
494- ] ;
495- format ! (
496- "{} {}{:>3} {:02}:{:02}:{:02} {}" ,
497- WDAY_NAME [ tm. tm_wday as usize ] ,
498- MON_NAME [ tm. tm_mon as usize ] ,
499- tm. tm_mday,
500- tm. tm_hour,
501- tm. tm_min,
502- tm. tm_sec,
503- tm. tm_year + 1900
504- )
505- }
506-
507487 #[ cfg( not( any( unix, windows) ) ) ]
508488 impl OptionalArg < StructTimeData > {
509489 fn naive_or_local ( self , vm : & VirtualMachine ) -> PyResult < NaiveDateTime > {
0 commit comments