Holidays related to Easter: Difference between revisions
Content added Content deleted
(Added Quackery.) |
|||
Line 2,683: | Line 2,683: | ||
for (let year = 400; year <= 2100; year += year < 2000 ? 100 : year >= 2021 ? 80 : year < 2010 ? 10 : 1) |
for (let year = 400; year <= 2100; year += year < 2000 ? 100 : year >= 2021 ? 80 : year < 2010 ? 10 : 1) |
||
document.write(getHolidaysDates(year, 1) + " <br />");</syntaxhighlight> |
document.write(getHolidaysDates(year, 1) + " <br />");</syntaxhighlight> |
||
# https://rosettacode.org/wiki/Holidays_related_to_Easter |
|||
=={{header|jq}}== |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
'''Also works with fq, a Go implementation of a large subset of jq''' |
|||
'''Adapted from [[#Wren|Wren]]''' |
|||
This entry uses jq's `mktime` and `gmtime` functions. Unfortunately, |
|||
the implementation of `mktime` in the C implementation of jq does not |
|||
currently (jq 1.6) support years before 1900. |
|||
<syntaxhighlight lang=jq> |
|||
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .; |
|||
# add the number of days to [year, month, day] |
|||
def addDays($days): |
|||
. as [$y,$m,$d] |
|||
| [$y,$m,$d + $days,0,0,0,0,0] | mktime | gmtime ; |
|||
# Output: [year, month_indexed_by_0, day] |
|||
def calculateEaster: |
|||
. as $year |
|||
| {} |
|||
| .a = $year % 19 |
|||
| .b = (($year / 100)|floor) |
|||
| .c = $year % 100 |
|||
| .d = ((.b / 4)|floor) |
|||
| .e = .b % 4 |
|||
| .f = (((.b + 8) / 25)|floor) |
|||
| .g = (((.b - .f + 1) / 3)|floor) |
|||
| .h = (19 * .a + .b - .d - .g + 15) % 30 |
|||
| .i = ((.c / 4)|floor) |
|||
| .k = .c % 4 |
|||
| .l = (32 + 2 * .e + 2 * .i - .h - .k) % 7 |
|||
| .m = (((.a + 11 * .h + 22 * .l) / 451)|floor) |
|||
| .n = .h + .l - 7 * .m + 114 |
|||
| .month = ((.n / 31)|floor) # months indexed from 1 |
|||
| .day = (.n % 31) + 1 |
|||
| [$year, .month - 1, .day] ; |
|||
def holidayOffsets: [ |
|||
["Easter", 0], |
|||
["Ascension", 39], |
|||
["Pentecost", 49], |
|||
["Trinity", 56], |
|||
["C/Christi", 60] |
|||
]; |
|||
# Input: year |
|||
def outputHolidays: |
|||
calculateEaster as $date |
|||
| holidayOffsets[] as [$h, $o] |
|||
| $date | addDays($o) | strftime("%d %b") ; |
|||
def tables: |
|||
def row: "\(lpad(4)) \([outputHolidays] | join(" "))"; |
|||
"Year Easter Ascension Pentecost Trinity C/Christi", |
|||
" CE Sunday Thursday Sunday Sunday Thursday ", |
|||
"---- ------ --------- --------- ------- ---------", |
|||
( range(400; 2101; 100) | row), |
|||
"", |
|||
( range(2010; 2021) | row) ; |
|||
tables |
|||
</syntaxhighlight> |
|||
'''Invocation''': gojq -nr -f holidays-related-to-easter.jq |
|||
{{output}} |
|||
Except for whitespace, the output is identical to that shown in the [[#Wren|Wren]] entry. |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |