Closed bxparks closed 2 months ago
Answering my own question: It needs to be a float
because AwareDateTime
provides microsecond resolution. It could change to int
if the value was interpreted as "microseconds since UNIX epoch".
If we are breaking free of the standard datetime library
This is the key question. When I added this method, I was still of the mind "don't break too much", but now I believe that breaking is a better strategy in the long term.
Continuing on this line, I'd also like to go for nanosecond resolution (like other modern libraries).
This means the timestamp methods could be available in epoch_seconds
, epoch_millis
, epoch_nanos
etc.
I like epoch_seconds()
, epoch_millis()
, epoch_nanos()
. I always have to look up what "timestamp" means in the Python world.
The problem with nanosecond resolution is that an i64
has a range of only +/- 292.27 years, which isn't enough to handle 4-digit years.
Python's int
of course doesn't have that limit—but this may be a problem when implementing this in an extension module.
Doesn't CPython gain some efficiency using machine native sized integers, rather than arbitrary precision int? (Not an expert on CPython internals). I was also considering efficiency issues if/when whenever
is ported to MicroPython.
Agree that it's probably best to stick to native sized integers where possible. The only solution I can imagine now is to raise OverflowException
and clearly document it.
In combination with #91 , it looks like this is definitely going to happen. In implementing the extension I realized that float
just isn't precise enough to handle timestamps up to full microsecond (let alone nanosecond)
Release 0.6.0 is now out with this change.
https://whenever.readthedocs.io/en/latest/api.html#whenever.AwareDateTime
If we are breaking free of the standard
datetime
library, then I have to ask: Does theAwareDateTime.timestamp()
function need to return the epoch_seconds as afloat
? Must we preserve backwards compatibility with Python'stime.time()
, or can it be changed toint
instead, like all other datetime libraries that I am aware of?