Holidays related to Easter: Difference between revisions

m
(added Arturo)
m (→‎{{header|Wren}}: Minor tidy)
 
(11 intermediate revisions by 5 users not shown)
Line 1,233:
2019 Easter: Sun 21 Apr, Ascension: Thu 30 May, Pentecost: Sun 9 Jun, Trinity: Sun 16 Jun, Corpus: Thu 20 Jun
2020 Easter: Sun 12 Apr, Ascension: Thu 21 May, Pentecost: Sun 31 May, Trinity: Sun 7 Jun, Corpus: Thu 11 Jun
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <chrono>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <vector>
 
std::chrono::year_month_day date_of_easter(const int32_t& year) {
const int32_t a = year % 19;
const int32_t b = year / 100;
const int32_t c = year % 100;
const int32_t d = b / 4;
const int32_t e = b % 4;
const int32_t f = ( b + 8 ) / 25;
const int32_t g = ( b - f + 1 ) / 3;
const int32_t h = ( 19 * a + b - d - g + 15 ) % 30;
const int32_t i = c / 4;
const int32_t k = c % 4;
const int32_t l = ( 32 + 2 * e + 2 * i - h - k ) % 7;
const int32_t m = ( a + 11 * h + 22 * l ) / 451;
const int32_t n = h + l - 7 * m + 114;
const unsigned int month = n / 31;
const unsigned int day = ( n % 31 ) + 1;
 
return { std::chrono::year{year}, std::chrono::month{month}, std::chrono::day{day} };
}
 
void display(const int32_t& year, const std::vector<int32_t>& holiday_offsets) {
std::chrono::year_month_day easter = date_of_easter(year);
 
std::cout << std::setw(4) << year;
for ( const int32_t& holiday_offset : holiday_offsets ) {
std::chrono::year_month_day date = std::chrono::sys_days(easter) + std::chrono::days{holiday_offset};
std::cout << std::setw(7) << date.day() << std::setw(4) << date.month();
}
std::cout << std::endl;
}
 
int main() {
const std::vector<int32_t> holiday_offsets{ 0, 39, 49, 56, 60 };
 
std::cout << "Year Easter Ascension Pentecost Trinity Corpus Christi" << std::endl;
std::cout << " CE Sunday Thursday Sunday Sunday Thursday " << std::endl;
std::cout << "---- ------ --------- --------- ------- --------------" << std::endl;
for ( int32_t year = 400; year <= 2100; year += 100 ) {
display(year, holiday_offsets);
}
std::cout << std::endl;
 
for ( int32_t year= 2010; year <= 2020; ++year ) {
display(year, holiday_offsets);
}
}
</syntaxhighlight>
{{ out }}
<pre>
Year Easter Ascension Pentecost Trinity Corpus Christi
CE Sunday Thursday Sunday Sunday Thursday
---- ------ --------- --------- ------- --------------
400 02 Apr 11 May 21 May 28 May 01 Jun
500 04 Apr 13 May 23 May 30 May 03 Jun
600 13 Apr 22 May 01 Jun 08 Jun 12 Jun
700 15 Apr 24 May 03 Jun 10 Jun 14 Jun
800 23 Apr 01 Jun 11 Jun 18 Jun 22 Jun
900 28 Mar 06 May 16 May 23 May 27 May
1000 30 Mar 08 May 18 May 25 May 29 May
1100 08 Apr 17 May 27 May 03 Jun 07 Jun
1200 09 Apr 18 May 28 May 04 Jun 08 Jun
1300 18 Apr 27 May 06 Jun 13 Jun 17 Jun
1400 20 Apr 29 May 08 Jun 15 Jun 19 Jun
1500 01 Apr 10 May 20 May 27 May 31 May
1600 02 Apr 11 May 21 May 28 May 01 Jun
1700 11 Apr 20 May 30 May 06 Jun 10 Jun
1800 13 Apr 22 May 01 Jun 08 Jun 12 Jun
1900 15 Apr 24 May 03 Jun 10 Jun 14 Jun
2000 23 Apr 01 Jun 11 Jun 18 Jun 22 Jun
2100 28 Mar 06 May 16 May 23 May 27 May
 
