@@ -44,6 +44,24 @@ mod inner {
4444 }
4545}
4646
47+ #[ cfg( all(
48+ target_arch = "wasm32" ,
49+ feature = "wasmbind" ,
50+ not( any( target_os = "emscripten" , target_os = "wasi" ) )
51+ ) ) ]
52+ mod inner {
53+ use crate :: { FixedOffset , LocalResult , NaiveDateTime } ;
54+
55+ pub ( super ) fn offset_from_utc_datetime ( _utc : & NaiveDateTime ) -> LocalResult < FixedOffset > {
56+ let offset = js_sys:: Date :: new_0 ( ) . get_timezone_offset ( ) ;
57+ LocalResult :: Single ( FixedOffset :: west_opt ( ( offset as i32 ) * 60 ) . unwrap ( ) )
58+ }
59+
60+ pub ( super ) fn offset_from_local_datetime ( local : & NaiveDateTime ) -> LocalResult < FixedOffset > {
61+ offset_from_utc_datetime ( local)
62+ }
63+ }
64+
4765#[ cfg( unix) ]
4866mod tz_info;
4967
@@ -119,21 +137,6 @@ impl TimeZone for Local {
119137 self . offset_from_local_datetime ( & local. and_time ( NaiveTime :: MIN ) )
120138 }
121139
122- #[ cfg( all(
123- target_arch = "wasm32" ,
124- feature = "wasmbind" ,
125- not( any( target_os = "emscripten" , target_os = "wasi" ) )
126- ) ) ]
127- fn offset_from_local_datetime ( & self , local : & NaiveDateTime ) -> LocalResult < FixedOffset > {
128- let offset = js_sys:: Date :: new_0 ( ) . get_timezone_offset ( ) ;
129- LocalResult :: Single ( FixedOffset :: west_opt ( ( offset as i32 ) * 60 ) . unwrap ( ) )
130- }
131-
132- #[ cfg( not( all(
133- target_arch = "wasm32" ,
134- feature = "wasmbind" ,
135- not( any( target_os = "emscripten" , target_os = "wasi" ) )
136- ) ) ) ]
137140 fn offset_from_local_datetime ( & self , local : & NaiveDateTime ) -> LocalResult < FixedOffset > {
138141 inner:: offset_from_local_datetime ( local)
139142 }
@@ -144,21 +147,6 @@ impl TimeZone for Local {
144147 self . offset_from_utc_datetime ( & utc. and_time ( NaiveTime :: MIN ) )
145148 }
146149
147- #[ cfg( all(
148- target_arch = "wasm32" ,
149- feature = "wasmbind" ,
150- not( any( target_os = "emscripten" , target_os = "wasi" ) )
151- ) ) ]
152- fn offset_from_utc_datetime ( & self , utc : & NaiveDateTime ) -> FixedOffset {
153- let offset = js_sys:: Date :: new_0 ( ) . get_timezone_offset ( ) ;
154- LocalResult :: Single ( FixedOffset :: west_opt ( ( offset as i32 ) * 60 ) . unwrap ( ) )
155- }
156-
157- #[ cfg( not( all(
158- target_arch = "wasm32" ,
159- feature = "wasmbind" ,
160- not( any( target_os = "emscripten" , target_os = "wasi" ) )
161- ) ) ) ]
162150 fn offset_from_utc_datetime ( & self , utc : & NaiveDateTime ) -> FixedOffset {
163151 inner:: offset_from_utc_datetime ( utc) . unwrap ( )
164152 }
0 commit comments