time Module Inconsistencies

Tim Peters tim.one at comcast.net
Thu Feb 20 02:37:09 CET 2003


[Martin Miller]
> In the standard Python time module, the item at index 6 of the "time
> tuple" which is returned from gmtime() and localtime() is defined to be
> an integer in the range [0,6] where Monday is 0.
>
> However, the "%w" format directive to strftime(), when given the same
> sort of tuple, returns a weekday number decimal string where Sunday
> equals 0.
>
> This unnecessarily complicates certain common sorts of date
> manipulations, IMHO (and probably also does the same to some degree to
> the internals of the time module's routines, I imagine).

It's really limited to one line in tmtotuple():

	SET(6, (p->tm_wday + 6) % 7); /* Want Monday == 0 */


> Does anywone know why this came to be this way? It probably can't be
> changed at this point in time without breaking too much existing code,
> but I'm curious if there's a logical explanation.

If you hear one, let us know <wink>.  I don't know.  You're absolutely right
that it can't be changed anymore.  It may be because Guido is European, and
the ISO week begins on Monday.  OTOH, ISO numbers days with 1-7, not 0-6.






More information about the Python-list mailing list