YearMonth¶
- final class whenever.YearMonth(iso_string: str, /)[source]¶
- final class whenever.YearMonth(year: int, month: int)
A year and month without a day component.
Useful for representing recurring events, billing periods, or any concept that doesn’t need a specific day.
>>> ym = YearMonth(2021, 1) YearMonth("2021-01")
Can also be constructed from an ISO 8601 string:
>>> YearMonth("2021-01") YearMonth("2021-01")
- classmethod parse_iso(s: str, /) YearMonth[source]¶
Create from the ISO 8601 format
YYYY-MMorYYYYMM.Inverse of
format_iso()>>> YearMonth.parse_iso("2021-01") YearMonth("2021-01")
- __eq__(other: object) bool[source]¶
Compare for equality
>>> ym = YearMonth(2021, 1) >>> ym == YearMonth(2021, 1) True >>> ym == YearMonth(2021, 2) False
- __str__() str¶
Format as the ISO 8601 year-month format.
Inverse of
parse_iso().>>> YearMonth(2021, 1).format_iso() '2021-01'
- format_iso() str[source]¶
Format as the ISO 8601 year-month format.
Inverse of
parse_iso().>>> YearMonth(2021, 1).format_iso() '2021-01'
- on_day(day: int, /) Date[source]¶
Create a date from this year-month with a given day
>>> YearMonth(2021, 1).on_day(2) Date("2021-01-02")