Skip to content

feat(time): add Duration::{WEEK, DAY, HOUR, MINUTE} - #163138

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
sorairolake:feature/more-duration-constants
Sep 22, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
sorairolake:feature/more-duration-constants

Conversation

@sorairolake

@sorairolake sorairolake commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

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.

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);
}

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 22, 2026
@rustbot

rustbot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from Darksonn, JohnTitor, Mark-Simulacrum, clarfonthey, jhpratt

@clarfonthey

Copy link
Copy Markdown
Contributor

@bors r+ rollup

Thank you!

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 99ad525 has been approved by clarfonthey

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2026
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
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
rust-bors Bot merged commit 3641daf into rust-lang:main Sep 22, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 22, 2026
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
@sorairolake
sorairolake deleted the feature/more-duration-constants branch September 23, 2026 00:58
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants