2021-02-05

gregorian calendar calculations

part of sph-lib

uses a year 0 like iso8601. a year 0 appears to keep leap-day calculations simpler

(sph time gregorian)

procedure: greg-days->leap-days a ->

integer -> integer

gives the number of leap days in a given time span of full days.

works with positive and negative day values and considers partial years where the leap day always falls on february 29.

the calculation for negative values is similar to greg-years->leap-days, based on the fact that the formula for

positive values can be used as long as year 0 is ignored.

for day totals shorter than a year we check if the leap day in year 0 has passed.

for longer day totals the contained cycles are counted, like for positive values.

works with positive and negative day values and considers partial years where the leap day always falls on february 29.

the calculation for negative values is similar to greg-years->leap-days, based on the fact that the formula for

positive values can be used as long as year 0 is ignored.

for day totals shorter than a year we check if the leap day in year 0 has passed.

for longer day totals the contained cycles are counted, like for positive values.

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

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 ->

procedure: greg-years->year a ->

does not work reliably when year is negative and part of a date with advanced months or days,

because advancing days in a negative year reduce the number of elapsed years but not the year number

because advancing days in a negative year reduce the number of elapsed years but not the year number

variable: sph-time-gregorian-description