[Python-ideas] Date/time literals

MRAB python at mrabarnett.plus.com
Tue Jun 1 19:44:23 CEST 2010


Alexander Belopolsky wrote:
> On Tue, Jun 1, 2010 at 10:41 AM, Mark Dickinson <dickinsm at gmail.com> wrote:
> ..
>> As per the POSIX standard (IIUC), [datetime(1985, 6, 30, 23, 59, 60)] would be
>> immediately converted
>> to datetime.datetime(1985, 7, 1, 0, 0, 0) internally.  So the datetime
>> object itself wouldn't support leap seconds, and would continue to use
>> POSIX time;  only the constructor would support leap seconds.
>>
> 
> It is my understanding that POSIX mandates that mktime() function
> normalizes the tm structure and therefore converts (1985, 6, 30, 23,
> 59, 60, ...) to (1985, 7, 1, 0, 0, 0, ...).  It is not quite accurate
> to say that tm structure is converted "immediately".  It is perfectly
> legal to pass around non-normalized tm structures and have for example
> utc2gps() function that would produce different values for Y-M-D
> 23:59:60 and T-M-[D+1] 00:00:00.
> 
> I would prefer a similar behavior for datetime constructor:
> 
>>>> datetime(1985, 6, 30, 23, 59, 60).second
> 60
>>>> datetime(1985, 6, 30, 23, 59, 60).timetuple()
> (1985, 6, 30, 23, 59, 60, ...)
> 
> but
>>>> datetime(1985, 6, 30, 23, 59, 60) - datetime(1985, 7, 1, 0, 0, 0)
> datetime.timedelta(0)
> 
Actually, that's wrong because there was a leap second. The clock went:

     1985-06-30 23:59:59
     1985-06-30 23:59:60
     1985-07-01 00:00:00

The following year, however, it went:

     1986-06-30 23:59:59
     1986-07-01 00:00:00



More information about the Python-ideas mailing list