Expand description
A proleptic-Gregorian calendar on i64 days-since-epoch (#1011).
chrono’s NaiveDate caps near year ±262,143 and Arrow Date32 is i32 days
(≈ year ±5.8M), but openCypher dates span years −999,999,999 …
+999,999,999. This module does all DATE math on i64 days since the Unix
epoch (1970-01-01), so the full range round-trips. It deliberately covers only
the calendar (year/month/day/ordinal/ISO-week/weekday + day-precision
arithmetic + ISO rendering); time-of-day stays nanoseconds-of-day and named
zones stay chrono_tz (both year-independent).
The core conversions are Howard Hinnant’s days_from_civil / civil_from_days
(http://howardhinnant.github.io/date_algorithms.html), exact for any year in
the proleptic Gregorian calendar (which has a year 0). Cross-checked against
chrono for in-range years in the unit tests.
Functions§
- add_
months - Add a signed number of calendar
monthsto(y, m, d), clamping the day to the target month’s length (e.g. Jan 31 + 1 month → Feb 28/29). Returns the resulting civil date. - add_
months_ to_ days - Add
monthscalendar months to a days count (day-clamped); convenience overadd_monthsfor the days representation. - civil_
from_ days - The civil date
(year, month, day)for a days-since-epoch count (the inverse ofdays_from_civil).monthis 1–12,dayis 1–31. - days_
from_ civil - Days since 1970-01-01 for the civil date
(year, month, day)in the proleptic Gregorian calendar.monthis 1–12,dayis 1–31 (not validated here — callymd_to_daysfor the checked form). Exact for anyi64year in range. - days_
in_ month - Number of days in
month(1–12) ofyear(28–31).monthout of range → 0. - days_
in_ year - Days in
year(365 or 366). - format_
date - Canonical openCypher ISO rendering of a date
(YYYY-MM-DD). Years 0000–9999 are zero-padded to four digits with no sign; outside that range the ISO-8601 expanded form applies — a leading+for years > 9999 and-for negative years (Neo4j: “a plus sign must prefix any year after 9999”). Matches chrono’s%Yfor the years chrono can render, and extends past chrono’s ±262k cap. - format_
year - Year formatting shared by date / localdatetime / datetime rendering.
- from_
iso_ ywd - Days for the ISO
(iso_year, week, weekday)(weekday 1 = Mon … 7 = Sun).Noneifweek/weekdayis out of range for that ISO year. - from_
ordinal - Days for the
ordinal-th day ofyear(1 = Jan 1).Noneif out of range. - is_leap
- Whether
yearis a leap year in the proleptic Gregorian calendar. - iso_
week - The ISO-8601 week-based year and week number
(iso_year, week)for a days count. The ISO week-year can differ from the calendar year near Jan 1 / Dec 31. - iso_
weekday - ISO weekday, 1 = Monday … 7 = Sunday.
- iso_
weeks_ in_ year - The number of ISO weeks in
iso_year(52 or 53). - num_
days_ from_ monday - Days from the Monday of the date’s week (0 = Monday … 6 = Sunday).
- ordinal
- The 1-based day-of-year (1–366) for a days count.
- quarter_
of_ month - The 1-based quarter (1–4) of
month(1–12). - ymd_
to_ days - Validated civil → days:
Nonefor an out-of-range month/day (e.g. 2025-02-30).