Skip to content

Commit e53a3c3

Browse files
committed
pal/unix: Implement SystemTime::{MIN, MAX}
1 parent 08ea8d2 commit e53a3c3

File tree

1 file changed

+15
-0
lines changed
  • library/std/src/sys/pal/unix

1 file changed

+15
-0
lines changed

library/std/src/sys/pal/unix/time.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub(crate) struct Timespec {
2929
}
3030

3131
impl SystemTime {
32+
#[unstable(feature = "time_systemtime_limits", issue = "none")]
33+
pub const MAX: SystemTime = SystemTime { t: Timespec::MAX };
34+
35+
#[unstable(feature = "time_systemtime_limits", issue = "none")]
36+
pub const MIN: SystemTime = SystemTime { t: Timespec::MIN };
37+
3238
#[cfg_attr(any(target_os = "horizon", target_os = "hurd"), allow(unused))]
3339
pub fn new(tv_sec: i64, tv_nsec: i64) -> Result<SystemTime, io::Error> {
3440
Ok(SystemTime { t: Timespec::new(tv_sec, tv_nsec)? })
@@ -61,6 +67,15 @@ impl fmt::Debug for SystemTime {
6167
}
6268

6369
impl Timespec {
70+
#[unstable(feature = "time_systemtime_limits", issue = "none")]
71+
const MAX: Timespec = unsafe { Self::new_unchecked(i64::MAX, 1_000_000_000 - 1) };
72+
73+
// As described below, on AppleOS, dates before epoch are represented differently.
74+
// This is not an issue here however, because we are using tv_sec = i64::MIN,
75+
// which will cause the compatibility wrapper to not be executed at all.
76+
#[unstable(feature = "time_systemtime_limits", issue = "none")]
77+
const MIN: Timespec = unsafe { Self::new_unchecked(i64::MIN, 0) };
78+
6479
const unsafe fn new_unchecked(tv_sec: i64, tv_nsec: i64) -> Timespec {
6580
Timespec { tv_sec, tv_nsec: unsafe { Nanoseconds::new_unchecked(tv_nsec as u32) } }
6681
}

0 commit comments

Comments
 (0)