Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add std::time::Duration::{from_days, from_hours, from_mins} #47097

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/libstd/time/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,44 @@ impl Duration {
Duration { secs: secs, nanos: nanos }
}

/// Creates a new `Duration` from the specified number of whole hours.
///
/// # Examples
///
/// ```
/// #![feature(duration_from)]
/// use std::time::Duration;
///
/// let duration = Duration::from_hours(2);
///
/// assert_eq!(7200, duration.as_secs());
/// assert_eq!(0, duration.subsec_nanos());
/// ```
#[unstable(feature = "duration_from", issue = "47097")]
#[inline]
pub fn from_hours(hours: u64) -> Duration {
Duration { secs: 3600*hours, nanos: 0 }
}

/// Creates a new `Duration` from the specified number of whole minutes.
///
/// # Examples
///
/// ```
/// #![feature(duration_from)]
/// use std::time::Duration;
///
/// let duration = Duration::from_minutes(5);
///
/// assert_eq!(300, duration.as_secs());
/// assert_eq!(0, duration.subsec_nanos());
/// ```
#[unstable(feature = "duration_from", issue = "47097")]
#[inline]
pub fn from_minutes(minutes: u64) -> Duration {
Duration { secs: 60*minutes, nanos: 0 }
}

/// Creates a new `Duration` from the specified number of whole seconds.
///
/// # Examples
Expand Down