[Datetime-SIG] PEP-495 - Strict Invalid Time Checking
alexander.belopolsky at gmail.com
Tue Aug 25 22:42:35 CEST 2015
On Tue, Aug 25, 2015 at 4:30 PM, Carl Meyer <carl at oddbird.net> wrote:
> > start = datetime.combine(date, time(0)).astimezone()
> > while True:
> > end = (start + timedelta(hours=0.5)).astimezone()
> > print(start, end)
> > start = end
> > if end.time() == time(0):
> > break
> On DST transition days, this code does not generate exactly 48 slots,
> displayable to the user in a schedule that includes all hours from 0 to
> 23 labeled exactly once.
> That introduces an unacceptable level of additional display-layer
> complexity, and remains inferior to the "strict checking" solution I chose.
OK. So you just want [datetime.combine(date, time(0)) +
timedelta(hours=0.5*i)) for i in range(48)] but detect those that are
either in the fold or in the gap? Just check for dt.astimezone() !=
dt.replace(fold=1).astimezone() instead of catching the strict exceptions.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Datetime-SIG