[Datetime-SIG] PEP-495 - Strict Invalid Time Checking
carl at oddbird.net
Tue Aug 25 22:13:09 CEST 2015
On 08/25/2015 02:10 PM, Alexander Belopolsky wrote:
> On Tue, Aug 25, 2015 at 3:36 PM, Carl Meyer <carl at oddbird.net
> <mailto:carl at oddbird.net>> wrote:
> Given the unlikelihood of someone trying to schedule an appointment at
> 2am, I didn't care much about the specific choice of user experience for
> the DST gaps and folds; my overriding concerns were to a) not crash the
> application when displaying a DST-transition day, and b) minimize the
> harm done to my codebase (in fragility or added complexity) for the sake
> of handling this rare edge case.
> Here is my recommendation for your case. Assuming that taking user
> entry is equivalent to parsing date and time string in some format and
> scheduling is equivalent to writing a seconds since epoch timestamp into
> some database, do the following post-PEP 495:
> dt = datetime.strptime(input, format)
> s = dt.timestamp()
> # optionally
> sdt = datetime.fromtimestamp(s)
> if dt != sdt:
> warn("You specified an invalid time %s, we scheduled your
> appointment for %s", dt, sdt)
> Instead of a warning, your program may highlight the changed hour in read.
> This program will have no means of scheduling in the "fold=1" hour and
> will correct you if you enter time that falls in a gap. The PEP 495
> design is motivated by precisely this type of application.
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 (and I need the actual
timezone-aware instants of the start and end time for each slot so that
I can properly populate its availability status based on a database
table of existing appointments, with start and end times stored in UTC).
So your solution, which is all about "taking user entry," is not
relevant to the use case.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: OpenPGP digital signature
More information about the Datetime-SIG