MonthDay¶
- final class whenever.MonthDay(iso_string: str, /)[source]¶
- final class whenever.MonthDay(month: int, day: int)
A month and day without a year component.
Useful for representing recurring annual events such as birthdays, holidays, or anniversaries.
>>> md = MonthDay(11, 23) MonthDay("--11-23")
Can also be constructed from an ISO 8601 string:
>>> MonthDay("--11-23") MonthDay("--11-23")
- classmethod parse_iso(s: str, /) MonthDay[source]¶
Create from the ISO 8601 format
--MM-DDor--MMDD.Inverse of
format_iso()>>> MonthDay.parse_iso("--11-23") MonthDay("--11-23")
- __eq__(other: object) bool[source]¶
Compare for equality
>>> md = MonthDay(10, 1) >>> md == MonthDay(10, 1) True >>> md == MonthDay(10, 2) False
- __str__() str¶
Format as the ISO 8601 month-day format.
Inverse of
parse_iso.>>> MonthDay(10, 8).format_iso() '--10-08'
Note
This format is officially only part of the 2000 edition of the ISO 8601 standard. There is no alternative for month-day in the newer editions. However, it is still widely used in other libraries.
- format_iso() str[source]¶
Format as the ISO 8601 month-day format.
Inverse of
parse_iso.>>> MonthDay(10, 8).format_iso() '--10-08'
Note
This format is officially only part of the 2000 edition of the ISO 8601 standard. There is no alternative for month-day in the newer editions. However, it is still widely used in other libraries.
- in_year(year: int, /) Date[source]¶
Create a date from this month-day with a given day
>>> MonthDay(8, 1).in_year(2025) Date("2025-08-01")
Note
This method will raise a
ValueErrorif the month-day is a leap day and the year is not a leap year.
- is_leap() bool[source]¶
Check if the month-day is February 29th
>>> MonthDay(2, 29).is_leap() True >>> MonthDay(3, 1).is_leap() False