2025-08-29

(sph time gregorian)

gregorian calendar calculations

part of sph-lib

library description

uses a year 0 like iso8601. year 0 is a leap year; this simplifies leap-day formulas by making them symmetric for negative and positive years

module name

(sph time gregorian)

exported bindings

procedure: greg-days->leap-days a ->
integer -> integer
number of leap days contained in a span of full days.
works with positive and negative spans.
for days < 1 year, checks whether 0-2-29 is included.
for larger spans, uses cycle decomposition symmetrical to the positive case, with century exceptions except multiples of 400
procedure: greg-days->year a ->
procedure: greg-days->year-days a leap-year? ->
gives the number of days elapsed in a year. handles negative years/days
procedure: greg-days->years a ->
integer -> integer
the number of years the given number of days fill
procedure: greg-month->days a leap-year? ->
integer boolean -> integer
gives the number of days needed to reach the first day of the given month.
months are from 1-12
variable: greg-month-days
syntax: greg-month-days-get leap-year?
variable: greg-month-days-leap-year
variable: greg-number-of-months
procedure: greg-week-day year month day ->
integer integer integer -> integer
0 being monday
variable: greg-year-1970-days
procedure: greg-year->years a ->
variable: greg-year-days
procedure: greg-year-days->month-and-day& a greg-month-days c ->
integer #(days-of-month ...) procedure:{month day -> any} -> any
get the month and month day after the given number of days have passed starting from the beginning of the year
variable: greg-year-days-leap-year
procedure: greg-year-first-week-day a ->
procedure: greg-year-leap-year? a ->
integer:year-number -> boolean
check if the given year is a leap year
procedure: greg-year-weeks-53? a ->
integer:year-number -> boolean
check if the given year number corresponds to a year with 53 instead of 52 weeks according to the iso8601 standard
procedure: greg-years->days a ->
integer -> integer
gives the days contained in given number of fully elapsed years
procedure: greg-years->leap-days a ->
integer -> integer
number of leap days contained in the given count of elapsed years from year 0.
result is nonnegative. for negative elapsed years, the caller subtracts this value.
leap year rule: years divisible by 4 are leap years, including year 0, except centuries not divisible by 400
procedure: greg-years->year a ->
integer:elapsed-years -> integer:calendar-year
maps an elapsed-year count to the corresponding calendar year label.
note: when combined with month/day offsets in negative years, the elapsed-year count may not advance monotonically with the year label
variable: sph-time-gregorian-description