Skip to content

Tracking issue for duration_constants #57391

Open

Description

@frewsxcv

View all comments

Implemented in #57375

This will make working with durations more ergonomic. Compare:

// Convenient, but deprecated function.
thread::sleep_ms(2000);

// The current canonical way to sleep for two seconds.
thread::sleep(Duration::from_secs(2));

// Sleeping using one of the new constants.
thread::sleep(2 * SECOND);
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);
    pub const SECOND: Duration = Duration::from_secs(1);
    pub const MILLISECOND: Duration = Duration::from_millis(1);
    pub const MICROSECOND: Duration = Duration::from_micros(1);
    pub const NANOSECOND: Duration = Duration::from_nanos(1);
    pub const MAX: Duration = ...;
}

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jan 6, 2019
  2. oli-obk commented on Jan 7, 2019

    @oli-obk
    Contributor

    Currently these constants are free constants in the std::time module. I think we should consider moving them onto the Duration type as associated constants.

  3. SimonSapin commented on Feb 1, 2019

    @SimonSapin
    Contributor

    Associated constants would reduce the (typical) number of imports in code using this. @stjepang @frewsxcv what do you think?

    I’ll FCP to merge once this is resolved one way or another.

  4. added 5 commits that reference this issue on Feb 23, 2019
  5. SimonSapin commented on Feb 27, 2019

    @SimonSapin
    Contributor

    Updated the issue description.

    @rfcbot fcp merge

  6. rfcbot commented on Feb 27, 2019

    @rfcbot

    Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged team members:

    Concerns:

    Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

    See this document for info about what commands tagged team members can give me.

  7. added
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    on Feb 27, 2019
  8. 31 remaining items

  9. added a commit that references this issue on Apr 26, 2021
  10. Ahmad-34567890 commented on Mar 27, 2023

    @Ahmad-34567890

    I was amazed by how long this has been opened.

    There are two possibilities
    -Associated constants become importable directly (use std::time::Duration::SECOND)
    then yes, it will be very ergonomic and handy and should be stabilized.

    -Close the issue as why even bother with (Duration::SECOND) when we already have (Duration::from_secs(n))
    AND when you want to use it for anything beside a second, lets say 42
    (Duration::from_secs(42)) makes no sense to implement (Duration::SECOND * 42).

    *Just a mere opinion
    If "const" was like "let" so that you don't have to always specify a type, I think, again, this issue would be closed in favor of...

    at worst, Duration is not in scope
    const SECOND = std::time::Duration::from_secs(1);

    instead of
    const SECOND:std::time::Duration = std::time::Duration::from_secs(1);

    At best
    const SECOND = Duration::from_secs(1);

  11. Aandreba commented on Mar 29, 2023

    @Aandreba
  12. zdivelbiss commented on Jul 14, 2025

    @zdivelbiss

    Is there a particular reason this still isn't in a FCP? It's been over 6 years, and this is a relatively small change.

  13. Velocifyer commented on Jul 22, 2026

    @Velocifyer

    I think that they should not use full names because I am bad at spelling MILLISECONDS.
    I think that the best option is to use SI abbreviations, like MS or S or US.
    If we are using full names, there should be both plural and singular versions (eg MILLISECOND and MILLISECONDS) because sleep(2*MILLISECOND) or sleep(1*MILLISECONDS) look weird.

    Ideally it would be properly capitalized SI abbreviations (like ms, not `MS'), but the convention says that constants should be uppercase, and I want to keep it that way.

  14. nia-e commented on Aug 11, 2026

    @nia-e
    Member

    We discussed this in the libs meeting - if someone would put up a stabilisation PR (and improve the docs to give usage examples, with the appropriate directive to ensure tests don't actually wait for n * Duration::SECOND) we're happy to FCP that. thanks!

  15. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  16. removed
    I-libs-nominatedNominated for discussion during a libs team meeting.
    on Aug 17, 2026
  17. added 2 commits that reference this issue on Sep 22, 2026
  18. added a commit that references this issue on Sep 22, 2026
  19. removed
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-timeArea: `std::time`B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions