rust-lang / rust-lang/rust

Tracking Issue for `try_from_{nanos_u128,mins,hours,days,weeks}` methods on `Duration`

Open
#153,678 2 comments 0 reactions 1 assignee View on GitHub

@Zorbatron is already working on this.

Since Mar 10, 2026.

C-tracking-issue T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(non_panicking_duration_conversion)]

This is a tracking issue for the try_from_{nanos_u128,mins,hours,days,weeks} methods on Duration.

These methods will allow you to convert from a number of minutes, hours, etc, without having to having to check for overflows before calling the method.

Public API
impl Duration {
    pub const fn try_from_nanos_u128(nanos: u64) -> Result<Duration, DurationConversionError>;
    pub const fn try_from_weeks(weeks: u64) -> Result<Duration, DurationConversionError>;
    pub const fn try_from_days(days: u64) -> Result<Duration, DurationConversionError>;
    pub const fn try_from_hours(hours: u64) -> Result<Duration, DurationConversionError>;
    pub const fn try_from_mins(mins: u64) -> Result<Duration, DurationConversionError>;
}
Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

  • ACP: rust-lang/libs-team#749
  • Implementation: #153683
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • TryFromFloatSecsError is still stable, but it's a type alias to DurationConversionError now. But DurationConversionError and it's fmt::Display implementation are unstable, so fmt::Display for TryFromFloatSecsError was downgraded to unstable. Should this be changed?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.