IsoWeekDate

class whenever.IsoWeekDate(iso_string: str, /)[source]
class whenever.IsoWeekDate(year: int, week: int, weekday: Weekday)

An ISO 8601 week date—a year, week number, and weekday.

The ISO week year may differ from the Gregorian year at year boundaries.

>>> iwd = IsoWeekDate(2024, 1, Weekday.MONDAY)
IsoWeekDate("2024-W01-1")

Can also be constructed from an ISO 8601 string:

>>> IsoWeekDate("2024-W01-1")
IsoWeekDate("2024-W01-1")
classmethod parse_iso(s: str, /) → IsoWeekDate[source]

Parse an ISO 8601 week date string

>>> IsoWeekDate.parse_iso("2024-W01-1")
IsoWeekDate("2024-W01-1")
__eq__(other: object, /) → bool[source]

Compare for equality

>>> IsoWeekDate(2024, 1, Weekday.MONDAY) == IsoWeekDate(2024, 1, Weekday.MONDAY)
True
__ge__(other: IsoWeekDate, /) → bool[source]

Return self>=value.

__gt__(other: IsoWeekDate, /) → bool[source]

Return self>value.

__le__(other: IsoWeekDate, /) → bool[source]

Return self<=value.

__lt__(other: IsoWeekDate, /) → bool[source]

Return self<value.

__str__() → str[source]

Return str(self).

date() → Date[source]

Convert to the corresponding Gregorian Date

>>> IsoWeekDate(2025, 1, Weekday.MONDAY).date()
Date("2024-12-30")
format_iso(*, basic: bool = False) → str[source]

Format as an ISO 8601 week date string, such as 2024-W01-1.

Inverse of parse_iso().

>>> IsoWeekDate(2024, 1, Weekday.MONDAY).format_iso()
'2024-W01-1'
>>> IsoWeekDate(2024, 1, Weekday.MONDAY).format_iso(basic=True)
'2024W011'
Parameters:

basic – Whether to use the basic ISO format (without separators) instead of the extended one.

replace(*, year: int = ..., week: int = ..., weekday: Weekday = ...) → IsoWeekDate[source]

Create a new instance with the given fields replaced

A week beyond the year’s count raises ValueError.

>>> IsoWeekDate(2024, 1, Weekday.MONDAY).replace(week=10)
IsoWeekDate("2024-W10-1")
weeks_in_year() → int[source]

Number of weeks in this ISO week year (52 or 53)

>>> IsoWeekDate(2004, 53, Weekday.FRIDAY).weeks_in_year()
53
>>> IsoWeekDate(2024, 1, Weekday.MONDAY).weeks_in_year()
52
MAX: ClassVar[IsoWeekDate] = IsoWeekDate("9999-W52-5")

The maximum possible value of this type.

MIN: ClassVar[IsoWeekDate] = IsoWeekDate("0001-W01-1")

The minimum possible value of this type.

property week: int

The ISO week number (1–53)

property weekday: Weekday

The day of the week

property year: int

The ISO week year