2010 04 Apr 13 May 23 May 30 May 03 Jun
2011 24 Apr 02 Jun 12 Jun 19 Jun 23 Jun
2012 08 Apr 17 May 27 May 03 Jun 07 Jun
2013 31 Mar 09 May 19 May 26 May 30 May
2014 20 Apr 29 May 08 Jun 15 Jun 19 Jun
2015 05 Apr 14 May 24 May 31 May 04 Jun
2016 27 Mar 05 May 15 May 22 May 26 May
2017 16 Apr 25 May 04 Jun 11 Jun 15 Jun
2018 01 Apr 10 May 20 May 27 May 31 May
2019 21 Apr 30 May 09 Jun 16 Jun 20 Jun
2020 12 Apr 21 May 31 May 07 Jun 11 Jun
</pre>
 
Line 1,953 ⟶ 2,045:
day=mod(n,31)+1
end</syntaxhighlight>
 
=={{header|FreeBASIC}}==
{{libheader|datetime}}
{{libheader|string}}
<syntaxhighlight lang="vb">#include "datetime.bi"
#include "string.bi"
 
Dim Shared As Integer anno, mes, dia
 
Type mytype
f As String*9
d As Short
End Type
Dim Shared fechas(1 To 5) As mytype => {("Easter ",0),_
("Ascension",39),("Pentecost",49),("Trinity ",56),("Corpus ",60)}
 
Function Pascua(anno As Short) As Double
Dim As Short a, b, c, d, e
Dim As Short f, g, h, i, k
Dim As Short l, m, n
a = anno Mod 19
b = anno \ 100
c = anno Mod 100
d = b \ 4
e = b Mod 4
f = (b + 8) \ 25
g = (b - f + 1) \ 3
h = (19 * a + b - d - g + 15) Mod 30
i = c \ 4
k = c Mod 4
l = (32 + 2 * e + 2 * i - h - k) Mod 7
m = (a + 11 * h + 22 * l) \ 451
n = h + l - 7 * m + 114
Dim As Short mes = n \ 31
Dim As Short dia = n Mod 31 + 1
Return Dateserial(anno, mes, dia)
End Function
 
Sub Mostar(anno As Short)
Dim As Double e = Pascua(anno)
Print Using (" #### "); anno;
For i As Short = 1 To Ubound(fechas)
Print Format(e + fechas(i).d, "dd/mmm"); Spc(3);
Next i
Print
End Sub
 
Print " Year Easter Ascension Pentecost Trinity C/Christi"
Print " CE Sunday Thursday Sunday Sunday Thursday "
Print " ---- ------ --------- ---------- ------- ---------"
 
For anno = 400 To 2100 Step 100
Mostar(anno)
Next anno
Print
For anno = 2010 To 2020
Mostar(anno)
Next anno
 
Sleep</syntaxhighlight>
{{out}}
<pre> Year Easter Ascension Pentecost Trinity C/Christi
CE Sunday Thursday Sunday Sunday Thursday
---- ------ --------- ---------- ------- ---------
400 02/abr. 11/may. 21/may. 28/may. 01/jun.
500 04/abr. 13/may. 23/may. 30/may. 03/jun.
600 13/abr. 22/may. 01/jun. 08/jun. 12/jun.
700 15/abr. 24/may. 03/jun. 10/jun. 14/jun.
800 23/abr. 01/jun. 11/jun. 18/jun. 22/jun.
900 28/mar. 06/may. 16/may. 23/may. 27/may.
1000 30/mar. 08/may. 18/may. 25/may. 29/may.
1100 08/abr. 17/may. 27/may. 03/jun. 07/jun.
1200 09/abr. 18/may. 28/may. 04/jun. 08/jun.
1300 18/abr. 27/may. 06/jun. 13/jun. 17/jun.
1400 20/abr. 29/may. 08/jun. 15/jun. 19/jun.
1500 01/abr. 10/may. 20/may. 27/may. 31/may.
1600 02/abr. 11/may. 21/may. 28/may. 01/jun.
1700 11/abr. 20/may. 30/may. 06/jun. 10/jun.
1800 13/abr. 22/may. 01/jun. 08/jun. 12/jun.
1900 15/abr. 24/may. 03/jun. 10/jun. 14/jun.
2000 23/abr. 01/jun. 11/jun. 18/jun. 22/jun.
2100 28/mar. 06/may. 16/may. 23/may. 27/may.
 
