MCPcopy Create free account
hub / github.com/RustPython/RustPython / formatyear

Method formatyear

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

405 return s
406
407 def formatyear(self, theyear, w=2, l=1, c=6, m=3):
408 """
409 Returns a year's calendar as a multi-line string.
410 """
411 w = max(2, w)
412 l = max(1, l)
413 c = max(2, c)
414 colwidth = (w + 1) * 7 - 1
415 v = []
416 a = v.append
417 a(repr(theyear).center(colwidth*m+c*(m-1)).rstrip())
418 a('\n'*l)
419 header = self.formatweekheader(w)
420 for (i, row) in enumerate(self.yeardays2calendar(theyear, m)):
421 # months in this row
422 months = range(m*i+1, min(m*(i+1)+1, 13))
423 a('\n'*l)
424 names = (self.formatmonthname(theyear, k, colwidth, False)
425 for k in months)
426 a(formatstring(names, colwidth, c).rstrip())
427 a('\n'*l)
428 headers = (header for k in months)
429 a(formatstring(headers, colwidth, c).rstrip())
430 a('\n'*l)
431
432 # max number of weeks for this row
433 height = max(len(cal) for cal in row)
434 for j in range(height):
435 weeks = []
436 for cal in row:
437 if j >= len(cal):
438 weeks.append('')
439 else:
440 weeks.append(self.formatweek(cal[j], w))
441 a(formatstring(weeks, colwidth, c).rstrip())
442 a('\n' * l)
443 return ''.join(v)
444
445 def pryear(self, theyear, w=0, l=0, c=6, m=3):
446 """Print a year's calendar."""

Callers 4

pryearMethod · 0.95
test_format_yearMethod · 0.45
test_format_year_headMethod · 0.45

Calls 15

formatweekheaderMethod · 0.95
formatmonthnameMethod · 0.95
formatweekMethod · 0.95
maxFunction · 0.85
reprFunction · 0.85
enumerateFunction · 0.85
minFunction · 0.85
formatstringFunction · 0.85
lenFunction · 0.85
yeardays2calendarMethod · 0.80
aClass · 0.50
rstripMethod · 0.45

Tested by 3

test_format_yearMethod · 0.36
test_format_year_headMethod · 0.36