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.untildefaults to today when omitted.--period <token>— aYYYY,YYYYQ1..Q4, orYYYYH1..H2shortcut 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.