Weekday
when_exactly.Weekday
dataclass
Bases: when_exactly.core.custom_interval.CustomInterval
Represents a single day within an ISO 8601 week.
A Weekday is a 24-hour interval identified by its ISO week year, week number, and day of week (1=Monday through 7=Sunday). This is one of three day representations in when-exactly, alongside Day (Gregorian) and OrdinalDay.
Attributes:
| Name | Type | Description |
|---|---|---|
start |
when_exactly.core.moment.Moment
|
The moment at midnight starting the weekday (inclusive). |
stop |
when_exactly.core.moment.Moment
|
The moment at midnight ending the weekday (exclusive). |
Example
>>> import when_exactly as wnx
>>> weekday = wnx.Weekday(2020, 1, 1)
>>> weekday
Weekday(2020, 1, 1)
>>> str(weekday)
'2020-W01-1'
>>> weekday.next
Weekday(2020, 1, 2)
>>> weekday.week
Week(2020, 1)
>>> weekday.to_day()
Day(2019, 12, 30)
next
property
The next weekday.
previous
property
The previous weekday.
week
cached
property
The week containing this weekday.
__init__(year, week, week_day)
Create a Weekday from ISO week year, week number, and weekday.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The ISO week year. |
required |
week
|
int
|
The week number (1-52 or 1-53). |
required |
week_day
|
int
|
The day of week (1=Monday, 7=Sunday). |
required |
Returns:
| Type | Description |
|---|---|
|
A Weekday interval. |
__repr__()
Return the canonical string representation of the weekday.
__str__()
Return the ISO 8601 string representation of the weekday.
from_moment(moment)
classmethod
Create a Weekday from a Moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moment
|
when_exactly.core.moment.Moment
|
The moment to extract the weekday from. |
required |
Returns:
| Type | Description |
|---|---|
when_exactly._api.Weekday
|
The Weekday containing the moment. |
Example
>>> import when_exactly as wnx
>>> moment = wnx.Moment(2019, 12, 30, 12, 0, 0)
>>> wnx.Weekday.from_moment(moment)
Weekday(2020, 1, 1)
to_day()
Convert this weekday to a Day (Gregorian calendar).
Returns:
| Type | Description |
|---|---|
when_exactly._api.Day
|
The corresponding Day object. |
Example
>>> import when_exactly as wnx
>>> weekday = wnx.Weekday(2020, 1, 1)
>>> weekday.to_day()
Day(2019, 12, 30)