feat(time): add Duration::{WEEK, DAY, HOUR, MINUTE} - #163138
Merged
rust-bors[bot] merged 1 commit intoSep 22, 2026
Merged
Conversation
Collaborator
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
|
@bors r+ rollup Thank you! |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Sep 22, 2026
…constants, r=clarfonthey
feat(time): add `Duration::{WEEK, DAY, HOUR, MINUTE}`
- Tracking issue: rust-lang#57391
This pull request adds associated constants for representing one week, one day, one hour, or one minute to `Duration`.
In the same way as rust-lang#162195 and rust-lang#162199, the exact number of seconds corresponding to one week, one day, one hour, and one minute are clearly specified in the documentation. Documentation tests are used to verify the correctness of these descriptions.
I initially proposed this as an ACP. However, the `duration_constants` feature is still unstable, and the ACP simply adds associated constants for units larger than the second to the feature, I determined that it could be incorporated into the feature.
By making `Duration::WEEK` and `Duration::DAY` dependent on the `duration_constructors` feature, these associated constants can be removed if `Duration::from_weeks` and `Duration::from_days` are not stabilized. Therefore, even if the `duration_constructors` feature is not stabilized, the `duration_constants` feature can be stabilized.
```rust
impl Duration {
pub const WEEK: Duration = Duration::from_weeks(1);
pub const DAY: Duration = Duration::from_days(1);
pub const HOUR: Duration = Duration::from_hours(1);
pub const MINUTE: Duration = Duration::from_mins(1);
}
```
- See also: rust-lang/libs-team#869
This was referenced Sep 22, 2026
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 22, 2026
…uwer Rollup of 8 pull requests Successful merges: - #162628 (Move `Const` from `rustc_middle` to `rustc_type_ir`) - #159589 (Avoid leaking opaque hidden types via auto trait candidates) - #147790 (constify comparison traits on sliced types) - #162325 (powerpc64-ibm-aix: fix cfg(target_abi) value) - #162786 (regression test for GCE inherent projection ICE) - #163065 (windows Dir::rename: remove incorrect is_dir query) - #163138 (feat(time): add `Duration::{WEEK, DAY, HOUR, MINUTE}`) - #163162 (Remove unused `make3.sh` CI script)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 22, 2026
Rollup merge of #163138 - sorairolake:feature/more-duration-constants, r=clarfonthey feat(time): add `Duration::{WEEK, DAY, HOUR, MINUTE}` - Tracking issue: #57391 This pull request adds associated constants for representing one week, one day, one hour, or one minute to `Duration`. In the same way as #162195 and #162199, the exact number of seconds corresponding to one week, one day, one hour, and one minute are clearly specified in the documentation. Documentation tests are used to verify the correctness of these descriptions. I initially proposed this as an ACP. However, the `duration_constants` feature is still unstable, and the ACP simply adds associated constants for units larger than the second to the feature, I determined that it could be incorporated into the feature. By making `Duration::WEEK` and `Duration::DAY` dependent on the `duration_constructors` feature, these associated constants can be removed if `Duration::from_weeks` and `Duration::from_days` are not stabilized. Therefore, even if the `duration_constructors` feature is not stabilized, the `duration_constants` feature can be stabilized. ```rust impl Duration { pub const WEEK: Duration = Duration::from_weeks(1); pub const DAY: Duration = Duration::from_days(1); pub const HOUR: Duration = Duration::from_hours(1); pub const MINUTE: Duration = Duration::from_mins(1); } ``` - See also: rust-lang/libs-team#869
bjorn3
pushed a commit
to rust-lang/rustc_codegen_cranelift
that referenced
this pull request
Sep 23, 2026
…uwer Rollup of 8 pull requests Successful merges: - rust-lang/rust#162628 (Move `Const` from `rustc_middle` to `rustc_type_ir`) - rust-lang/rust#159589 (Avoid leaking opaque hidden types via auto trait candidates) - rust-lang/rust#147790 (constify comparison traits on sliced types) - rust-lang/rust#162325 (powerpc64-ibm-aix: fix cfg(target_abi) value) - rust-lang/rust#162786 (regression test for GCE inherent projection ICE) - rust-lang/rust#163065 (windows Dir::rename: remove incorrect is_dir query) - rust-lang/rust#163138 (feat(time): add `Duration::{WEEK, DAY, HOUR, MINUTE}`) - rust-lang/rust#163162 (Remove unused `make3.sh` CI script)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request adds associated constants for representing one week, one day, one hour, or one minute to
Duration.In the same way as #162195 and #162199, the exact number of seconds corresponding to one week, one day, one hour, and one minute are clearly specified in the documentation. Documentation tests are used to verify the correctness of these descriptions.
I initially proposed this as an ACP. However, the
duration_constantsfeature is still unstable, and the ACP simply adds associated constants for units larger than the second to the feature, I determined that it could be incorporated into the feature.By making
Duration::WEEKandDuration::DAYdependent on theduration_constructorsfeature, these associated constants can be removed ifDuration::from_weeksandDuration::from_daysare not stabilized. Therefore, even if theduration_constructorsfeature is not stabilized, theduration_constantsfeature can be stabilized.Duration::{WEEK, DAY, HOUR, MINUTE}associated constants libs-team#869