Issue 9909: request for calendar.dayofyear() function (original) (raw)

Issue9909

Created on 2010-09-21 03:27 by jfinkels, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
dayofyear.patch jfinkels,2010-09-21 03:27 Adds calendar.dayofyear() function.
Messages (6)
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) * (Python committer) 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) * (Python committer) 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 .
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 54118
2011-03-24 19:31:28 belopolsky set status: pending -> closed
2011-01-06 17:15:45 belopolsky set status: open -> pendingnosy:rhettinger, belopolsky, jfinkels, JJeffries, ark3messages: + assignee: belopolskyresolution: rejected
2011-01-06 16:42:23 pitrou set nosy: + belopolsky
2010-11-21 01:02:50 rhettinger set priority: normal -> lownosy: + rhettingermessages: +
2010-11-20 21:07:01 ark3 set messages: +
2010-11-20 20:57:48 ark3 set nosy: + ark3messages: +
2010-10-17 13:27:50 JJeffries set nosy: + JJeffriesmessages: +
2010-09-21 14:55:24 belopolsky link issue9864 dependencies
2010-09-21 03:27:41 jfinkels create