(year, week, day)
| 457 | |
| 458 | # tuple[int, int, int] -> tuple[int, int, int] version of date.fromisocalendar |
| 459 | def _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. |
no test coverage detected