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

Function _isoweek_to_gregorian

Lib/_pydatetime.py:511–540  ·  view source on GitHub ↗
(year, week, day)

Source from the content-addressed store, hash-verified

509
510# tuple[int, int, int] -> tuple[int, int, int] version of date.fromisocalendar
511def _isoweek_to_gregorian(year, week, day):
512 # Year is bounded this way because 9999-12-31 is (9999, 52, 5)
513 if not MINYEAR <= year <= MAXYEAR:
514 raise ValueError(f"year must be in {MINYEAR}..{MAXYEAR}, not {year}")
515
516 if not 0 < week < 53:
517 out_of_range = True
518
519 if week == 53:
520 # ISO years have 53 weeks in them on years starting with a
521 # Thursday and leap years starting on a Wednesday
522 first_weekday = _ymd2ord(year, 1, 1) % 7
523 if (first_weekday == 4 or (first_weekday == 3 and
524 _is_leap(year))):
525 out_of_range = False
526
527 if out_of_range:
528 raise ValueError(f"Invalid week: {week}")
529
530 if not 0 < day < 8:
531 raise ValueError(f"Invalid weekday: {day} (range is [1, 7])")
532
533 # Now compute the offset from (Y, 1, 1) in days:
534 day_offset = (week - 1) * 7 + (day - 1)
535
536 # Calculate the ordinal day for monday, week 1
537 day_1 = _isoweek1monday(year)
538 ord_day = day_1 + day_offset
539
540 return _ord2ymd(ord_day)
541
542
543# Just raise TypeError if the arg isn't None or a string.

Callers 2

_parse_isoformat_dateFunction · 0.85
fromisocalendarMethod · 0.85

Calls 4

_ymd2ordFunction · 0.85
_is_leapFunction · 0.85
_isoweek1mondayFunction · 0.85
_ord2ymdFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…