MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _isoweek_to_gregorian

Function _isoweek_to_gregorian

tools/python-3.11.9-amd64/Lib/datetime.py:459–488  ·  view source on GitHub ↗
(year, week, day)

Source from the content-addressed store, hash-verified

457
458# tuple[int, int, int] -> tuple[int, int, int] version of date.fromisocalendar
459def _isoweek_to_gregorian(year, week, day):
460 # Year is bounded this way because 9999-12-31 is (9999, 52, 5)
461 if not MINYEAR <= year <= MAXYEAR:
462 raise ValueError(f"Year is out of range: {year}")
463
464 if not 0 < week < 53:
465 out_of_range = True
466
467 if week == 53:
468 # ISO years have 53 weeks in them on years starting with a
469 # Thursday and leap years starting on a Wednesday
470 first_weekday = _ymd2ord(year, 1, 1) % 7
471 if (first_weekday == 4 or (first_weekday == 3 and
472 _is_leap(year))):
473 out_of_range = False
474
475 if out_of_range:
476 raise ValueError(f"Invalid week: {week}")
477
478 if not 0 < day < 8:
479 raise ValueError(f"Invalid weekday: {day} (range is [1, 7])")
480
481 # Now compute the offset from (Y, 1, 1) in days:
482 day_offset = (week - 1) * 7 + (day - 1)
483
484 # Calculate the ordinal day for monday, week 1
485 day_1 = _isoweek1monday(year)
486 ord_day = day_1 + day_offset
487
488 return _ord2ymd(ord_day)
489
490
491# 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