Expand description
Canonical civil-calendar arithmetic and date-token parsing (git date.c
subset): the one home for the helpers previously duplicated across
cli/log_cli.rs, rev/setup.rs, rev/lib.rs, and commands/am.rs.
All functions take borrowed inputs; allocation is limited to returned
values. The civil math is Howard Hinnant’s proleptic-Gregorian pair
(days_from_civil/civil_from_days), which matches git’s date
arithmetic over the full range.
Modules§
- approxidate
- A faithful port of the subset of git’s
date.capproxidate machinery.
Functions§
- civil_
from_ days - Inverse of
days_from_civil: civil(year, month, day)for a day count. - days_
from_ civil - Days between 1970-01-01 and the given civil date (Howard Hinnant’s
algorithm). Month/day are not range-checked: callers that need validated
input use
parse_date_ymdor checkdays_in_monthfirst. - days_
in_ month - Days in
month(1-12) ofyear; 0 when the month index is out of range. - is_
leap_ year - True for Gregorian leap years (divisible by 4, except centuries not divisible by 400).
- parse_
date_ ymd - Parse a strict
YYYY-MM-DDcalendar date, rejecting trailing components, months outside 1-12, and days beyond the month’s length. - parse_
time_ hms - Parse a strict
HH:MM:SSclock time, rejecting trailing components and out-of-range fields (second == 60is rejected here; leap-second-tolerant callers keep their own looser parser). - parse_
tz_ offset - Parse a timezone token into seconds east of UTC. Only git’s canonical
<+|->HHMMform is accepted: exactly five bytes, sign first, then four ASCII digits, with hours at most 23 and minutes at most 59 (the bounds of git’s date.cmatch_tz). ReturnsNoneotherwise. - split_
embedded_ timezone - Split an ISO 8601 time portion (the part after
T) into the bare time and an optional embedded timezone suffix. A trailingZnormalises to the static"+0000"; a trailing±HHMMis borrowed from the input. Otherwise the whole string is the time and any timezone arrives separately.