<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 25, 2015 at 4:30 PM, Carl Meyer <span dir="ltr"><<a href="mailto:carl@oddbird.net" target="_blank">carl@oddbird.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">> start = datetime.combine(date, time(0)).astimezone()<br>
> while True:<br>
>     end = (start + timedelta(hours=0.5)).astimezone()<br>
>     print(start, end)<br>
>     start = end<br>
>     if end.time() == time(0):<br>
>         break<br>
<br>
</span>On DST transition days, this code does not generate exactly 48 slots,<br>
displayable to the user in a schedule that includes all hours from 0 to<br>
23 labeled exactly once.<br>
<br>
That introduces an unacceptable level of additional display-layer<br>
complexity, and remains inferior to the "strict checking" solution I chose.</blockquote></div><br>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.</div></div>