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

Carl Meyer carl at oddbird.net
Tue Aug 25 22:30:32 CEST 2015


On 08/25/2015 02:24 PM, Alexander Belopolsky wrote:
> 
> On Tue, Aug 25, 2015 at 4:13 PM, Carl Meyer <carl at oddbird.net
> <mailto:carl at oddbird.net>> wrote:
> 
>     You are missing the crux of my use case, which is that I need to
>     generate a calendar to display to the user, with all the half-hour slots
>     from midnight to midnight for one day in it
> 
> 
> Got it.  How is this then
> 
> 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.

Carl


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150825/c8657646/attachment.sig>


More information about the Datetime-SIG mailing list