@@ -11,7 +11,13 @@ use super::{LocalResult, TimeZone};
1111use crate :: naive:: { NaiveDate , NaiveDateTime } ;
1212use crate :: { Date , DateTime } ;
1313
14- #[ cfg( all( not( unix) , not( windows) ) ) ]
14+ // we don't want `stub.rs` when the target_os is not wasi or emscripten
15+ // as we use js-sys to get the date instead
16+ #[ cfg( all(
17+ not( unix) ,
18+ not( windows) ,
19+ not( all( target_arch = "wasm32" , not( any( target_os = "emscripten" , target_os = "wasi" ) ) ) )
20+ ) ) ]
1521#[ path = "stub.rs" ]
1622mod inner;
1723
@@ -51,13 +57,16 @@ impl Local {
5157 }
5258
5359 /// Returns a `DateTime` which corresponds to the current date and time.
54- #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "wasi" ) , feature = "wasmbind" ) ) ) ]
60+ #[ cfg( not( all(
61+ target_arch = "wasm32" ,
62+ not( any( target_os = "emscripten" , target_os = "wasi" ) )
63+ ) ) ) ]
5564 pub fn now ( ) -> DateTime < Local > {
5665 inner:: now ( )
5766 }
5867
5968 /// Returns a `DateTime` which corresponds to the current date and time.
60- #[ cfg( all( target_arch = "wasm32" , not( target_os = "wasi" ) , feature = "wasmbind" ) ) ]
69+ #[ cfg( all( target_arch = "wasm32" , not( any ( target_os = "emscripten" , target_os = "wasi" ) ) ) ) ]
6170 pub fn now ( ) -> DateTime < Local > {
6271 use super :: Utc ;
6372 let now: DateTime < Utc > = super :: Utc :: now ( ) ;
@@ -101,7 +110,7 @@ impl TimeZone for Local {
101110 midnight. map ( |datetime| Date :: from_utc ( * local, * datetime. offset ( ) ) )
102111 }
103112
104- #[ cfg( all( target_arch = "wasm32" , not( target_os = "wasi" ) , feature = "wasmbind" ) ) ]
113+ #[ cfg( all( target_arch = "wasm32" , not( any ( target_os = "emscripten" , target_os = "wasi" ) ) ) ) ]
105114 fn from_local_datetime ( & self , local : & NaiveDateTime ) -> LocalResult < DateTime < Local > > {
106115 let mut local = local. clone ( ) ;
107116 // Get the offset from the js runtime
@@ -110,7 +119,10 @@ impl TimeZone for Local {
110119 LocalResult :: Single ( DateTime :: from_utc ( local, offset) )
111120 }
112121
113- #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "wasi" ) , feature = "wasmbind" ) ) ) ]
122+ #[ cfg( not( all(
123+ target_arch = "wasm32" ,
124+ not( any( target_os = "emscripten" , target_os = "wasi" ) )
125+ ) ) ) ]
114126 fn from_local_datetime ( & self , local : & NaiveDateTime ) -> LocalResult < DateTime < Local > > {
115127 inner:: naive_to_local ( local, true )
116128 }
@@ -120,14 +132,17 @@ impl TimeZone for Local {
120132 Date :: from_utc ( * utc, * midnight. offset ( ) )
121133 }
122134
123- #[ cfg( all( target_arch = "wasm32" , not( target_os = "wasi" ) , feature = "wasmbind" ) ) ]
135+ #[ cfg( all( target_arch = "wasm32" , not( any ( target_os = "emscripten" , target_os = "wasi" ) ) ) ) ]
124136 fn from_utc_datetime ( & self , utc : & NaiveDateTime ) -> DateTime < Local > {
125137 // Get the offset from the js runtime
126138 let offset = FixedOffset :: west ( ( js_sys:: Date :: new_0 ( ) . get_timezone_offset ( ) as i32 ) * 60 ) ;
127139 DateTime :: from_utc ( * utc, offset)
128140 }
129141
130- #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "wasi" ) , feature = "wasmbind" ) ) ) ]
142+ #[ cfg( not( all(
143+ target_arch = "wasm32" ,
144+ not( any( target_os = "emscripten" , target_os = "wasi" ) )
145+ ) ) ) ]
131146 fn from_utc_datetime ( & self , utc : & NaiveDateTime ) -> DateTime < Local > {
132147 // this is OK to unwrap as getting local time from a UTC
133148 // timestamp is never ambiguous
0 commit comments