Module:Calendrical Calculations/doc
| This is a documentation subpage for Module:Calendrical Calculations. It may contain usage information, categories and other content that is not part of the original module page. |
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
This module is a Lua translation of the Lisp code in Appendix D of Calendrical Calculations: The Ultimate Edition by Nachum Dershowitz and Edward Reingold. It allows any date to be converted between any two of the Rata Die, Modified Julian Date, Julian day, Egyptian, Armenian, Akan, Gregorian, Julian, Roman, Coptic, Ethiopian, ISO week date, Icelandic, Islamic, Hebrew, Hindu, Mayan, Aztec, Balinese pawukon, Persian/Solar Hijri, Baha'i, French Republican, Babylonian, Samaritan, Chinese, Japanese, and Tibetan calendars
Usage
[edit]For most of the calendars above, two functions are implemented: one that converts a fixed (i.e. Rata Die) date into a date in the calendar, and another that converts a date into the calendar into a fixed date. For a calendar named X, these would be called x_from_fixed and fixed_from_x respectively. Therefore, to convert a date in calendar X to calendar Y, the date must be converted from x to Rata Die using fixed_from_x(x_date), then the result converted to y using y_from_fixed. For example, the date 12 November 1945 in the Gregorian calendar could be converted to the Julian calendar like this:
{{#invoke:Calendrical Calculations|fixed_from_gregorian|1945|11|12}}→ 710347{{#invoke:Calendrical Calculations|julian_from_fixed|710347}}→ 1945-10-30
There is a convert function that automatically combines the two steps like this:
{{#invoke:Calendrical Calculations|convert|gregorian|julian|1945|11|12}}→ 1945-10-30
Either method correctly returns 30 October 1945. The convert function makes calendar names case-insensitive, and replaces spaces and dashes with underscores, so that Hindu Lunar, hindu_lunar, hindu-lunar, etc will all work.
Isolating elements in arrays
[edit]Most x_from_fixed functions return arrays. To isolate one element in the array, an index= parameter could be passed. For example, to get just the day of the month in the conversion above, an index=3 parameter can be added like this:
{{#invoke:Calendrical Calculations|julian_from_fixed|710347|index=3}}→ 30
Likewise, index=2 would return only the month number, and index=1 would return only the year.
Accepted parameters
[edit]It should be noted that all inputted parameters must be numerical, and all outputs are also numerical. For boolean values, 0 is used as false and 1 as true. For months, the helper templates listed below convert the month numbers into names.
Not all of the fixed_from_x functions accept parameters in the form of year, month, day, and likewise not all the x_from_fixed functions return outputs in that format. Below is a list of, for each calendar, which parameters its fixed_from_ function accepts and its _from_fixed function returns:
| Calendar | Functions | Parameters/returned values |
|---|---|---|
| Rata Die | rd |
date |
| Modified Julian Date | fixed_from_mjd / mjd_from_fixed |
mjd |
| Julian day | fixed_from_jd / jd_from_fixed |
jd |
| Egyptian | fixed_from_egyptian / egyptian_from_fixed |
year, month, day |
| Armenian | fixed_from_armenian / armenian_from_fixed |
year, month, day |
| Gregorian | fixed_from_gregorian / gregorian_from_fixed |
year, month, day |
| Julian | fixed_from_julian / julian_from_fixed |
year, month, day |
| Roman | fixed_from_roman / roman_from_fixed |
year, month, event, count, leap |
| Coptic | fixed_from_coptic / coptic_from_fixed |
year, month, day |
| Ethiopian | fixed_from_ethiopic / ethiopic_from_fixed |
year, month, day |
| ISO week date | fixed_from_iso / iso_from_fixed |
year, week, day |
| Icelandic | fixed_from_icelandic / icelandic_from_fixed |
year, season, week, weekday |
| Islamic | fixed_from_islamic / islamic_from_fixed |
year, month, day |
| Observational Islamic | fixed_from_observational_islamic / observational_islamic_from_fixed |
year, month, day |
| Saudi Islamic | fixed_from_saudi_islamic / saudi_islamic_from_fixed |
year, month, day |
| Hebrew | fixed_from_hebrew / hebrew_from_fixed |
year, month, day |
| Observational Hebrew | fixed_from_observational_hebrew / observational_hebrew_from_fixed |
year, month, day |
| Old Hindu solar | fixed_from_old_hindu_solar / old_hindu_solar_from_fixed |
year, month, day |
| Old Hindu lunar | fixed_from_old_hindu_lunar / old_hindu_lunar_from_fixed |
year, month, leap month, day |
| Modern Hindu solar | fixed_from_hindu_solar / hindu_solar_from_fixed |
year, month, day |
| Modern Hindu lunar | fixed_from_hindu_lunar / hindu_lunar_from_fixed |
year, month, leap month, day, leap day |
| Full-moon Hindu lunar | fixed_from_hindu_fullmoon / hindu_fullmoon_from_fixed |
year, month, leap month, day, leap day |
| Astronomical Hindu solar | fixed_from_astro_hindu_solar / astro_hindu_solar_from_fixed |
year, month, day |
| Astronomical Hindu lunar | fixed_from_astro_hindu_lunar / astro_hindu_lunar_from_fixed |
year, month, leap month, day, leap day |
| Maya Long Count | fixed_from_mayan_long_count / mayan_long_count_from_fixed |
baktun, katun, tun, uinal, kin |
| Persian | fixed_from_persian / persian_from_fixed |
year, month, day |
| Arithmetic Persian | fixed_from_arithmetic_persian / arithmetic_persian_from_fixed |
year, month, day |
| Baháʼí | fixed_from_bahai / bahai_from_fixed |
major, cycle, year, month, day |
| Astronomical Baháʼí | fixed_from_astro_bahai / astro_bahai_from_fixed |
major, cycle, year, month, day |
| French Republican | fixed_from_french / french_from_fixed |
year, month, day |
| Arithmetic French Republican | fixed_from_arithmetic_french / arithmetic_french_from_fixed |
year, month, day |
| Babylonian | fixed_from_babylonian / babylonian_from_fixed |
year, month, leap month, day |
| Samaritan | fixed_from_samaritan / samaritan_from_fixed |
year, month, day |
| Chinese | fixed_from_chinese / chinese_from_fixed |
cycle, year, month, leap month, day |
| Japanese | fixed_from_japanese / japanese_from_fixed |
cycle, year, month, leap month, day |
| Korean | fixed_from_korean / korean_from_fixed |
cycle, year, month, leap month, day |
| Tibetan | fixed_from_tibetan / tibetan_from_fixed |
year, month, leap month, day, leap day |
Helper templates
[edit]Because most conversions will be from the Gregorian calendar to another calendar, there are several helper templates which simplify the usage of this module by taking a Gregorian year, month and day, and converting it to the given calendar, and handling the formatting. If not given a date, they default to using the current date in UTC+00. Below is a list of these helper templates and their documentation guides:
- Akan calendar:
{{AKANCALENDAR}} - Armenian calendar:
{{ARMENIANDATE}} - Aztec calendar:
{{AZTECCALENDAR}} - Babylonian calendar:
{{BABYLONIANDATE}} - Balinese pawukon calendar:
{{BALINESEPAWUKONCALENDAR}} - Bengali calendar:
{{BENGALIDATE}} - Chinese calendar:
{{CHINESECALENDAR}} - Coptic calendar:
{{COPTICDATE}} - Egyptian calendar:
{{EGYPTIANDATE}} - Ethiopian calendar:
{{ETHIOPIANDATE}} - French Republican calendar:
{{FRENCHREVOLUTIONARYDATE}} - Hindu calendar:
{{HINDUCALENDAR}} - Icelandic calendar:
{{ICELANDICDATE}} - Japanese calendar:
{{JAPANESECALENDAR}} - Julian calendar:
{{JULIANCALENDAR}} - Julian day:
{{JD}} - Korean calendar:
{{KOREANCALENDAR}} - Maya calendar:
{{MAYANCALENDAR}} - Rata Die:
{{RD fixed}} - Roman calendar:
{{ROMANDATE}} - Tibetan calendar:
{{TIBETANDATE}}
The ISO week date, Hebrew, Islamic, Solar Hijri calendars do not have helper functions because MediaWiki's #time function already provides conversions for them, in its o, xj, xm and xi portions respectively. A usage guide for this function can be found here.
Template:Infobox calendar date
[edit]This module is used by {{Infobox calendar date}} to convert the current date, or any given date, into many different calendars. Its documentation guide can be read here.
AI Declaration
[edit]LLM aid was used to translate the Lisp code in the book to Lua.
Source
[edit]- Dershowitz, Nachum; Reingold, Edward M. (2018). Calendrical Calculations (Fourth ed.). Cambridge: Cambridge University Press. ISBN 9781107057623. OCLC 1030959487.