Skip to content

Commit 6894ec1

Browse files
committed
Better gating for tm_gmtoff extension
1 parent 2297a4e commit 6894ec1

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/sys/local_offset_at/unix.rs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,22 @@ unsafe fn timestamp_to_tm(timestamp: i64) -> Option<libc::tm> {
4343
}
4444

4545
/// 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+
))]
4862
fn tm_to_offset(tm: libc::tm) -> Option<UtcOffset> {
4963
let seconds: i32 = tm.tm_gmtoff.try_into().ok()?;
5064
UtcOffset::from_hms(
@@ -56,20 +70,52 @@ fn tm_to_offset(tm: libc::tm) -> Option<UtcOffset> {
5670
}
5771

5872
/// Convert a `libc::tm` to a `UtcOffset`. Returns `None` on any error.
59-
// Solaris/Illumos is unsound and requires opting into.
6073
#[cfg(all(
6174
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+
))
6390
))]
6491
#[allow(unused_variables, clippy::missing_const_for_fn)]
6592
fn tm_to_offset(tm: libc::tm) -> Option<UtcOffset> {
6693
None
6794
}
6895

6996
/// 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.
70102
#[cfg(all(
71103
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+
))
73119
))]
74120
fn tm_to_offset(tm: libc::tm) -> Option<UtcOffset> {
75121
use crate::Date;

0 commit comments

Comments
 (0)