This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients belopolsky, doerwalter, serhiy.storchaka, xiang.zhang
Date 2016-09-27.17:17:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474996655.78.0.455444297242.issue28281@psf.upfronthosting.co.za>
In-reply-to
Content
> What's the use case for this?

Why did George Mallory climb Mount Everest? "Because it's there."

We have two open issues complaining about calendar behavior for years 1 and 9999: #28253 and #26650.  There is also a closed issue #15421 that attempted to fix an overflow in the year 9999 only to introduce a silent error.

I don't think there are use cases beyond educational (demonstrating calendar periodicity?) or testing, but since several users bothered to report edge case bugs, it is probably easier to remove the limits than to properly document them.

Fortunately, extending calendar to arbitrary years does not require climbing Mount Everest.  Since the proleptic calendar repeats every 400 years, all we need (assuming issue 28253 patch is applied) is to fix the weekday() function as follows:

 def weekday(year, month, day):
     """Return weekday (0-6 ~ Mon-Sun) for year (1970-...), month (1-12),
        day (1-31)."""
+    if not 0 < year < 10000:
+        year = 2000 + year % 400
     return datetime.date(year, month, day).weekday()

$ ./python.exe -mcalendar 40000 12
   December 40000
Mo Tu We Th Fr Sa Su
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

$ ./python.exe -mcalendar -104 2
   February -104
Mo Tu We Th Fr Sa Su
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29

We can also treat negative years "properly" so that year 1 is preceded by year -1, but I don't think there is any value in this.
History
Date User Action Args
2016-09-27 17:17:35belopolskysetrecipients: + belopolsky, doerwalter, serhiy.storchaka, xiang.zhang
2016-09-27 17:17:35belopolskysetmessageid: <1474996655.78.0.455444297242.issue28281@psf.upfronthosting.co.za>
2016-09-27 17:17:35belopolskylinkissue28281 messages
2016-09-27 17:17:35belopolskycreate