2010 04/abr. 13/may. 23/may. 30/may. 03/jun.
2011 24/abr. 02/jun. 12/jun. 19/jun. 23/jun.
2012 08/abr. 17/may. 27/may. 03/jun. 07/jun.
2013 31/mar. 09/may. 19/may. 26/may. 30/may.
2014 20/abr. 29/may. 08/jun. 15/jun. 19/jun.
2015 05/abr. 14/may. 24/may. 31/may. 04/jun.
2016 27/mar. 05/may. 15/may. 22/may. 26/may.
2017 16/abr. 25/may. 04/jun. 11/jun. 15/jun.
2018 01/abr. 10/may. 20/may. 27/may. 31/may.
2019 21/abr. 30/may. 09/jun. 16/jun. 20/jun.
2020 12/abr. 21/may. 31/may. 07/jun. 11/jun.</pre>
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?timeZone=UTC&script=examples/Holidays_related_to_Easter}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
This is a implementation of the [https://en.wikipedia.org/wiki/Date_of_Easter#Anonymous_Gregorian_algorithm "Meeus/Jones/Butcher" algorithm]:
 
[[File:Fōrmulæ - Holidays related to Easter 01.png]]
 
[[File:Fōrmulæ - Holidays related to Easter 02.png]]
 
'''Test cases'''
 
[[File:Fōrmulæ - Holidays related to Easter 03.png]]
 
[[File:Fōrmulæ - Holidays related to Easter 04.png]]
 
[[File:Fōrmulæ - Holidays related to Easter 05.png]]
 
[[File:Fōrmulæ - Holidays related to Easter 06.png]]
 
=={{header|FutureBasic}}==
This code outputs a complete Mac application showing the Julian Easter dates from 532 to 1582 and Gregorian Easter dates thereafter, without regard to historical niceties. The Gregorian rule has no set limits, but we went up to the year 10,000,000 (note that Gregorian Easter dates repeat every 5,700,000 years, so Easter 5702023 is on the same date as Easter 2023). Calculating other moveable feasts is trivial.
<syntaxhighlight lang=futurebasic>
 
begin enum 1
_window : _scroll : _showOff
_clmYear : _clmEaster : _lblYear : _lblEaster
_inField : _outField
end enum
 
void local fn buildInterface
window _window, @"Easter dates", ( 0, 0, 200, 200 ), 3
scrollview _scroll, ( 20, 80, 170, 91 )
textview _showOff, , _scroll
textlabel _clmYear, @"Year", ( 21, 168, 60, 22 )
textlabel _clmEaster, @"Easter", ( 92, 168, 140, 22 )
textlabel _lblYear, @"Year:", ( 40, 40, 100, 22 )
textlabel _lblEaster, @"Easter:", ( 31, 10, 100, 22 )
textlabel _outField, @"14 April", ( 87, 10, 100, 22 )
textfield _inField, , @"14250", ( 85, 42, 70, 22 )
ControlSetFormat ( _inField, @"0123456789", YES, 7, 0 )
TextSetFont( _showOff, fn FontMonospacedDigitSystemFontOfSize( 12 , 0 ) )
menu 1, , , @"File" : menu 1, 0, , @"Close", @"w"
MenuItemSetAction(1, 0, @"performClose:")
editmenu 2
WindowMakeFirstResponder( _window, _inField )
end fn
 
clear local fn easter( year as NSInteger) as CFStringRef
NSInteger goldenNumber, leapDays, century, epact
NSInteger moonAdjust, leapAdjust,fullMoon, easter
CFStringRef s = @""
goldenNumber = year mod 19 + 1 ' moon phase on 1 Jan
if year < 1583
// Algorithm by Dionysius Exiguus, 525
leapDays = 5 * year / 4 ' one leap year every four years
epact = ( 11 * goldenNumber - 4 ) mod 30 ' moon phase on 22 March
else
// Algorithm by Christoph Clavius, 1582 (see D. Knuth: CACM 1962;5:209)
century = int( year / 100 ) + 1
leapAdjust = int( ( 3 * century / 4 ) - 12 ) ' correct leap years
leapDays = int( 5 * year / 4 ) - leapAdjust - 10 ' new calculation of leap days
moonAdjust = int( ( 8 * century + 5 ) / 25 ) - 5 ' correct moon cycle
epact = ( 11 * goldenNumber + moonAdjust - leapAdjust + 20 ) mod 30 ' new calculation of moon phase
if epact < 0 then epact += 30
if ( epact = 24 or ( epact = 25 and goldenNumber > 11 ) ) then epact ++ ' final tweaks
end if
fullMoon = 44 - epact ' find first full moon in March
if fullMoon < 21 then fullMoon += 30 ' not before 21 March
easter = fullMoon + 7 - ( ( leapDays + fullMoon ) mod 7 ) ' find Sunday after first full moon in March
if easter < 32
s = fn StringWithFormat( @"%u March", easter )
else
s = fn StringWithFormat( @"%u April", easter - 31 )
end if
end fn = s
 
void local fn showOff
NSInteger year
CFMutableStringRef s = @"", t
for year = 532 to 2100 ' 532 is first year of Dionysius' tables
t = fn StringWithFormat( @"%u%@%@\n", year, @" ", fn easter( year) )
s = fn StringByAppendingString( s, t )
next
s = left( s, len( s ) - 1 ) ' cosmetic: remove last line feed
TextSetString( _showOff, s )
end fn
 
void local fn doEvents( evt as Long, tag as Long )
NSInteger t
select evt
case _textFieldDidChange
ControlSetStringValue ( _outField, @"" )
t = fn ControlIntegerValue( _inField )
if t > 531 then ControlSetStringValue ( _outField, fn easter( t ) )
case _windowShouldClose : end
end select
end fn
 
fn buildInterface
fn showOff
on dialog fn doEvents
 
handleevents
</syntaxhighlight>
{{output}}
[[File:Easter.jpg]]
 
In '''[https://formulae.org/?example=Holidays_related_to_Easter this]''' page you can see the program(s) related to this task and their results.
 
=={{header|Go}}==
Line 3,135 ⟶ 3,424:
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="textmk-61">П2 1 9 ПП 86 90 П3 ИП2 4 ПП 86 90
П4 ИП2 7 ПП 86 90 П5 1 9 ИП3 *
1 5 + 3 0 ПП 86 90 П6 2 ИП4
* 4 ИП5 * + 6 ИП6 * + 6
+ 7 ПП 86 90 ИП6 + П1 3 П4 ИП2
1 - 2 10^x / [x] ^ ^ 4 /
[x] - 2 0 + ИП1 + П3 3 1
- /-/ x>=<0 76 78 |x| П3 КИП4 KИП4 ИП3 3 0 - x>= 0
83 - /-/ x<0 87 |x| П3 КИП4 KИП4 ИП3 ИП4 С/П П0 <-> П1 <->
П0 <-> П1 <-> / [x] ИП0 * ИП1 - /-/ В/О</syntaxhighlight>
/-/ В/О</syntaxhighlight>
 
Calculated, of course, the Orthodox Easter. Enter the number of the year, the result of: the day in the register Y, a month in the register X.
 
For the subsequent calculation of Ascension and Pentecost (Trinity Day):
 
<syntaxhighlight lang="text">П0 <-> П1 <-> - 1 3 + П1 3
1 - /-/ x>=<0 19 21 |x| П1 ИП0 1 + П0 ИП0
П0 ИП0 1 + П0 ИП1 ИП0 С/П ИП1 1 0 +
0 + П1 3 1 - /-/ x<0 45 |x|
П1 3 1 - x>=0 41 П1 ИП0 1 +
П1 ИП0 1 + П0 ИП1 ИП0 С/П</syntaxhighlight>
 
''Example'': Easter in 2014 is 20.04; Ascension is 29.05; Pentecost is 08.06.
Line 5,187 ⟶ 5,477:
{{libheader|Wren-fmt}}
{{libheader|Wren-iterate}}
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
import "./fmt" for Fmt
import "./iterate" for Stepped
 
var holidayOffsets = [
9,476

edits