Excel Date Compatibility
The excel-date library mirrors Excel’s most relied-upon date and workday functions so spreadsheet logic can be ported into L4 without rewriting every calculation. It builds on the existing daydate primitives and adds Excel-specific behavior such as serial number conversion (with the 1900 leap-year bug), 30/360 day-count conventions, and working-day helpers.
Import it alongside daydate:
IMPORT daydate
IMPORT `excel-date`Serial Number Helpers
excelSerial1900 date
Convert a DATE into the Excel 1900 serial system (inserting the phantom 1900‑02‑29 day for compatibility).
dateFromExcelSerial serial
Convert a serial number back to a DATE. Returns LEFT if the value has a fractional component or equals 60 (Excel’s non-existent 1900‑02‑29).
excelSerial1904 / dateFromExcelSerial1904
Serial/date conversions for the 1904 system.
All conversion helpers validate integers via EITHER STRING …; call sites should CONSIDER the result.
Clock & Parsing Helpers
excelToday— Wraps the runtimeTODAYbuiltin and returns aDATE.excelNow— CombinesNOWwithexcelSerial1900to yield an Excel serial number (including the 1900 leap-year shim).ExcelDateValue text— CallsDATEVALUE, converting successful results intoDATE.ExcelTimeValue text— Thin wrapper overTIMEVALUEthat keeps Excel’sEITHER STRING NUMBERAPI.
Difference & Fraction Functions
DATEDIF start end unit— Supports unitsY,M,D,MD,YM,YD, matching Excel’s rounding rules and returningLEFTifstart > endor the unit is unknown.ExcelDays end start— Simple day difference for eitherDATEor serial arguments.ExcelDays360 start end [isEuropean]— 30/360 day count (US default, setTRUEfor European).ExcelYearFrac start end [basis]— Bases 0–4 (US 30/360, Actual/Actual, Actual/360, Actual/365, European 30/360). Negative spans are handled by swapping and negating.
Month Arithmetic
ExcelEDate start months— Adds months, clamping the day to the target month length.ExcelEOMonth start months— Returns the last day of the month offset bymonths.
Both require integer months and return EITHER STRING DATE to report invalid input.
Workday & Network-Day Helpers
ExcelWorkday start offset [holidays]— Moves forward/backward by working days (Mon–Fri), optionally skipping a list of holidayDATEs.ExcelNetworkDays start end [holidays]— Counts working days inclusively. Returns negative counts whenstart > end, just like Excel.
Weekend masks (WORKDAY.INTL, NETWORKDAYS.INTL) are not yet implemented; add a custom predicate if you need region-specific weekends.
Limitations
Serial value 60 cannot be represented because
DATEis strictly Gregorian.dateFromExcelSerialreturnsLEFTwith an explanatory message; downstream code can remap it if necessary.TODAY/NOWread from the evaluation clock supplied via CLI/LSP flags or theJL4_FIXED_NOWenvironment variable. They are impure and may eventually raise a compiler warning; treat the evaluation datetime as part of your inputs.YEARFRACbasis 1 follows the common Actual/Actual (ISDA-style) split-by-year approach and may differ from Excel in edge cases where the spreadsheet uses different day-count standards.
Testing Notes
The library ships with golden tests under jl4-core/libraries/tests/excel-date.* and executable examples in jl4/examples/ok/excel-date-tests.l4. When adding functions, update the .l4 source first, run cabal test jl4:test:jl4-test to regenerate the *.actual outputs, inspect, then promote them to the .golden files so CI remains stable.
Last updated
