Open bxparks opened 4 months ago
It occurs to me that the Instant
class would replace the float
type returned by the timestamp()
function mentioned in #63 .
My thoughts after some time:
Instant
and UTCDateTime
are very similar. In the end, if you normalize to UTC, you might as well be dealing with a timestamp/integer: you're usually not interested in the nominal month, day, hour in UTC. You're more likely interested in comparison or adding/subtracting
what I'm tending towards: keep UTCDateTime
, but optimize it for comparison and shifting. It would probably be a timestamp under the hood.
An update to add here: In the rust extension I'm working on, UTCDateTime
is Instant
in almost everything but name.
Note that I'm still hanging on to the UTCDateTime
name for these reasons:
UTCDateTime
will be more familiar to most users than Instant
XXXXXDateTime
in the API is already complex. Making Instant
separate from them may confuse users.It occurs to me that the Instant class would replace the float type returned by the timestamp() function mentioned in https://github.com/ariebovenberg/whenever/issues/63 .
Not necessarily... Instant
can be opaque while the timestamp must be a an integer with a specific value 🤔
I've come around to Instant
now:
Instant
(or similar)Instant
repr will be a UTC datetimeZonedDateTime
can be used.The next release will replace UTCDateTime
with Instant
(Spun off from #59)
I can see some value in
UTCDateTime
, because it captures an intent of the developer, and it's more ergonomic thanOffsetDateTime(offset=0)
.Can
UTCDateTime
be replaced with anInstant
class? TheInstant
class is a wrapper around an "epoch seconds". It provides type-safety and encapsulation. There should be an unambiguous 1-to-1 conversion between anInstant
andUTCDateTime
.Here are some examples from other libraries:
long
(seconds) and anint
(nanoseconds)Instant
classInt64
as "milliseconds from UNIX epoch"uint64
, anint64
, and a pointer to aLocation
(i.e. TimeZone) objectTime
class contains aLocation
object, which makes it different than theInstant
class in java.time and NodaTimeDateTime
class hierarchy. Everything is derived from theTime
objectI don't know, I can see both
Instant
andUTCDateTime
being useful, because they capture slightly different things, and the ergonomics for the end-users are slightly different.