OrdinalDay

when_exactly.OrdinalDay dataclass

Bases: when_exactly.core.custom_interval.CustomInterval

Represents a single day using ordinal day-of-year numbering.

An OrdinalDay is a 24-hour interval identified by its year and day number within that year (1-365 or 1-366 for leap years). This is one of three day representations in when-exactly, alongside Day (Gregorian) and Weekday (ISO week).

Attributes:

Name Type Description
start when_exactly.core.moment.Moment

The moment at midnight starting the ordinal day (inclusive).

stop when_exactly.core.moment.Moment

The moment at midnight ending the ordinal day (exclusive).

Example
>>> import when_exactly as wnx
>>> ordinal_day = wnx.OrdinalDay(2020, 1)
>>> ordinal_day
OrdinalDay(2020, 1)
>>> str(ordinal_day)
'2020-001'
>>> ordinal_day.next
OrdinalDay(2020, 2)
>>> ordinal_day.previous
OrdinalDay(2019, 365)

next property

The next ordinal day.

previous property

The previous ordinal day.

__init__(year, ordinal_day)

Create an OrdinalDay from year and ordinal day number.

Parameters:

Name Type Description Default
year int

The year.

required
ordinal_day int

The day number within the year (1-365 or 1-366).

required

Returns:

Type Description
None

An OrdinalDay interval.

__repr__()

Return the canonical string representation of the ordinal day.

__str__()

Return the ordinal day string representation.

from_moment(moment) classmethod

Create an OrdinalDay from a Moment.

Parameters:

Name Type Description Default
moment when_exactly.core.moment.Moment

The moment to extract the ordinal day from.

required

Returns:

Type Description
when_exactly._api.OrdinalDay

The OrdinalDay containing the moment.

Example
>>> import when_exactly as wnx
>>> moment = wnx.Moment(2020, 1, 1, 12, 0, 0)
>>> wnx.OrdinalDay.from_moment(moment)
OrdinalDay(2020, 1)