You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems to me that Instant and OffsetDateTime represent a fairly similar concept (some absolute point in time). It would be useful to convert between them, for example to obtain an Instant for "tomorrow at 11am" and use tokio or something else to wait until then. However, I can't find an obvious way to perform this conversion.
It might be possible to do something like Instant::now() + (datetime - OffsetDateTime::now()), but this seems quite unintuitive and I'm also not sure if the internal data formats are suitable for this conversion.
Is Instant (or, for that matter, std::time::Instant) even suitable for representing instants that are days or even weeks into the past/future?
If so, would an explicit method for converting from OffsetDateTime to Instant be in scope of this crate?
If not, I think we should document why this conversion is a bad idea.
The text was updated successfully, but these errors were encountered:
The Instant in the time crate is nearly identical to that in the standard library (and is actually just a thin wrapper). Instants can only be used with themselves and Durations, either from this crate or stdlib.
Instant is primarily used for timing things, and can not be used to represent a known moment in time. That's what OffsetDateTime is for.
Completely aside from the two structs serving entirely different purposes, this is quite literally impossible. Instant ultimately performs syscalls via the stdlib implementation, and these are almost always a counter since boot time. Needless to say, there is no concept of an epoch there, unless you can somehow guarantee the boot time.
It seems to me that
Instant
andOffsetDateTime
represent a fairly similar concept (some absolute point in time). It would be useful to convert between them, for example to obtain anInstant
for "tomorrow at 11am" and use tokio or something else to wait until then. However, I can't find an obvious way to perform this conversion.It might be possible to do something like
Instant::now() + (datetime - OffsetDateTime::now())
, but this seems quite unintuitive and I'm also not sure if the internal data formats are suitable for this conversion.Is
Instant
(or, for that matter,std::time::Instant
) even suitable for representing instants that are days or even weeks into the past/future?If so, would an explicit method for converting from
OffsetDateTime
toInstant
be in scope of this crate?If not, I think we should document why this conversion is a bad idea.
The text was updated successfully, but these errors were encountered: