3 ms·
Ok now do date math, does the day-of-month accurately jump over the non-existent numbers?
by kfse 2mo ago
Ok now do date math, does the day-of-month accurately jump over the non-existent numbers?
- kipcole9 2mo agoThis "civic vs proleptic" split is a good use case for composite calendars: glue a few calendars together at their historical cut-over dates and the result behaves like one ordinary calendar. I maintain an Elixir library (Calendrical) that does this. England, for example, is just three segments spliced onto a Julian base: defmodule England do use Calendrical.Composite, calendars: [ ~D[1155-03-25 Calendrical.Julian.March25], # year starts on Lady Day ~D[1751-03-25 Calendrical.Julian.Jan1], # New Year moved to Jan 1 ~D[1752-09-14 Calendrical.Gregorian] # the 11-day jump ], base_calendar: Calendrical.Julian end The "missing" days simply aren't valid dates, and stepping across the boundary jumps: England.days_in_month(1752, 9) #=> 19 England.valid_date?(1752, 9, 3) #=> false Date.shift(~D[1752-09-02 England], day: 1) #=> ~D[1752-09-14 England]