macro librarylibs/Dates/src/Dates.xtlm
Dates: its macro library -- d_ate<, date literals checked at compile time. Imported with the functions, under one alias: "d:" u_se< "Dates". A macro is a function from the source text written left and right of its call to the source that replaces the call, run before the program is compiled (X_eTaL MC10). Names with m: are macros; those under h: are private to this file.
Parsing
ʰs̲paced : Char -> Char
The text with each "-" as a space, so n_umbers reads the three parts.
ʰs̲paced ← { t → n ← t̲ally t dash ← t = f̲irst "-" ((r̲ange n) + dash × (n + 1) − r̲ange n) s̲elect t c̲at " " }
ʰf̲ormed? : Truthy a => Char -> a
Whether a text has the form yyyy-mm-dd (digits and two dashes).
ʰf̲ormed? ← { t → (2 = t̲ally w̲here t = f̲irst "-") ∧ '∧ r̲/ t m̲ember? digits c̲at "-" }
ʰv̲alid? : Truthy a => Int -> a
Whether y m d is a date of the calendar (Dates' own month lengths).
ʰv̲alid? ← { ymd → m ← f̲irst 1 d̲rop ymd d ← f̲irst 2 d̲rop ymd (m < 1) ∨ m > 12 ? 0 = 1 (d ≥ 1) ∧ d ≤ (f̲irst ymd) ᵈᵈd̲aysIn m }
The macro
ᵐd̲ate< : Unit -> Char -> Char
@ d:d_ate< "2026-10-03": the date's day number, worked out when the program is compiled (20729), written in place of the call. A text that is not a date of the calendar (2026-02-30, 2026-13-01) stops the compiler at it: error[bad-date]. Nothing goes on the left (@).
ᵐd̲ate< ← { none t → ({ @ → 0 })_ none ⍝ the left side takes only @ (MC22) n̲ot ʰf̲ormed? t ? "bad-date right" ⎕R̲EJECT t c̲at " is not a date: write it yyyy-mm-dd" ymd ← f̲loor n̲umbers ʰs̲paced t n̲ot ʰv̲alid? ymd ? "bad-date right" ⎕R̲EJECT t c̲at " is not a date of the calendar" f̲ormat ᵈᵈd̲ays ymd }