MCPcopy Index your code
hub / github.com/RustPython/RustPython / _isoweek_to_gregorian

Function _isoweek_to_gregorian

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

Source from the content-addressed store, hash-verified

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