-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add std::time::Duration::{from_days, from_hours, from_mins} #47097
Closed
ChristopherRabotin
wants to merge
3
commits into
rust-lang:master
from
ChristopherRabotin:std-time-duration-from-mins-hours-days
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
61d8bdb
Add std::time::Duration::{from_days, from_hours, from_mins}
ChristopherRabotin 84279c7
Clarify from_days docs. Group all new features into one feature name
ChristopherRabotin fb71cbd
Remove `from_days` constructor. Fix `from_minutes` test.
ChristopherRabotin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,63 @@ impl Duration { | |
Duration { secs: secs, nanos: nanos } | ||
} | ||
|
||
/// Creates a new `Duration` from the specified number of whole days. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// #![feature(duration_from_hours)] | ||
/// use std::time::Duration; | ||
/// | ||
/// let duration = Duration::from_days(1); | ||
/// | ||
/// assert_eq!(86_400, duration.as_secs()); | ||
/// assert_eq!(0, duration.subsec_nanos()); | ||
/// ``` | ||
#[unstable(feature = "duration_from_hours", issue = "47097")] | ||
#[inline] | ||
pub fn from_days(days: u64) -> Duration { | ||
Duration { secs: 86_400*days, nanos: 0 } | ||
} | ||
|
||
/// Creates a new `Duration` from the specified number of whole hours. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// #![feature(duration_from_hours)] | ||
/// 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_hours", 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_mins)] | ||
/// use std::time::Duration; | ||
/// | ||
/// let duration = Duration::from_mins(5); | ||
/// | ||
/// assert_eq!(300, duration.as_secs()); | ||
/// assert_eq!(0, duration.subsec_nanos()); | ||
/// ``` | ||
#[unstable(feature = "duration_from_mins", issue = "47097")] | ||
#[inline] | ||
pub fn from_mins(mins: u64) -> Duration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd rather this be called |
||
Duration { secs: 60*mins, nanos: 0 } | ||
} | ||
|
||
/// Creates a new `Duration` from the specified number of whole seconds. | ||
/// | ||
/// # Examples | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we generally create a separate (non-PR) tracking issue for new features. I think you can leave it like this for now, but if we do merge this, then I think we'll want to create a tracking issue and then update the PR.
Is that right @alexcrichton?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I note that this feature name is
duration_from_hours
, which is the same as thefrom_hours
method but different from the nameduration_from_mins
used for thefrom_mins
method.I suspect you probably just want to use one feature name for all of them (
duration_from
perhaps?).