ZonedDateTime should expose its 'fold' and 'is_ambiguous' properties in some way #68
Labels
discussion
Discussion is needed before proceeding
documentation
Improvements or additions to documentation
in development
Has been addressed but not released yet
As far as I can tell,
ZonedDateTime
, which inherits fromDateTimeAwareDateTime
time, does not expose the underlyingfold
value:https://whenever.readthedocs.io/en/latest/api.html#whenever.ZonedDateTime
https://whenever.readthedocs.io/en/latest/api.html#whenever.AwareDateTime
It may not be obvious that the
fold
parameter described by PEP 495 is both an input parameter and an output parameter. The outputfold
parameter is what allowsdatetime.datetime
to support round trip conversions without loss of information. In other words,epoch_seconds
can be converted intodatetime.datetime
, which can then be converted back toepoch_seconds
, and the 2epoch_seconds
will be identical, even during an overlap (when, for example, northern hemisphere countries "fall back" in the fall).But more practically, the
fold
parameter of adatetime.datetime
object is useful to a client app, because it allows the app to know if a specificepoch_second
was converted to adatetime
which could be interpreted by humans as ambiguous. Access to thefold
parameter is required if the application wants to warn the user of an ambiguous time, something like: "The meeting time is 01:30 on Nov 3, 2024 (Warning: this is the first occurrence of 01:30, not the second occurrence.)"Currently,
ZonedDateTime
is a thin wrapper arounddatetime.datetime
. But it does not expose thefold
parameter to the calling client. I think it should, but in a way that is more friendly thanfold
. As I was writing this ticket, it occurred to me that there is a complication: the underlyingdatetime.datetime
class, which is used byZonedDateTime
, does not actually contain enough information to solve this problem properly. We actually needZonedDateTime
to expose two bits of information:is_ambiguous: bool
: Whether or not theepoch_seconds
mapped to aZonedDateTime
that can be ambiguous, i.e. a "duplicate" or an "overlap". Alternative names for this property may beis_overlap
oris_duplicate
.fold: int
: 0 if theZonedDateTime
corresponds to the first instance, and 1 if theZonedDateTime
corresponds to the second.The
is_ambiguous
parameter can be calculated by brute force withinZonedDateTime
. But it would be more efficient to delegate that calculation to aTimeZone
class (which does not currently exist inwhenever
, but I described its contours in #60), so that we get efficient access to the metadata information about the given timezone.Anyway, I don't know how you want to prioritize this issue. I figure that if you are going make a clean break from
datetime
, and solve a bunch of problems, you might as well fix this one too. :-)The text was updated successfully, but these errors were encountered: