Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upExpand the std::time module #29866
Comments
alexcrichton
added
A-libs
B-RFC-approved
labels
Nov 16, 2015
This was referenced Nov 16, 2015
bors
added a commit
that referenced
this issue
Nov 19, 2015
This comment has been minimized.
This comment has been minimized.
|
One question raised during review is what representation these types should have on each platform. Currently they all have the native representation (e.g. As a consequence, however, issues like #29970 come up where the types have the property that basic algebra does not work on them. For example I think that having a |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Nov 23, 2015
alexcrichton
added
T-libs
B-unstable
and removed
B-RFC-approved
labels
Nov 23, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Nov 23, 2015
bors
added a commit
that referenced
this issue
Nov 24, 2015
This comment has been minimized.
This comment has been minimized.
|
Is there intended to be a public constructor for any of these, or make |
This comment has been minimized.
This comment has been minimized.
|
It’s a bit convoluted, but you can construct a |
This comment has been minimized.
This comment has been minimized.
|
Does |
This comment has been minimized.
This comment has been minimized.
|
Yeah as @SimonSapin mentioned construction is intended to not be possible for the opaque |
This comment has been minimized.
This comment has been minimized.
|
They're stored as microseconds since 2000, so there would potentially be 2037 problems when converting. |
This comment has been minimized.
This comment has been minimized.
|
Ah ok, in that case (especially if there's no extra time zone data or anything like that) I'd just create something like: let microseconds_since_2000 = db_value;
let t2000 = UNIX_EPOCH + thirty_years;
let duration_since_2000 = Duration::new(...);
let date = t2000 + duration_since_2000; |
This comment has been minimized.
This comment has been minimized.
|
I added support for this to Diesel in diesel-rs/diesel@dbcc1d2. A note on the API from that -- The lack of negative durations makes constructing arbitrary times really painful, though I understand the reasoning that went into that. However, using |
This comment has been minimized.
This comment has been minimized.
|
Very interesting! It's true that the APIs weren't necessarily designed initially with ergonomics as the primary feature, but rather correctness in terms of not omitting various oddities here and there. It's an interesting point though that |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
cc @wycats |
This comment has been minimized.
This comment has been minimized.
|
My original design did indeed have a Signed Duration, but @aturon wanted to @aturon how do you feel now? On Mon, Dec 7, 2015, 6:37 AM Aaron Turon notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
In short, the justification is: if the way to convert |
This comment has been minimized.
This comment has been minimized.
|
I'm not opposed to a sign duration type, and agree with @SimonSapin that we'll still have achieved the basic goal by making the "default" duration nonnegative. Perhaps we can usefully prototype this out of tree. |
This comment has been minimized.
This comment has been minimized.
|
I don’t really like the name Although it would probably have to duplicate much of |
This comment has been minimized.
This comment has been minimized.
|
I experimented with converting r2d2 over to using One note I do have is that for whatever reason, I found |
This comment has been minimized.
This comment has been minimized.
|
@sfackler Would |
This comment has been minimized.
This comment has been minimized.
|
Might be, yeah. |
alexcrichton
removed
the
I-nominated
label
Jan 29, 2016
This comment has been minimized.
This comment has been minimized.
Greater than or equal to. There is no uniqueness guarantee. |
This comment has been minimized.
This comment has been minimized.
|
I'd like to re-raise the issue of renaming Another possibility is to rename |
This comment has been minimized.
This comment has been minimized.
|
@danburkert note that the name is |
This comment has been minimized.
This comment has been minimized.
|
Sorry about that. But yes, I have the same issues with |
This comment has been minimized.
This comment has been minimized.
|
I'm also somewhat sympathetic to naming, specifically if we end up having a couple of clocks we'd probably want them all consistently named. Right now the names |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton @danburkert I'm pretty uneasy with Instead of trying to find a way to make the two types appear to have parity, I'd rather find a name for |
This comment has been minimized.
This comment has been minimized.
|
I agree with @wycats here. The name |
This comment has been minimized.
This comment has been minimized.
|
This can go both ways. Ultimately you can't save all parties from their own ignorance by anointing one clock or another. It's better to put the two clock types on equal footing, and leave the education up to the documentation.
The two types do have parity. They are both clocks which provide measurements. Neither is perfect, neither is strictly superior, and in any given situation it's likely that only one of them can appropriately be used.
It also implies other properties: steadiness, not jumping forwards, that measurements can be compared across hosts, etc. None of the properties are guaranteed or provided by |
This comment has been minimized.
This comment has been minimized.
|
One more thought. A monotonic clock is not sufficient for benchmarking, the clock should also be steady. As a trivial example, a logical clock is monotonic but would be inappropriate for benchmarking. Perhaps the type should be |
This comment has been minimized.
This comment has been minimized.
|
although |
This comment has been minimized.
This comment has been minimized.
|
Just re-export it from |
This comment has been minimized.
This comment has been minimized.
|
I've been using time2 in one of my projects, and I've been getting panics from "overflow when subtracting Durations". Unfortunately I haven't been able to repro this myself, but one of the users of my code has been getting it sporadically. I haven't been able to tell which subtraction could be causing them (they all look fine), and I've yet to get a backtrace back. I think its a bit of an ergonomic issue for subtraction to panic; if we want to disallow negative Durations, then it seems to me that subtraction should return a |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage yesterday and we reached a few conclusions:
|
This comment has been minimized.
This comment has been minimized.
|
Ah, and the other conclusion was to also stabilize everything, which is probably worth mentioning! |
alexcrichton commentedNov 16, 2015
Tracking issue for rust-lang/rfcs#1288