Calendar Module
The solcadre.calendar module generates localized Solcadre calendars and provides helpers to map arbitrary datetimes to Solcadre dates and times.
calendar
Implementation of the Solcadre calendar system.
This module provides the core calendar functionality: generating localized days, weeks, blocks, and years aligned to solar events, as well as helpers to map arbitrary datetimes to Solcadre Day, Week, Block, Year, and Time objects.
Classes
Calendar
dataclass
Calendar system that calculates days based on solar events and geographic location.
The calendar generates a sequence of days based on sunrise/sunset times for a given location. Seasons and transitions are automatically adjusted based on the hemisphere.
Attributes:
| Name | Type | Description |
|---|---|---|
latitude |
float
|
The latitude for solar calculations (defaults to canonical). |
longitude |
float
|
The longitude for solar calculations (defaults to canonical). |
timezone |
ZoneInfo
|
The timezone for solar calculations (defaults to canonical). |
observer |
ZoneInfo
|
Astral observer object for solar calculations. |
hemisphere |
ZoneInfo
|
The hemisphere determined from latitude. |
epoch |
ZoneInfo
|
The first day of the calendar. |
Functions
__post_init__
Initialize the calendar with observer, hemisphere, and cached iterators.
Source code in src/solcadre/calendar.py
block_of
Get the Block object that contains the given day or week.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Day | Week
|
The Day or Week object to find the block for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Block |
Block
|
The Block object (season or transition) containing the given object. |
Source code in src/solcadre/calendar.py
find_block
Find the Block object that contains the given datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime to search for. |
required |
Returns:
| Type | Description |
|---|---|
Block | None
|
Block | None: The Block object containing the time, or None if not found. |
Source code in src/solcadre/calendar.py
find_day
Find the Day object that contains the given datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime to search for. |
required |
Returns:
| Type | Description |
|---|---|
Day | None
|
Day | None: The Day object containing the time, or None if not found. |
Source code in src/solcadre/calendar.py
find_time
Find the Time object that corresponds to the given time point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
A timezone-aware datetime to locate within the calendar. |
required |
Returns:
| Type | Description |
|---|---|
Time | None
|
Time | None: A Time object representating the time point, or None if not found. |
Source code in src/solcadre/calendar.py
find_week
Find the Week object that contains the given datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime to search for. |
required |
Returns:
| Type | Description |
|---|---|
Week | None
|
Week | None: The Week object containing the time, or None if not found. |
Source code in src/solcadre/calendar.py
find_year
Find the Year object that contains the given datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime to search for. |
required |
Returns:
| Type | Description |
|---|---|
Year | None
|
Year | None: The Year object containing the time, or None if not found. |
Source code in src/solcadre/calendar.py
iter_blocks
Iterate over blocks (seasons and transitions) in the calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_block
|
Block | None
|
Optional Block object to start iteration from (inclusive). If None, starts from the beginning. |
None
|
end_block
|
Block | None
|
Optional Block object to end iteration at (exclusive). If None, continues to the end. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Block]
|
Iterable[Block]: An iterator over Block objects in chronological order. |
Source code in src/solcadre/calendar.py
iter_days
Iterate over days in the calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_day
|
Day | None
|
Optional Day object to start iteration from (inclusive). If None, starts from the beginning. |
None
|
end_day
|
Day | None
|
Optional Day object to end iteration at (exclusive). If None, continues to the end. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Day]
|
Iterable[Day]: An iterator over Day objects in chronological order. |
Source code in src/solcadre/calendar.py
iter_weeks
Iterate over weeks in the calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_week
|
Week | None
|
Optional Week object to start iteration from (inclusive). If None, starts from the beginning. |
None
|
end_week
|
Week | None
|
Optional Week object to end iteration at (exclusive). If None, continues to the end. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Week]
|
Iterable[Week]: An iterator over Week objects in chronological order. |
Source code in src/solcadre/calendar.py
iter_years
Iterate over years in the calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_year
|
Year | None
|
Optional Year object to start iteration from (inclusive). If None, starts from the beginning. |
None
|
end_year
|
Year | None
|
Optional Year object to end iteration at (exclusive). If None, continues to the end. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Year]
|
Iterable[Year]: An iterator over Year objects in chronological order. |
Source code in src/solcadre/calendar.py
week_of
year_of
Get the Year object that contains the given day, week, or block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Day | Week | Block
|
The Day, Week, or Block object to find the year for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Year |
Year
|
The Year object containing the given object. |
Source code in src/solcadre/calendar.py
InvalidLatitude
Bases: Exception
Exception raised when a latitude value is invalid for Solcadre.
This occurs when the latitude is too close to the poles, resulting in days where sunrise or sunset cannot be calculated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
The invalid latitude value. |
required | |
message
|
Additional error message describing why the latitude is invalid. |
required |
Source code in src/solcadre/calendar.py
Calendar
Calendar
dataclass
Calendar system that calculates days based on solar events and geographic location.
The calendar generates a sequence of days based on sunrise/sunset times for a given location. Seasons and transitions are automatically adjusted based on the hemisphere.
Attributes:
| Name | Type | Description |
|---|---|---|
latitude |
float
|
The latitude for solar calculations (defaults to canonical). |
longitude |
float
|
The longitude for solar calculations (defaults to canonical). |
timezone |
ZoneInfo
|
The timezone for solar calculations (defaults to canonical). |
observer |
ZoneInfo
|
Astral observer object for solar calculations. |
hemisphere |
ZoneInfo
|
The hemisphere determined from latitude. |
epoch |
ZoneInfo
|
The first day of the calendar. |
Functions
__post_init__
Initialize the calendar with observer, hemisphere, and cached iterators.
Source code in src/solcadre/calendar.py
block_of
Get the Block object that contains the given day or week.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Day | Week
|
The Day or Week object to find the block for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Block |
Block
|
The Block object (season or transition) containing the given object. |
Source code in src/solcadre/calendar.py
find_block
Find the Block object that contains the given datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime to search for. |
required |
Returns:
| Type | Description |
|---|---|
Block | None
|
Block | None: The Block object containing the time, or None if not found. |
Source code in src/solcadre/calendar.py
find_day
Find the Day object that contains the given datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime to search for. |
required |
Returns:
| Type | Description |
|---|---|
Day | None
|
Day | None: The Day object containing the time, or None if not found. |
Source code in src/solcadre/calendar.py
find_time
Find the Time object that corresponds to the given time point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
A timezone-aware datetime to locate within the calendar. |
required |
Returns:
| Type | Description |
|---|---|
Time | None
|
Time | None: A Time object representating the time point, or None if not found. |
Source code in src/solcadre/calendar.py
find_week
Find the Week object that contains the given datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime to search for. |
required |
Returns:
| Type | Description |
|---|---|
Week | None
|
Week | None: The Week object containing the time, or None if not found. |
Source code in src/solcadre/calendar.py
find_year
Find the Year object that contains the given datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime
|
The datetime to search for. |
required |
Returns:
| Type | Description |
|---|---|
Year | None
|
Year | None: The Year object containing the time, or None if not found. |
Source code in src/solcadre/calendar.py
iter_blocks
Iterate over blocks (seasons and transitions) in the calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_block
|
Block | None
|
Optional Block object to start iteration from (inclusive). If None, starts from the beginning. |
None
|
end_block
|
Block | None
|
Optional Block object to end iteration at (exclusive). If None, continues to the end. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Block]
|
Iterable[Block]: An iterator over Block objects in chronological order. |
Source code in src/solcadre/calendar.py
iter_days
Iterate over days in the calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_day
|
Day | None
|
Optional Day object to start iteration from (inclusive). If None, starts from the beginning. |
None
|
end_day
|
Day | None
|
Optional Day object to end iteration at (exclusive). If None, continues to the end. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Day]
|
Iterable[Day]: An iterator over Day objects in chronological order. |
Source code in src/solcadre/calendar.py
iter_weeks
Iterate over weeks in the calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_week
|
Week | None
|
Optional Week object to start iteration from (inclusive). If None, starts from the beginning. |
None
|
end_week
|
Week | None
|
Optional Week object to end iteration at (exclusive). If None, continues to the end. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Week]
|
Iterable[Week]: An iterator over Week objects in chronological order. |
Source code in src/solcadre/calendar.py
iter_years
Iterate over years in the calendar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_year
|
Year | None
|
Optional Year object to start iteration from (inclusive). If None, starts from the beginning. |
None
|
end_year
|
Year | None
|
Optional Year object to end iteration at (exclusive). If None, continues to the end. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Year]
|
Iterable[Year]: An iterator over Year objects in chronological order. |
Source code in src/solcadre/calendar.py
week_of
year_of
Get the Year object that contains the given day, week, or block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Day | Week | Block
|
The Day, Week, or Block object to find the year for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Year |
Year
|
The Year object containing the given object. |
Source code in src/solcadre/calendar.py
Exceptions
InvalidLatitude
Bases: Exception
Exception raised when a latitude value is invalid for Solcadre.
This occurs when the latitude is too close to the poles, resulting in days where sunrise or sunset cannot be calculated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
The invalid latitude value. |
required | |
message
|
Additional error message describing why the latitude is invalid. |
required |