Skip to main content

calendar-smith

PyPI Version

Calendar-Smith is a zero-dependency, high-performance Python utility for fiscal year calculations, ISO week mapping, and safe date parsing.

It was built for data engineers and analysts who need to process CSVs or perform calendar math without the overhead of heavy libraries like Pandas or Arrow.

Key Features

  • Safety-First Parsing: Strictly rejects ambiguous 6-digit (460614) and 7-digit (2026123) strings to prevent century errors and data corruption.

  • Fiscal Logic: Built-in support for US (fiscal year ends Sep 30) and Japanese (fiscal year ends Mar 31) fiscal systems.

  • Fast-Path Execution: Utilizes datetime.fromisoformat for high-performance processing of standard data.

  • Timezone Utilities: Lightweight helpers for UTC, JST, ET, and other common timezones with ISO 8601 support.

  • Ordinal Formatting: Human-friendly outputs (e.g., “1st week”, “3rd week”).

  • Zero External Dependencies: Uses only the Python Standard Library (3.10+).

Installation

pip install calendar-smith

To contribute or run tests:

git clone https://github.com/yeiichi/calendar-smith.git
cd calendar-smith
pip install -e ".[dev]"
pytest

CLI Commands

1. calendar-smith

Top-level command with subcommands:

calendar-smith solve 2026
calendar-smith week-span 2020 53
calendar-smith nth
calendar-smith windows 2026-03-17 7 4
calendar-smith tz 2026-03-20T10:00:00+09:00 America/New_York
calendar-smith fiscal-year 2026-04-22 --system jp
calendar-smith csv records.csv records_with_fy.csv --system jp --date-column created_at

2. calendar-smith-csv

Appends a fiscal_year column to an existing CSV file. Supports:

  • us: fiscal year ends Sep 30

  • jp: fiscal year ends Mar 31

calendar-smith-csv records.csv records_with_fy.csv --system jp --date-column created_at

3. calendar-smith-solve

Lists the Monday-to-Sunday date ranges for every ISO week in a given year.

calendar-smith-solve 2026

4. calendar-smith-nth

Interactive tool to find the ordinal week of the month and the ISO week of the year for any date.

$ calendar-smith-nth
Date? [yyyy-mm-dd] (leave blank for today) >> 2026-02-17

Result:
  Date:       2026-02-17 (Tuesday)
  Month Week: The 3rd week
  Year Week:  The 8th week

5. calendar-smith-week-span

Show the Monday-to-Sunday span for a specific ISO week.

calendar-smith-week-span 2020 53

6. calendar-smith-windows

Generate date windows (consecutive, overlapping, or gapped) from a starting date using a fixed window size and repeat count. Use --sampling-rate (or -s) for overlapping or gapped windows.

# Generate 4 consecutive 7-day windows
calendar-smith-windows 2026-03-17 7 4

# Generate 4 overlapping 7-day windows starting every 1 day
calendar-smith-windows 2026-03-17 7 4 --sampling-rate 1

Example output:

Generated 4 windows starting from 2026-03-17 with size 7:
  Window  1: 2026-03-17 to 2026-03-23
  Window  2: 2026-03-24 to 2026-03-30
  Window  3: 2026-03-31 to 2026-04-06
  Window  4: 2026-04-07 to 2026-04-13

7. calendar-smith-tz

Convert an ISO 8601 datetime string from one timezone to another.

calendar-smith-tz 2026-03-20T10:00:00+09:00 America/New_York
# Output: 2026-03-19T21:00:00-04:00

8. calendar-smith-fiscal-year

Return the fiscal year for a given date.

calendar-smith-fiscal-year 2026-04-22 --system jp
# Output: 2026

Date Parsing Rules

To ensure data integrity, calendar-smith follows these parsing rules:

  • Accepted: 2026-02-17, 2026/02/17, 2026.02.17, 2026-2-17, 20260217.

  • Rejected:
    • 260217 (6-digit): Rejected to avoid century ambiguity (1926 vs 2026).

    • 2026123 (7-digit): Rejected because it could be Jan 23rd or Dec 3rd.

API Example

from calendar_smith import (
    get_fiscal_year,
    ensure_date,
    get_nth_week_of_month,
    get_dates_windows,
    get_iso_week_span,
    get_iso_weeks_for_year,
    format_ordinal,
    WeekSpan,
    DateRange,
)

# Parse a messy but valid string
d = ensure_date("2026/4/1")

# Get Japanese Fiscal Year (2026)
fy_jp = get_fiscal_year(d, system="jp")

# Get US Fiscal Year (2026 - fiscal year ends Sep 30, 2026)
fy_us = get_fiscal_year(d, system="us")

# Get week of month
week_num = get_nth_week_of_month(d)

# Get a specific ISO week span
span = get_iso_week_span(2026, 1)

# Get all ISO week spans for a year
all_weeks = get_iso_weeks_for_year(2026)

# Generate the next 4 date windows (default: consecutive)
future_windows = get_dates_windows(d, window_size=7, repeats=4)

# Generate overlapping windows (starting every 1 day)
overlapping = get_dates_windows(d, window_size=7, repeats=4, sampling_rate=1)

from calendar_smith import (
    now_utc,
    now_jst,
    to_timezone,
    to_iso,
    from_iso,
    JST,
    ET,
)

# Get current time in JST
dt_jst = now_jst()

# Convert to New York time (ET)
dt_et = to_timezone(dt_jst, ET)

# Get ISO 8601 string
iso_str = to_iso(dt_et)

# Parse ISO 8601 string
dt_parsed = from_iso("2026-03-20T10:00:00+09:00")

License

MIT License. See LICENSE for details.

Metadata

Release files for calendar-smith 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calendar-smith 1.1.0
File Size Uploaded Provenance
calendar_smith-1.1.0.tar.gz 7.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for calendar-smith 1.1.0
File Interpreter ABI Platform
calendar_smith-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / calendar_smith-1.1.0.tar.gz

Download URL calendar_smith-1.1.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9f19aeb722d97431b78b84b5f6aa4c5e024cb83ec5f9aa7b540f67b84f6fb058
BLAKE2b-256 checksum
How to use checksums
343c418b90b895ead83e32615529f5171e3ccc513ec6f8c8b6a79126588166fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / calendar_smith-1.1.0-py3-none-any.whl

Download URL calendar_smith-1.1.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e38a1c92767a25867fe089761dd3be41b333bcabfdfa5c298e421c6af73e6b30
BLAKE2b-256 checksum
How to use checksums
ad98851fa6f09093bf260c4a43d9181698084c0be4124f82d2f16c30dee916b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for calendar-smith 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page