Skip to main content

Module date

Module date 

Source
Expand description

Shared calendar date range parsing for CLI tools.

Two forms are supported on the command line side:

  • --since YYYY-MM-DD [--until YYYY-MM-DD] — explicit, inclusive range. until defaults to today when omitted.
  • --period <token> — a YYYY, YYYYQ1..Q4, or YYYYH1..H2 shortcut that expands to the matching calendar range.

Tools wire these up as two option groups and pass the raw values into resolve_date_range. See parse_period for the period token grammar.

use chrono::NaiveDate;
use sandogasa_cli::date::{parse_period, resolve_date_range};

let (start, end) = parse_period("2026Q1").unwrap();
assert_eq!(start, NaiveDate::from_ymd_opt(2026, 1, 1).unwrap());
assert_eq!(end,   NaiveDate::from_ymd_opt(2026, 3, 31).unwrap());

let (s, e) = resolve_date_range(None, None, Some("2026H2")).unwrap();
assert_eq!(s, NaiveDate::from_ymd_opt(2026, 7, 1).unwrap());
assert_eq!(e, NaiveDate::from_ymd_opt(2026, 12, 31).unwrap());

Functions§

parse_period
Parse a calendar-period shortcut into an inclusive (start, end) range.
resolve_date_range
Resolve a (--since, --until, --period) triple into an inclusive date range.