@@ -22,7 +22,23 @@ pub(crate) use self::sys::*;
22
22
) ) ) ]
23
23
mod sys {
24
24
pub ( crate ) fn system_time ( ) -> std:: time:: SystemTime {
25
- std:: time:: SystemTime :: now ( )
25
+ // `SystemTime::now()` should continue to panic on this exact target in
26
+ // the future as well; Instead of letting `std` panic, we panic first
27
+ // with a more informative error message.
28
+ if cfg ! ( all(
29
+ not( feature = "js" ) ,
30
+ any( target_arch = "wasm32" , target_arch = "wasm64" ) ,
31
+ target_os = "unknown"
32
+ ) ) {
33
+ panic ! (
34
+ "getting the current time in wasm32-unknown-unknown \
35
+ is not possible with just the standard library, \
36
+ enable Jiff's `js` feature if you are \
37
+ targeting a browser environment",
38
+ ) ;
39
+ } else {
40
+ std:: time:: SystemTime :: now ( )
41
+ }
26
42
}
27
43
28
44
#[ cfg( any(
@@ -31,7 +47,18 @@ mod sys {
31
47
feature = "tzdb-concatenated"
32
48
) ) ]
33
49
pub ( crate ) fn monotonic_time ( ) -> Option < std:: time:: Instant > {
34
- Some ( std:: time:: Instant :: now ( ) )
50
+ // Same reasoning as above, but we return `None` instead of panicking,
51
+ // because Jiff can deal with environments that don't provide
52
+ // monotonic time.
53
+ if cfg ! ( all(
54
+ not( feature = "js" ) ,
55
+ any( target_arch = "wasm32" , target_arch = "wasm64" ) ,
56
+ target_os = "unknown"
57
+ ) ) {
58
+ None
59
+ } else {
60
+ Some ( std:: time:: Instant :: now ( ) )
61
+ }
35
62
}
36
63
}
37
64
0 commit comments