[Datetime-SIG] Calendar vs timespan calculations...

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Jul 31 03:00:45 CEST 2015


On Thu, Jul 30, 2015 at 8:36 PM, Tim Peters <tim.peters at gmail.com> wrote:
> Speaking of which, the current tzinfo API has no way to ask "is this
> an ambiguous time?"

I was hoping that we would agree on the name of the flag before
someone asks this question. :-)

With my proposal, a naive datetime t is ambiguous in timezone tz if

tz.utcoffset(t) < tz.utcoffset(t.replace(first=False))

> or "is this an invalid (missing) time?"

I was hoping to sneak in a rule that for an invalid time t

tz.utcoffset(t) > tz.utcoffset(t.replace(first=False))

(I really don't want  tz.utcoffset(t) to ever raise an exception) and
of course, for most of the times

tz.utcoffset(t) == tz.utcoffset(t.replace(first=False))


> The most
> important new question callers will want to resolve  is "what should
> `first` (aka is_dst) be now?".

I want most callers to be able to get away with not knowing that
`first` exists and consistently get the earlier time from an ambiguous
input and some "nearby" time from an invalid input.  A careful
application will have to call tz.utcoffset() with both values of the
flag and either warn about the default choice or ask the user for an
additional input.


More information about the Datetime-SIG mailing list