@@ -43,8 +43,22 @@ unsafe fn timestamp_to_tm(timestamp: i64) -> Option<libc::tm> {
43
43
}
44
44
45
45
/// Convert a `libc::tm` to a `UtcOffset`. Returns `None` on any error.
46
- // `tm_gmtoff` extension
47
- #[ cfg( not( any( target_os = "solaris" , target_os = "illumos" ) ) ) ]
46
+ // This is available to any target known to have the `tm_gmtoff` extension.
47
+ #[ cfg( any(
48
+ target_os = "redox" ,
49
+ target_os = "linux" ,
50
+ target_os = "l4re" ,
51
+ target_os = "android" ,
52
+ target_os = "emscripten" ,
53
+ target_os = "macos" ,
54
+ target_os = "ios" ,
55
+ target_os = "watchos" ,
56
+ target_os = "freebsd" ,
57
+ target_os = "dragonfly" ,
58
+ target_os = "openbsd" ,
59
+ target_os = "netbsd" ,
60
+ target_os = "haiku" ,
61
+ ) ) ]
48
62
fn tm_to_offset ( tm : libc:: tm ) -> Option < UtcOffset > {
49
63
let seconds: i32 = tm. tm_gmtoff . try_into ( ) . ok ( ) ?;
50
64
UtcOffset :: from_hms (
@@ -56,20 +70,52 @@ fn tm_to_offset(tm: libc::tm) -> Option<UtcOffset> {
56
70
}
57
71
58
72
/// Convert a `libc::tm` to a `UtcOffset`. Returns `None` on any error.
59
- // Solaris/Illumos is unsound and requires opting into.
60
73
#[ cfg( all(
61
74
not( unsound_local_offset) ,
62
- any( target_os = "solaris" , target_os = "illumos" )
75
+ not( any(
76
+ target_os = "redox" ,
77
+ target_os = "linux" ,
78
+ target_os = "l4re" ,
79
+ target_os = "android" ,
80
+ target_os = "emscripten" ,
81
+ target_os = "macos" ,
82
+ target_os = "ios" ,
83
+ target_os = "watchos" ,
84
+ target_os = "freebsd" ,
85
+ target_os = "dragonfly" ,
86
+ target_os = "openbsd" ,
87
+ target_os = "netbsd" ,
88
+ target_os = "haiku" ,
89
+ ) )
63
90
) ) ]
64
91
#[ allow( unused_variables, clippy:: missing_const_for_fn) ]
65
92
fn tm_to_offset ( tm : libc:: tm ) -> Option < UtcOffset > {
66
93
None
67
94
}
68
95
69
96
/// Convert a `libc::tm` to a `UtcOffset`. Returns `None` on any error.
97
+ // This method can return an incorrect value, as it only approximates the `tm_gmtoff` field. As such
98
+ // it is gated behind `--cfg unsound_local_offset`. The reason it can return an incorrect value is
99
+ // that daylight saving time does not start on the same date every year, nor are the rules for
100
+ // daylight saving time the same for every year. This implementation assumes 1970 is equivalent to
101
+ // every other year, which is not always the case.
70
102
#[ cfg( all(
71
103
unsound_local_offset,
72
- any( target_os = "solaris" , target_os = "illumos" )
104
+ not( any(
105
+ target_os = "redox" ,
106
+ target_os = "linux" ,
107
+ target_os = "l4re" ,
108
+ target_os = "android" ,
109
+ target_os = "emscripten" ,
110
+ target_os = "macos" ,
111
+ target_os = "ios" ,
112
+ target_os = "watchos" ,
113
+ target_os = "freebsd" ,
114
+ target_os = "dragonfly" ,
115
+ target_os = "openbsd" ,
116
+ target_os = "netbsd" ,
117
+ target_os = "haiku" ,
118
+ ) )
73
119
) ) ]
74
120
fn tm_to_offset ( tm : libc:: tm ) -> Option < UtcOffset > {
75
121
use crate :: Date ;
0 commit comments