-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Description
At the moment the Duration type looks like
pub struct Duraion {
secs: i64,
nanos: i32
}
According to this, one can expect that maximum possible duration value is at least i64::MAX seconds. But in fact, the full range that i64 seconds gives us is restricted to i64::MAX milliseconds (see #16626 for more details).
I offer to change the internal representation of Duration to
pub struct Duraion {
ticks: i64, // A single tick represents 100 nanoseconds
nanos: i8 // to hold values from -99 to 99
}
Some pros:
- Internals of
struct Duraionare not exposed. So, we are free to change them. - New representation is 3 bytes smaller.
- Methods like
num_millisecondsetc will return correct i64 values (see libstd: Refactor Duration. #16626). TimeSpanin .NET andDurationin Joda-Time types do the same.
Some cons:
- The overall range of values for
Durationwill be shorter:i64::MAXseconds gives us 106751991167300 days. We don't useneedit.i64::MAXmilliseconds gives us 106751991167 days. This is our current choice.i64::MAXticks gives us 10675199 days. The range is still long enough, who cares?
- ?
Metadata
Metadata
Assignees
Labels
No labels