Year
when_exactly.Year
dataclass
Bases: when_exactly.core.custom_interval.CustomInterval
The Year represents an entire year, starting from January 1 to December 31.
Creating a Year
>>> import when_exactly as wnx
>>> year = wnx.Year(2025)
>>> year
Year(2025)
>>> str(year)
'2025'
The Months of a Year
Get the Months of a year.
>>> months = year.months
>>> len(months)
12
>>> months[0]
Month(2025, 1)
>>> months[-2:]
Months([Month(2025, 11), Month(2025, 12)])
The Weeks of a Year
Get the Weeks of a year.
>>> weeks = year.weeks
>>> len(weeks)
52
>>> weeks[0]
Week(2025, 1)
__init__(year)
Create a Year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The year to represent. |
required |
Examples:
>>> import when_exactly as wnx
>>> year = wnx.Year(2025)
>>> year
Year(2025)
>>> str(year)
'2025'
from_moment(moment)
classmethod
Create a Year from a Moment.
month(month)
Get a specific month of the year. Args: month (int): The month number (1-12).