msg117024 - (view) |
Author: Jeffrey Finkelstein (jfinkels) * |
Date: 2010-09-21 03:27 |
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 , in which parsing of date strings has an unimplemented "day of year" feature. |
|
|
msg118941 - (view) |
Author: JJeffries (JJeffries) |
Date: 2010-10-17 13:27 |
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__. |
|
|
msg121773 - (view) |
Author: Abhay Saxena (ark3) |
Date: 2010-11-20 20:57 |
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. |
|
|
msg121776 - (view) |
Author: Abhay Saxena (ark3) |
Date: 2010-11-20 21:07 |
Quick hack alternative test. It would look nicer if the test used the datetime module, but I'm not sure that would be appropriate. def test_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. """ for expected_total, year in (366, 2008), (365, 2010): expected_day_of_year = 1 for month in range(1, 13): lastDay = calendar.mdays[month] if year == 2008 and month == 2: lastDay = 29 for day in range(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 += 1 self.assertEqual(expected_day_of_year - 1, expected_total) |
|
|
msg121824 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2010-11-21 01:02 |
"We already got one, and it's very nice-a" ISTM, this should be done with regular date arithmetic in the datetime module. >>> date(1964, 7, 31) - date(1963, 12, 31) datetime.timedelta(213) 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). |
|
|
msg125568 - (view) |
Author: Alexander Belopolsky (belopolsky) *  |
Date: 2011-01-06 17:15 |
This is yet another request for functionality that can be implemented as a simple expression using datetime arithmetics. Also, issue #9864 is not a compelling use case because "the parsedate() function now returns a datetime object." See . |
|
|