MCPcopy Index your code
hub / github.com/python/cpython / formatyear

Method formatyear

Lib/calendar.py:735–785  ·  view source on GitHub ↗

Returns a year's calendar as a multi-line string.

(self, theyear, w=2, l=1, c=6, m=3)

Source from the content-addressed store, hash-verified

733 return s
734
735 def formatyear(self, theyear, w=2, l=1, c=6, m=3):
736 """
737 Returns a year's calendar as a multi-line string.
738 """
739 w = max(2, w)
740 l = max(1, l)
741 c = max(2, c)
742 colwidth = (w + 1) * 7 - 1
743 v = []
744 a = v.append
745 a(repr(theyear).center(colwidth*m+c*(m-1)).rstrip())
746 a('\n'*l)
747 header = self.formatweekheader(w)
748 for (i, row) in enumerate(self.yeardays2calendar(theyear, m)):
749 # months in this row
750 months = range(m*i+1, min(m*(i+1)+1, 13))
751 a('\n'*l)
752 names = (self.formatmonthname(theyear, k, colwidth, False)
753 for k in months)
754 a(formatstring(names, colwidth, c).rstrip())
755 a('\n'*l)
756 headers = (header for k in months)
757 a(formatstring(headers, colwidth, c).rstrip())
758 a('\n'*l)
759
760 if (
761 self.highlight_day
762 and self.highlight_day.year == theyear
763 and self.highlight_day.month in months
764 ):
765 month_pos = months.index(self.highlight_day.month)
766 else:
767 month_pos = None
768
769 # max number of weeks for this row
770 height = max(len(cal) for cal in row)
771 for j in range(height):
772 weeks = []
773 for k, cal in enumerate(row):
774 if j >= len(cal):
775 weeks.append('')
776 else:
777 day = (
778 self.highlight_day.day if k == month_pos else None
779 )
780 weeks.append(
781 self.formatweek(cal[j], w, highlight_day=day)
782 )
783 a(formatstring(weeks, colwidth, c).rstrip())
784 a('\n' * l)
785 return ''.join(v)
786
787
788class _CLIDemoLocaleCalendar(LocaleTextCalendar, _CLIDemoCalendar):

Callers

nothing calls this directly

Calls 12

formatweekMethod · 0.95
enumerateFunction · 0.85
formatstringFunction · 0.85
yeardays2calendarMethod · 0.80
aClass · 0.50
rstripMethod · 0.45
centerMethod · 0.45
formatweekheaderMethod · 0.45
formatmonthnameMethod · 0.45
indexMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected