Skip to main content

Lightweight fiscal and ISO calendar utilities.

Project description

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.

  • 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-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

2. calendar-smith-solve

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

calendar-smith-solve 2026

3. 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

4. calendar-smith-week-span

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

calendar-smith-week-span 2020 53

5. calendar-smith-windows

Generate consecutive date windows from a starting date using a fixed window size and repeat count.

calendar-smith-windows 2026-03-17 7 4

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

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,
    to_date,
    get_nth_week_of_month,
    get_dates_windows,
    get_iso_week_span,
    get_iso_weeks_for_year,
    format_ordinal,
    WeekSpan,
)

# Parse a messy but valid string
d = to_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
future_windows = get_dates_windows(d, window_size=7, repeats=4)

License

MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

calendar_smith-0.2.3.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

calendar_smith-0.2.3-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file calendar_smith-0.2.3.tar.gz.

File metadata

  • Download URL: calendar_smith-0.2.3.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for calendar_smith-0.2.3.tar.gz
Algorithm Hash digest
SHA256 536bf1c43dbba8ea92a0f63a13c51eee8b9983766c3c1e8f816211891914e683
MD5 f249886b38fd91b7115d3005f0d42c33
BLAKE2b-256 ac707dbb6b67277f4498bc37b1a5d395a215cfe92c1db02489348f1a61debb83

See more details on using hashes here.

File details

Details for the file calendar_smith-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: calendar_smith-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for calendar_smith-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5afa6ac1f3bd4cfb39bc995631e0757fb63a3c334876d33b30b825c9c7dabaf4
MD5 c68da0cf8418b0889658d32ff8fe1334
BLAKE2b-256 663ed3648b4ec817bbd2249ceba3d01cd1849d1cec40948f1a6f90cbb56dd3c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page