weekday numbers (sunday not being 0)

Skip Montanaro skip at pobox.com
Wed Oct 23 13:03:20 EDT 2002


    Michal>  does anyone know why is for god's sake monday 0 and sunday 6 in
    Michal>  time.localtime().tm_wday? why have the python developers
    Michal>  decided to differ from standard C library function?

Looking back at the CVS logs, I see that behavior has been in there since
1993 when Guido added the gmtime and localtime functions to the time module.
His checkin message doesn't say why he made that semantic distinction.  One
comment in the source code says simply, "Want Monday == 0".  The only
possible reason which comes to my mind is that calendar.weekday() returns
the weekday w/ Monday == 0 and has since it was first written in 1990.
Perhaps this was a case of the tail wagging the dog.  Instead of changing
calendar.py, the behavior in timemodule.c was adjusted to suit.

Guido doesn't do things without good reason, and his general goal is for
extension modules to mimic the functions they wrap.  Perhaps he can
elaborate further.

-- 
Skip Montanaro - skip at pobox.com
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list