Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why does time.gmtime() use Monday=0?

51 views
Skip to first unread message

Tim Bell

unread,
Jun 14, 2000, 3:00:00 AM6/14/00
to
Hi,

Can anyone tell me why time.gmtime() (and time.localtime()) use the
convention that Monday=0, rather than Sunday=0? The Sunday=0 convention
is used by C's gmtime(3), as well as both C and Python's strftime().
Oh, and Python's strptime() uses Monday=0 also, but C's uses Sunday=0.

Here's the relevant code from tmtotuple() in python-1.5.2/Modules/timemodule.c,
line 262:

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

Why does Python go out of its way to be inconsistant, both with itself
and with C? (Or have I missed something here?)

Any enlightenment would be appreciated.

Tim.
--
Tim Bell - bh...@cs.mu.oz.au - Dept of Comp Sci & SE - Uni of Melbourne, Aust.


Tim Bell

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to

Huaiyu Zhu

unread,
Jun 16, 2000, 3:00:00 AM6/16/00
to
On 15 Jun 2000 12:46:55 +1000, Tim Bell <bh...@cs.mu.OZ.AU> wrote:
>
>Can anyone tell me why time.gmtime() (and time.localtime()) use the
>convention that Monday=0, rather than Sunday=0? The Sunday=0 convention
>is used by C's gmtime(3), as well as both C and Python's strftime().
>Oh, and Python's strptime() uses Monday=0 also, but C's uses Sunday=0.
>
>Here's the relevant code from tmtotuple() in python-1.5.2/Modules/timemodule.c,
>line 262:
>
> (p->tm_wday + 6) % 7, /* Want Monday == 0 */
>
>Why does Python go out of its way to be inconsistant, both with itself
>and with C? (Or have I missed something here?)

Is this a misfeature of python, inspired by the desire of making every
sequence starting at 0, presumably for consistency's sake?

But consistency is illusive here: we count dates, months and years starting
at 1 while hours, minutes and seconds starting at 0. If any, counting
weekdays the same as dates would be more consistent.

Speaking of other languages (real ones): In Chinese the names for Monday to
Saturday are "Weekday one" to "Weekday six". And the names for the months
(1 to 12) has been around for thousands of years. Do we also want to count
January as 0? :-)


Huaiyu

0 new messages