Week
when_exactly.Week
dataclass
Bases: when_exactly.core.custom_interval.CustomInterval
Represents an ISO 8601 week, from Monday to Sunday.
A Week is a 7-day interval following the ISO 8601 week date system. Weeks are numbered from 1 to 52 (or 53 in some years). Week 1 is the first week containing a Thursday.
Attributes:
| Name | Type | Description |
|---|---|---|
start |
when_exactly.core.moment.Moment
|
The moment at the beginning of Monday (inclusive). |
stop |
when_exactly.core.moment.Moment
|
The moment at the beginning of the next Monday (exclusive). |
Example
>>> import when_exactly as wnx
>>> week = wnx.Week(2020, 1)
>>> week
Week(2020, 1)
>>> str(week)
'2020-W01'
>>> week.next
Week(2020, 2)
>>> week.previous
Week(2019, 52)
>>> week.week_day(1)
Weekday(2020, 1, 1)
>>> len(week.week_days)
7
days
cached
property
All seven days in this week as Day objects.
next
property
The next week.
previous
property
The previous week.
week_days
cached
property
All seven weekdays in this week.
__init__(year, week)
Create a Week from ISO week year and week number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The ISO week year. |
required |
week
|
int
|
The week number (1-52 or 1-53). |
required |
Returns:
| Type | Description |
|---|---|
None
|
A Week interval. |
__repr__()
Return the canonical string representation of the week.
__str__()
Return the ISO 8601 string representation of the week.
from_moment(moment)
classmethod
Create a Week from a Moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moment
|
when_exactly.core.moment.Moment
|
The moment to extract the week from. |
required |
Returns:
| Type | Description |
|---|---|
when_exactly._api.Week
|
The Week containing the moment. |
Example
>>> import when_exactly as wnx
>>> moment = wnx.Moment(2020, 1, 3, 12, 0, 0)
>>> wnx.Week.from_moment(moment)
Week(2020, 1)
week_day(week_day)
Get a specific weekday of the week.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
week_day
|
int
|
The day of week (1=Monday, 7=Sunday). |
required |
Returns:
| Type | Description |
|---|---|
when_exactly._api.Weekday
|
The Weekday for the specified day. |
Example
>>> import when_exactly as wnx
>>> week = wnx.Week(2020, 1)
>>> week.week_day(1)
Weekday(2020, 1, 1)