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

Method formatyear

Lib/calendar.py:426–462  ·  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

424 return s
425
426 def formatyear(self, theyear, w=2, l=1, c=6, m=3):
427 """
428 Returns a year's calendar as a multi-line string.
429 """
430 w = max(2, w)
431 l = max(1, l)
432 c = max(2, c)
433 colwidth = (w + 1) * 7 - 1
434 v = []
435 a = v.append
436 a(repr(theyear).center(colwidth*m+c*(m-1)).rstrip())
437 a('\n'*l)
438 header = self.formatweekheader(w)
439 for (i, row) in enumerate(self.yeardays2calendar(theyear, m)):
440 # months in this row
441 months = range(m*i+1, min(m*(i+1)+1, 13))
442 a('\n'*l)
443 names = (self.formatmonthname(theyear, k, colwidth, False)
444 for k in months)
445 a(formatstring(names, colwidth, c).rstrip())
446 a('\n'*l)
447 headers = (header for k in months)
448 a(formatstring(headers, colwidth, c).rstrip())
449 a('\n'*l)
450
451 # max number of weeks for this row
452 height = max(len(cal) for cal in row)
453 for j in range(height):
454 weeks = []
455 for cal in row:
456 if j >= len(cal):
457 weeks.append('')
458 else:
459 weeks.append(self.formatweek(cal[j], w))
460 a(formatstring(weeks, colwidth, c).rstrip())
461 a('\n' * l)
462 return ''.join(v)
463
464 def pryear(self, theyear, w=0, l=0, c=6, m=3):
465 """Print a year's calendar."""

Callers 4

pryearMethod · 0.95
test_format_yearMethod · 0.45
test_format_year_headMethod · 0.45

Calls 11

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

Tested by 3

test_format_yearMethod · 0.36
test_format_year_headMethod · 0.36