[Datetime-SIG] PEP-495 - Strict Invalid Time Checking

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Aug 25 22:56:40 CEST 2015


On Tue, Aug 25, 2015 at 4:33 PM, Carl Meyer <carl at oddbird.net> wrote:

> To further explain this requirement: days can be displayed adjacent to
> each other in a weekly view, so the server must provide to the client
> exactly 48 slot data structures per day (including DST transition days),
> which can be laid out in a strict grid, where all the days share the
> same set of time labels on the left.
>

Whatever your requirements are, the difference between "strict checking"
and PEP 495 code will be the same as between

dt = get_naive_time()
try:
    dt = dt.astimezone()
except AmbiguousTimeError:
    # do something
except MissingTimeError:
    # do something else
else:
    # use dt

and

dt = get_naive_time()
dt0 = dt.replace(fold=0).astimezone()
dt1 = dt.replace(fold=1).astimezone()
if dt1 > dt0:
    # do something
elif dt1 < dt0:
    # do something else
else:
    # use dt0 which is the same as dt1

The PEP 495 code may be slightly more involved, but most people can get
away with just

dt = get_time().astimezone()

and not see any crashes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150825/bbb34e23/attachment.html>


More information about the Datetime-SIG mailing list