time, calendar, datetime, etc

Dan Bishop danb_83 at yahoo.com
Sat Aug 2 06:59:00 CEST 2003

"Andrew Dalke" <adalke at mindspring.com> wrote in message news:<bgepjp$a4j$1 at slb2.atl.mindspring.net>...

> "Intractable?"!  What about defining your own class which handles
> BC dates, using datetime to do the heavy load?  All you need is
> your own offset to choose a year which has the same day-of-week
> and leapyear behaviour.  datetime says 1/1/1 was a Monday, so
> you just need a year offset X so that 12/31/X is a Sunday and
> where X is a leapyear (or not?  Don't know how the leap years
> are affected that far in the past.).

There were no leap years between 10 BC and AD 4, because after Julius
Caesar's death, the priests in charge of the calendar mistakenly added
leap days every 3 years instead of 4, and this had to be corrected.

I wouldn't expect the datetime module to deal with that, though ;-)

> Looks like X=6000 does the job.

So does any multiple of 400: The Gregorian leap year cycle is 400
years and this is coincidentally also a whole number of weeks.
> >>> datetime.date(1970, 8, 22).weekday()
>  5
> >>> datetime.date(6970, 8, 22).weekday()
>  5

The output above is my least favorite feature of the datetime module. 
It took me a while to figure out that those dates are Saturdays.

Perhaps we could add a weekday class to 2.3.1?

DAY_NAMES = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
             'Saturday', 'Sunday']
class weekday(int):
   def __repr__(self):
      return DAY_NAMES[self]
for i, name in enumerate(DAY_NAMES):
   globals()[name] = weekday(i)

More information about the Python-list mailing list