MonthDay

class whenever.MonthDay(iso_string: str, /)[source]
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-DD or --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
__ge__(other: MonthDay, /) → bool[source]

Return self>=value.

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

Return self>value.

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

Return self<=value.

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

Return self<value.

__str__() → str[source]

Return str(self).

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 in a given year

>>> MonthDay(8, 1).in_year(2025)
Date("2025-08-01")

Note

This method will raise a ValueError if 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.

Deprecated since version 0.11: Use is_leap_day() instead.

is_leap_day() → bool[source]

Whether the month-day is February 29th

>>> MonthDay(2, 29).is_leap_day()
True
>>> MonthDay(3, 1).is_leap_day()
False
replace(*, month: int = ..., day: int = ...) → MonthDay[source]

Create a new instance with the given fields replaced

>>> d = MonthDay(11, 23)
>>> d.replace(month=3)
MonthDay("--03-23")
MAX: ClassVar[MonthDay] = MonthDay("--12-31")

The maximum possible value of this type.

MIN: ClassVar[MonthDay] = MonthDay("--01-01")

The minimum possible value of this type.

property day: int

The day component of the month-day

property month: int

The month component of the month-day