I'm writing a program that needs to be able to handle multiple calendars (mainly the standard “proleptic Gregorian” and the "365 day" (no leap) calendars). The python datetime module handles the Gregorian calendar out of the box but I'd like to also have it handle other calendars.
A short example:
from datetime import datetime
import calendar
def example(year):
delta = datetime(year, 3, 1) - datetime(year, 2, 28)
print '%i is a leap year: %s' % (year, calendar.isleap(year))
print 'Days between 2-28 and 3-1: %s' % delta.days
example(2012)
2012 is a leap year: True
Days between 2-28 and 3-1: 2
example(2013)
2013 is a leap year: False
Days between 2-28 and 3-1: 1
This is certainly the intended operation of the module but it doesn't serve my particular needs. I'd like to be able to set the calendar to 'noleap' and retain the functionality of datetime and timedelta.
I'm wondering if anyone have any experience defining/using a custom calendar with datetime?