diff --git a/library/core/src/time.rs b/library/core/src/time.rs index d66f558078ea8..9dc4d39ae4e95 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -101,6 +101,66 @@ pub struct Duration { } impl Duration { + /// The duration of one week. + /// + /// # Examples + /// + /// ``` + /// #![feature(duration_constructors)] + /// use std::time::Duration; + /// + /// assert_eq!(Duration::WEEK, Duration::from_weeks(1)); + /// assert_eq!(5 * Duration::WEEK, Duration::from_weeks(5)); + /// assert_eq!(Duration::WEEK, Duration::from_secs(7 * 24 * 60 * 60)); + /// ``` + #[unstable(feature = "duration_constructors", issue = "120301")] + pub const WEEK: Duration = Duration::from_weeks(1); + + /// The duration of one day. + /// + /// # Examples + /// + /// ``` + /// #![feature(duration_constructors)] + /// use std::time::Duration; + /// + /// assert_eq!(Duration::DAY, Duration::from_days(1)); + /// assert_eq!(5 * Duration::DAY, Duration::from_days(5)); + /// assert_eq!(Duration::DAY, Duration::from_secs(24 * 60 * 60)); + /// ``` + #[unstable(feature = "duration_constructors", issue = "120301")] + pub const DAY: Duration = Duration::from_days(1); + + /// The duration of one hour. + /// + /// # Examples + /// + /// ``` + /// #![feature(duration_constructors)] + /// use std::time::Duration; + /// + /// assert_eq!(Duration::HOUR, Duration::from_hours(1)); + /// assert_eq!(5 * Duration::HOUR, Duration::from_hours(5)); + /// assert_eq!(Duration::HOUR, Duration::from_secs(60 * 60)); + /// ``` + #[unstable(feature = "duration_constructors", issue = "120301")] + pub const HOUR: Duration = Duration::from_hours(1); + + /// The duration of one minute. + /// + /// # Examples + /// + /// ``` + /// #![feature(duration_constructors)] + /// use std::time::Duration; + /// + /// assert_eq!(Duration::MINUTE, Duration::from_mins(1)); + /// assert_eq!(5 * Duration::MINUTE, Duration::from_mins(5)); + /// assert_eq!(Duration::MINUTE, Duration::from_secs(60)); + /// ``` + #[unstable(feature = "duration_constructors", issue = "120301")] + pub const MINUTE: Duration = Duration::from_mins(1); + /// The duration of one second. /// /// # Examples