diff --git a/src/header/time/constants.rs b/src/header/time/constants.rs index 34f0056573..5c610ac230 100644 --- a/src/header/time/constants.rs +++ b/src/header/time/constants.rs @@ -1,7 +1,5 @@ use crate::platform::types::*; -pub use self::sys::*; - #[cfg(target_os = "linux")] #[path = "linux.rs"] pub mod sys; @@ -10,6 +8,8 @@ pub mod sys; #[path = "redox.rs"] pub mod sys; +pub use self::sys::*; + pub(crate) const UTC: *const c_char = b"UTC\0".as_ptr().cast(); pub(crate) const DAY_NAMES: [&str; 7] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; @@ -28,6 +28,6 @@ pub const TIMER_ABSTIME: c_int = 1; // The values are offset by one for simplicity since zero represents an error. /// `TIME_UTC` returns the time since the Unix epoch. -pub const TIME_UTC: c_int = sys::CLOCK_REALTIME + 1; +pub const TIME_UTC: c_int = CLOCK_REALTIME + 1; /// `TIME_MONOTONIC` returns the time from the monotonically increasing clock. -pub const TIME_MONOTONIC: c_int = sys::CLOCK_MONOTONIC + 1; +pub const TIME_MONOTONIC: c_int = CLOCK_MONOTONIC + 1; diff --git a/tests/time/localtime_r.c b/tests/time/localtime_r.c index 3d96f23a94..a874daee1e 100644 --- a/tests/time/localtime_r.c +++ b/tests/time/localtime_r.c @@ -7,6 +7,9 @@ void test_localtime_r_epoch() { time_t t = 0; // Unix epoch (1970-01-01 00:00:00) struct tm result; + setenv("TZ", "UTC", 1); + tzset(); + assert(localtime_r(&t, &result) != NULL); assert(result.tm_year == 70); // Year 1970 - 1900 assert(result.tm_mon == 0); // January @@ -22,6 +25,9 @@ void test_localtime_r_non_epoch() { time_t t = 1609459200; // January 1, 2021 00:00:00 UTC (New Year 2021) struct tm result; + setenv("TZ", "UTC", 1); + tzset(); + assert(localtime_r(&t, &result) != NULL); assert(result.tm_year == 121); // Year 2021 - 1900 assert(result.tm_mon == 0); // January @@ -35,6 +41,9 @@ void test_localtime_r_dst() { time_t t = 1615708800; // March 14 2021 08:00:00 UTC struct tm result; + setenv("TZ", "UTC", 1); + tzset(); + assert(localtime_r(&t, &result) != NULL); // Ensure localtime_r does not fail assert(result.tm_year == 121); // Year 2021 - 1900 assert(result.tm_mon == 2); // March @@ -48,6 +57,9 @@ void test_localtime_r_large_time() { time_t t = 32503680000; // A large value: 1 January 3000 (UTC) struct tm result; + setenv("TZ", "UTC", 1); + tzset(); + assert(localtime_r(&t, &result) != NULL); // Ensure localtime_r does not fail assert(result.tm_year == 1100); // Year 3000 - 1900 = 1100 assert(result.tm_mon == 0); // January diff --git a/tests/time/timegm.c b/tests/time/timegm.c index 96fed8e877..9fbfa89fac 100644 --- a/tests/time/timegm.c +++ b/tests/time/timegm.c @@ -4,6 +4,9 @@ #include int main(void) { + setenv("TZ", "UTC", 1); + tzset(); + struct { time_t timestamp; const char *expected_asctime;