calendar_smith package¶
Submodules¶
calendar_smith.core module¶
- class calendar_smith.core.DateRange(start: date, end: date)[source]¶
Bases:
NamedTupleSimple date range with start and end dates.
- end: date¶
Alias for field number 1
- start: date¶
Alias for field number 0
- class calendar_smith.core.WeekSpan(number: int, start: date, end: date)[source]¶
Bases:
NamedTupleISO week span with week number, start date, and end date.
- end: date¶
Alias for field number 2
- number: int¶
Alias for field number 0
- start: date¶
Alias for field number 1
- calendar_smith.core.get_dates_windows(start_date: date, window_size: int, repeats: int, sampling_rate: int | None = None) list[DateRange][source]¶
Return date windows based on a sampling rate.
- Parameters:
start_date – The starting date of the first window.
window_size – The duration of each window in days.
repeats – Number of windows to generate.
sampling_rate – The number of days between the start of each window. Defaults to window_size, which produces consecutive non-overlapping windows.
- calendar_smith.core.get_fiscal_year(date_obj: date, system: str = 'us') int[source]¶
Return the fiscal year for a date.
- Supported systems:
us: fiscal year starts Oct 1jp: fiscal year starts Apr 1
- calendar_smith.core.get_iso_week_span(iso_year: int, iso_week: int) WeekSpan[source]¶
Return the Monday-to-Sunday span for an ISO week.
calendar_smith.time module¶
- calendar_smith.time.from_iso(value: str) datetime[source]¶
Parse an ISO 8601 string into an aware datetime.
- Raises:
ValueError – If the parsed datetime is naive.
- calendar_smith.time.now_in(timezone: ZoneInfo) datetime[source]¶
Return the current datetime in the given timezone.
- calendar_smith.time.to_iso(dt: datetime) str[source]¶
Return an ISO 8601 string for an aware datetime.
- Raises:
ValueError – If
dtis naive.
calendar_smith.utils module¶
- calendar_smith.utils.ensure_date(date_input: str | date | None) date[source]¶
Convert a string, date, or
Noneinto adatetime.date.
calendar_smith.cli module¶
- calendar_smith.cli.convert_timezone_args(args)[source]¶
Convert an ISO 8601 datetime to another timezone.
Module contents¶
Calendar-Smith: Lightweight fiscal and ISO calendar utilities.
- class calendar_smith.DateRange(start: date, end: date)[source]¶
Bases:
NamedTupleSimple date range with start and end dates.
- end: date¶
Alias for field number 1
- start: date¶
Alias for field number 0
- class calendar_smith.WeekSpan(number: int, start: date, end: date)[source]¶
Bases:
NamedTupleISO week span with week number, start date, and end date.
- end: date¶
Alias for field number 2
- number: int¶
Alias for field number 0
- start: date¶
Alias for field number 1
- calendar_smith.ensure_date(date_input: str | date | None) date[source]¶
Convert a string, date, or
Noneinto adatetime.date.
- calendar_smith.format_ordinal(n: int) str[source]¶
Return
nas an ordinal string, such as1stor22nd.
- calendar_smith.from_iso(value: str) datetime[source]¶
Parse an ISO 8601 string into an aware datetime.
- Raises:
ValueError – If the parsed datetime is naive.
- calendar_smith.get_dates_windows(start_date: date, window_size: int, repeats: int, sampling_rate: int | None = None) list[DateRange][source]¶
Return date windows based on a sampling rate.
- Parameters:
start_date – The starting date of the first window.
window_size – The duration of each window in days.
repeats – Number of windows to generate.
sampling_rate – The number of days between the start of each window. Defaults to window_size, which produces consecutive non-overlapping windows.
- calendar_smith.get_fiscal_year(date_obj: date, system: str = 'us') int[source]¶
Return the fiscal year for a date.
- Supported systems:
us: fiscal year starts Oct 1jp: fiscal year starts Apr 1
- calendar_smith.get_iso_week_span(iso_year: int, iso_week: int) WeekSpan[source]¶
Return the Monday-to-Sunday span for an ISO week.
- calendar_smith.get_iso_weeks_for_year(year: int) List[WeekSpan][source]¶
Return all ISO week spans for a given year.
- calendar_smith.get_nth_week_of_month(date_obj: date) int[source]¶
Return the 1-based week number within the month.
- calendar_smith.now_in(timezone: ZoneInfo) datetime[source]¶
Return the current datetime in the given timezone.
- calendar_smith.to_iso(dt: datetime) str[source]¶
Return an ISO 8601 string for an aware datetime.
- Raises:
ValueError – If
dtis naive.