Basic functions for calendrical computations.
All parameters should be integer numbers. In order to increase efficiency, almost no check is done.
Any NaN parameter will yield NaN values.
Non-integer parameter will yield erroneous non-integer values.
Default parameters assume that computations are done using 1 for the first month of any calendar.
- Version:
- M2024-07-02
- License:
- MIT 2016-2024
- Source:
Classes
Type Definitions
calendarRule
Structure of the calendar rule parameter that describes a calendar's computation rules
and that is passed to the Cycle Bases Calendar Computation Engine (Cbcce), a class constructor.
The calendar structure is made up of nested cycles. Each cycle finishes with an intercalary or missing element.
Computations are made on an intermediary calendar which is derived from a real-life calendar.
E.g. for the Julian-Gregorian calendar, the derived calendar's year finishes in February, the intercalary day (29 February) is at the very end,
and the olympiade (4-years cycle), finishes with the leap year.
Non checked constraints:
1. The cycles and the canvas elements shall be defined from the largest to the smallest
e.g. four-centuries cycle, then century, then four-year cycle, then year, etc.
2. The same names shall be used for the "coeff" and the "canvas" properties, otherwise functions shall give erroneous results.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
timeepoch |
Number | origin date or timestamp in elementary units (days, milliseconds...) to be used for the decomposition, with respect to instant 0 of used timestamp. |
coeff |
Array | Array of coefficients used to decompose a timestamp into time cycles like eras, quadrisaeculae, centuries, ... down to the elementary unit. |
coeff[].cyclelength |
Number | length of the cycle, in elementary units. |
coeff[].ceiling |
Number | Infinity, or the maximum number of cycles of this size minus one in the upper cycle; the last cycle may hold an intercalation remainder up to the next level, example: this level is year of 365 days, upper level is 1461 days i.e. the last year holds more than 365 days. |
coeff[].subCycleShift |
Number | number (-1, 0 or +1) to add to the ceiling of the cycle of the next level when the ceiling is reached at this level; to be used for common/embolismic years in a Meton cycle, or for 128-years cycles of 4 or 5 years elementary cycles. |
coeff[].multiplier |
Number | multiplies the number of cycles of this level to convert into target units. |
coeff[].target |
String | the unit (e.g. "year") of the decomposition element at this level. |
coeff[].notify |
String | optional, the boolean field (e.g. "leapyear") where to indicate that the element's length is "singular" (i.e. not "common"). |
canvas |
Array | Canvas of the decomposition , e.g. "year", "month", "day", with suitable properties at each level. |
canvas[].name |
String | the name of the property at this level, which must match one target property of the coeff component, |
canvas[].init |
Number | value of this component at epoch, which is the lowest value (except for the first component), e.g. 0 or 1 for month, 1 for date, 0 for hours, minutes, seconds. |
- Source:
weekRule
Structure of the weekRule parameter passed to WeekClock that describes the structure of the week.
Non checked constraints:
1. characWeekNumber shall be at beginning of year, before any intercalary month or day.
2. weekLength shall be > 0.
Type:
- Object
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
originWeekday |
Number | weekday number of day 0; value is renormalised to 0..weekLength-1. | ||
daysInYear |
function | function (year), number of days in year; year is specified as "fullyear" (unambiguous); with solar calendars, result is 365 or 366. | ||
characDayIndex |
function | function (year): the day index of one day of week number characWeekNumber of year; if weekReset is true, this day shall be the first day of the week characWeekNumber ; if not, all weeks are of same length. | ||
startOfWeek |
Number |
<optional> |
1 | weekday number of the first day of the week for this calendar, e.g. 0 for Sunday, 1 for Monday etc. Default is 1; value is renormalised to 0..weekLength-1. |
characWeekNumber |
Number |
<optional> |
1 | number of the week of the characDayIndex; default is 1. |
dayBase |
Number |
<optional> |
1 | the lowest number a weekday may have, normally only 0 or 1 are possible; not necessarily startOfWeek; default is 1. |
weekBase |
Number |
<optional> |
1 | the lowest number for a week, normally only 0 or 1 are possible; not necessarily characWeekNumber; default is 1. |
weekLength |
Number |
<optional> |
7 | number of days, or minimum number of days in one week; default is 7. |
weekReset |
Number |
<optional> |
false | whether weekday is forced to a constant value at beginning of year; default is false. |
uncappedWeeks |
Array.<Number> |
<optional> |
null | an array of the week numbers that have one or more day above weekLength; possible cases: undefined (and set to null): all weeks have always the same duration, weekLength; .length = 1: last complete week of year is followed by several epagomenal days. These days are attached to the last week and hold numbers above weekLength; .length > 1: each indentified week is followed by one (unique) epagomenal day. Any such week has weekLength + 1 days; e.g. for French revolutionary calendar: [36], and the epagomenal days are indexed above Décadi, last day of the ordinary decade; e.g. for ONU projected calendar: [26, 52], the Mondial day in the middle of year and the Bissextile day at the very end. These days are only considered if weekReset is true, and in this case, uncappedWeeks should at least have one value. |
- Source: