Skip to main content

Module date

Module date 

Source
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.c approxidate 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_ymd or check days_in_month first.
days_in_month
Days in month (1-12) of year; 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-DD calendar date, rejecting trailing components, months outside 1-12, and days beyond the month’s length.
parse_time_hms
Parse a strict HH:MM:SS clock time, rejecting trailing components and out-of-range fields (second == 60 is 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 <+|->HHMM form 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.c match_tz). Returns None otherwise.
split_embedded_timezone
Split an ISO 8601 time portion (the part after T) into the bare time and an optional embedded timezone suffix. A trailing Z normalises to the static "+0000"; a trailing ±HHMM is borrowed from the input. Otherwise the whole string is the time and any timezone arrives separately.