Skip to content
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

Yet another attempt to refactor libstd's Duration #18416

Closed
1-more opened this issue Oct 29, 2014 · 2 comments
Closed

Yet another attempt to refactor libstd's Duration #18416

1-more opened this issue Oct 29, 2014 · 2 comments

Comments

@1-more
Copy link
Contributor

1-more commented Oct 29, 2014

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:

  1. Internals of struct Duraion are not exposed. So, we are free to change them.
  2. New representation is 3 bytes smaller.
  3. Methods like num_milliseconds etc will return correct i64 values (see libstd: Refactor Duration. #16626).
  4. TimeSpan in .NET and Duration in Joda-Time types do the same.

Some cons:

  1. The overall range of values for Duration will be shorter:
    • i64::MAX seconds gives us 106751991167300 days. We don't use need it.
    • i64::MAX milliseconds gives us 106751991167 days. This is our current choice.
    • i64::MAX ticks gives us 10675199 days. The range is still long enough, who cares?
  2. ?
1-more added a commit to 1-more/rust that referenced this issue Nov 3, 2014
This commit changes the internal representation of Duration from

    pub struct Duraion {
        secs: i64,
        nanos: i32
    }

to

    /// An absolute amount of time, independent of time zones
    /// and calendars with tick precision. A single tick
    /// represents 100 nanoseconds.
    pub struct Duration(pub i64)

Closes rust-lang#18166,rust-lang#18416.
@jooert
Copy link
Contributor

jooert commented May 27, 2015

Isn't this obsolete because #24920 has been merged?

@alexcrichton
Copy link
Member

Ah yes, thanks @jooert! More design info can also be found in the associated RFC thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants