You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I agree, I think this would be very useful. I use a function that does this quite often.
Should also be added to calendar.py's __all__.
ark3 commented on Nov 20, 2010
ark3mannequin
Mannequin
More actions
The test is incorrect on leap years for February 29, due to the way it constructs its list of dates. The function itself appears to give the right answer.
ark3 commented on Nov 20, 2010
ark3mannequin
Mannequin
More actions
Quick hack alternative test. It would look nicer if the test used the datetime module, but I'm not sure that would be appropriate.
deftest_dayofyear(self):
"""Test for the calendar.dayofyear() function, which computes the integer between 1 and 366 (inclusive) representing the specified day in the specified month of the specified year. """forexpected_total, yearin (366, 2008), (365, 2010):
expected_day_of_year=1formonthinrange(1, 13):
lastDay=calendar.mdays[month]
ifyear==2008andmonth==2:
lastDay=29fordayinrange(1, lastDay+1):
day_of_year=calendar.dayofyear(year, month, day)
self.assertEqual(expected_day_of_year, day_of_year)
# The computed day of the year must be between 1 and 366. self.assertGreaterEqual(day_of_year, 1)
self.assertLessEqual(day_of_year, 366)
expected_day_of_year+=1self.assertEqual(expected_day_of_year-1, expected_total)
I don't see why we need a new function for this or why it would be put in the calendar module (where some of its functions have been supplanted by the datetime module).
This is yet another request for functionality that can be implemented as a simple expression using datetime arithmetics. Also, issue bpo-9864 is not a compelling use case because "the parsedate() function now returns a datetime object." See msg117496.
Activity
jfinkels commentedon Sep 21, 2010
This is a function which computes the integer between 1 and 366 representing the day of the year, given a year, month, and day.
The implementation I have provided computes the difference between the ordinal numbers of the given day and January first of that month.
This will be useful in resolving bpo-9864, in which parsing of date strings has an unimplemented "day of year" feature.
JJeffries commentedon Oct 17, 2010
I agree, I think this would be very useful. I use a function that does this quite often.
Should also be added to calendar.py's __all__.
ark3 commentedon Nov 20, 2010
The test is incorrect on leap years for February 29, due to the way it constructs its list of dates. The function itself appears to give the right answer.
ark3 commentedon Nov 20, 2010
Quick hack alternative test. It would look nicer if the test used the datetime module, but I'm not sure that would be appropriate.
rhettinger commentedon Nov 21, 2010
"We already got one, and it's very nice-a"
ISTM, this should be done with regular date arithmetic in the datetime module.
I don't see why we need a new function for this or why it would be put in the calendar module (where some of its functions have been supplanted by the datetime module).
abalkin commentedon Jan 6, 2011
This is yet another request for functionality that can be implemented as a simple expression using datetime arithmetics. Also, issue bpo-9864 is not a compelling use case because "the parsedate() function now returns a datetime object." See msg117496.