Message119048
The most pedantic implementation of calendar.isleap() would be
from datetime import date, timedelta
def isleap(year):
return date(year, 3, 1) - date(year, 2, 1) == timedelta(29)
Since python calendar only supports years in the range [1, 9999], the above will properly raise ValueError: year is out of range on negative or zero year. This also guarantees that calendar module's notion of leap year is the same as that of datetime module.
If this is found to be a worthwhile change, I would also rewrite monthrange as
def monthrange(year, month):
first = date(year, month, 1)
if month == 12:
ndays = 31
else:
ndays = (date(year, month + 1, 1) - first).days
return first.weekday(), ndays |
|
Date |
User |
Action |
Args |
2010-10-18 17:59:27 | belopolsky | set | recipients:
+ belopolsky, georg.brandl, terry.reedy, pjenvey, eric.araujo, Retro, r.david.murray, shadikka |
2010-10-18 17:59:27 | belopolsky | set | messageid: <1287424767.34.0.282370740611.issue10073@psf.upfronthosting.co.za> |
2010-10-18 17:59:25 | belopolsky | link | issue10073 messages |
2010-10-18 17:59:25 | belopolsky | create | |
|