-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Time units #52556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Time units #52556
Changes from 1 commit
4f9ccfb
2f90e91
d230ef7
96aa208
ef92df4
5d6ab9f
e78120d
9f9520d
f5db99d
9e5daa5
2732503
5d9b925
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,29 @@ const NANOS_PER_MICRO: u32 = 1_000; | |
const MILLIS_PER_SEC: u64 = 1_000; | ||
const MICROS_PER_SEC: u64 = 1_000_000; | ||
|
||
/// 1 nanosecond `Duration` | ||
#[unstable(feature = "time_units", issue = "0")] | ||
const NS: Duration = Duration::from_nanos(1); | ||
/// 1 microsecond `Duration` | ||
#[unstable(feature = "time_units", issue = "0")] | ||
const US: Duration = Duration::from_micros(1); | ||
#[unstable(feature = "time_units", issue = "0")] | ||
/// 1 millisecond `Duration` | ||
#[unstable(feature = "time_units", issue = "0")] | ||
const MS: Duration = Duration::from_millis(1); | ||
/// 1 second `Duration` | ||
#[unstable(feature = "time_units", issue = "0")] | ||
const S: Duration = Duration::from_secs(1); | ||
/// 1 minute `Duration` | ||
#[unstable(feature = "time_units", issue = "0")] | ||
const M: Duration = Duration::from_secs(60); | ||
/// 1 hour `Duration` | ||
#[unstable(feature = "time_units", issue = "0")] | ||
const H: Duration = Duration::from_secs(60*60); | ||
/// 1 day `Duration` | ||
#[unstable(feature = "time_units", issue = "0")] | ||
const D: Duration = Duration::from_secs(24*60*60); | ||
|
||
/// A `Duration` type to represent a span of time, typically used for system | ||
/// timeouts. | ||
/// | ||
|
@@ -501,6 +524,15 @@ impl Mul<u32> for Duration { | |
} | ||
} | ||
|
||
#[unstable(feature = "time_units", issue = "0")] | ||
impl Mul<Duration> for u32 { | ||
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. This impl is going to be insta-stable unfortunately. 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. Should I keep the attribute or use instead something like 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. @newpavlov The latter (with a different feature name, otherwise 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. Hm, what should I use for UPD: Ah, haven't noticed your update. :) |
||
type Output = Duration; | ||
|
||
fn mul(self, rhs: Duration) -> Duration { | ||
rhs.checked_mul(self).expect("overflow when multiplying scalar by duration") | ||
} | ||
} | ||
|
||
#[stable(feature = "time_augmented_assignment", since = "1.9.0")] | ||
impl MulAssign<u32> for Duration { | ||
fn mul_assign(&mut self, rhs: u32) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ use sys_common::FromInner; | |
|
||
#[stable(feature = "time", since = "1.3.0")] | ||
pub use core::time::Duration; | ||
pub use core::time::{NS, US, MS, S, M, H, D}; | ||
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. This line needs an |
||
|
||
/// A measurement of a monotonically nondecreasing clock. | ||
/// Opaque and useful only with `Duration`. | ||
|
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.
Similar to #47097, I doubt we want to support hours and days.
Abbreviating minutes to
M
is also confusing (months? meters?). The SI standard short formMIN
conflicts in meaning with "minimum". I would like to leave this out as well, keeping onlyS
,MS
,US
andNS
.