Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Lib/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ def __len__(self):
month_name = _localized_month('%B')
month_abbr = _localized_month('%b')

# Check if the platform supports the %OB format code
def _is_alt_mon_available():
try:
datetime.date(2001, 1, 1).strftime('%OB')
datetime.date(2001, 1, 1).strftime('%Ob')
except ValueError:
return False
return True

# In Greek and in many Slavic and Baltic languages, "%OB" will produce
# the month in nominative case.
if _is_alt_mon_available():
alt_month_name = _localized_month('%OB')
alt_month_abbr = _localized_month('%Ob')
else:
alt_month_name = month_name
alt_month_abbr = month_abbr


def isleap(year):
"""Return True for leap years, False for non-leap years."""
Expand Down Expand Up @@ -377,7 +395,7 @@ def formatmonthname(self, theyear, themonth, width, withyear=True):
"""
_validate_month(themonth)

s = month_name[themonth]
s = alt_month_name[themonth]
if withyear:
s = "%s %r" % (s, theyear)
return s.center(width)
Expand Down Expand Up @@ -510,9 +528,9 @@ def formatmonthname(self, theyear, themonth, withyear=True):
"""
_validate_month(themonth)
if withyear:
s = '%s %s' % (month_name[themonth], theyear)
s = '%s %s' % (alt_month_name[themonth], theyear)
else:
s = '%s' % month_name[themonth]
s = '%s' % alt_month_name[themonth]
return '<tr><th colspan="7" class="%s">%s</th></tr>' % (
self.cssclass_month_head, s)

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,8 @@ def test__all__(self):
not_exported = {
'mdays', 'January', 'February', 'EPOCH',
'different_locale', 'c', 'prweek', 'week', 'format',
'formatstring', 'main', 'monthlen', 'prevmonth', 'nextmonth', ""}
'formatstring', 'main', 'monthlen', 'prevmonth', 'nextmonth',
'alt_month_name', 'alt_month_abbr', ""}
support.check__all__(self, calendar, not_exported=not_exported)


Expand Down
Loading