-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasterCalculator.java
436 lines (379 loc) · 14.9 KB
/
EasterCalculator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
package javaapplication3;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* This class calculates all the mobile Orthodox holy days.
*
* @author Drakoulelis <drakouleli at ceid.upatras.gr>
*/
public final class EasterCalculator {
private Calendar easter;
private Calendar forefathers;
private Calendar george;
private Calendar mark;
private Calendar cloe;
/**
*
* @param year The year to search dates for. It must be over 1582.
*/
public EasterCalculator(int year) {
if (year <= 1582) {
throw new IllegalArgumentException("Algorithm invalid before April 1583");
}
easter = calculateEaster(year);
forefathers = calculateSundayOfTheForefathers(year);
george = calculateSaintGeorge(year);
mark = calculateMarkTheEvangelist(year);
cloe = calculateCloe(year);
}
private GregorianCalendar calculateEaster(int year) {
int e = 10;
if (year > 1600) {
int y2 = (int) Math.floor(year / 100);
e = 10 + y2 - 16 - (int) Math.floor((y2 - 16) / 4);
}
int G = year % 19;
int I = (19 * G + 15) % 30;
int J = (year + (int) Math.floor(year / 4) + I) % 7;
int L = I - J;
int p = L + e;
int d = 1 + (p + 27 + (int) Math.floor((p + 6) / 40)) % 31;
int m = 3 + (int) Math.floor((p + 26) / 30) - 1;
return new GregorianCalendar(year, m, d);
}
private GregorianCalendar calculateSundayOfTheForefathers(int year) {
GregorianCalendar f = new GregorianCalendar(year, Calendar.DECEMBER, 11);
if (f.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
f.add(Calendar.DAY_OF_WEEK, Calendar.SATURDAY - f.get(Calendar.DAY_OF_WEEK) + Calendar.SUNDAY);
}
return f;
}
private GregorianCalendar calculateSaintGeorge(int year) {
GregorianCalendar g = new GregorianCalendar(year, Calendar.APRIL, 23);
if (g.before(easter) || g.equals(easter)) {
g = (GregorianCalendar) easter.clone();
g.add(Calendar.DAY_OF_MONTH, 1);
}
return g;
}
private GregorianCalendar calculateMarkTheEvangelist(int year) {
GregorianCalendar m = new GregorianCalendar(year, Calendar.APRIL, 25);
if (m.before(george) || m.equals(george)) {
m = (GregorianCalendar) george.clone();
m.add(Calendar.DAY_OF_MONTH, 1);
}
return m;
}
private GregorianCalendar calculateCloe(int year) {
GregorianCalendar c = new GregorianCalendar(year, Calendar.FEBRUARY, 13);
if (c.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
c.add(Calendar.DAY_OF_WEEK, Calendar.SATURDAY - c.get(Calendar.DAY_OF_WEEK) + Calendar.SUNDAY);
}
return c;
}
/**
* Returns Easter day. Also known as "Πάσχα"
*
* @return a Calendar object representing the day.
*/
public Calendar getEaster() {
return easter;
}
/**
* Returns Sunday of the Forefathers. Also known as "Των Προπατόρων"
*
* @return a Calendar object representing the day.
*/
public Calendar getSundayOfTheForefathers() {
return forefathers;
}
/**
* Returns Saint George day.
*
* @return a Calendar object representing the day.
*/
public Calendar getSaintGeorgeDay() {
return george;
}
/**
* Returns Mark the Evangelist day.
*
* @return a Calendar object representing the day.
*/
public Calendar getMarkTheEvangelistDay() {
return mark;
}
/**
* Returns Saint Cloe day.
*
* @return a Calendar object representing the day.
*/
public Calendar getSaintCloeDay() {
return cloe;
}
/**
* Calculates the start of the Triodion day. Also known as the Publican (or
* "Τελώνου και Φαρισαίου").
*
* @return a Calendar object representing the day.
*/
public Calendar getPublicanDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 70);
}
/**
* Calculates the prodigal son day.
*
* @return a Calendar object representing the day.
*/
public Calendar getProdigal() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 63);
}
/**
* Calculates the All Souls (A) day. Also known as "Ψυχοσάββατον Α'"
*
* @return a Calendar object representing the day.
*/
public Calendar getAllSoulsDayA() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 57);
}
/**
* Calculates the All Souls (B) day. Also known as "Ψυχοσάββατον Β'"
*
* @return a Calendar object representing the day.
*/
public Calendar getAllSoulsDayB() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 48);
}
/**
* Calculates the Carnival day. Also known as "Αποκριά"
*
* @return a Calendar object representing the day.
*/
public Calendar getCarnivalDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 56);
}
/**
* Calculates Shrove Monday. Also known as "Καθαρά Δευτέρα"
*
* @return a Calendar object representing the day.
*/
public Calendar getShroveMonday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 48);
}
/**
* Calculates Shrove Thursday. Also known as "Τσικνοπέμπτη"
*
* @return a Calendar object representing the day.
*/
public Calendar getShroveThursday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 59);
}
/**
* Calculates Shrovetide Sunday. Also known as "Κυριακή της Τυροφάγου"
*
* @return a Calendar object representing the day.
*/
public Calendar getCheeseSunday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 49);
}
/**
* Calculates the Gregory Palamas day.
*
* @return a Calendar object representing the day.
*/
public Calendar getGregoryPalamasDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 35);
}
/**
* Calculates the Saint Theodore's day.
*
* @return a Calendar object representing the day.
*/
public Calendar getSaintTheodoreDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 43);
}
/**
* Calculates Sunday of Orthodoxy.
*
* @return a Calendar object representing the day.
*/
public Calendar getSundayOfOrthodoxy() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 42);
}
/**
* Calculates Lazarus Saturday.
*
* @return a Calendar object representing the day.
*/
public Calendar getLazarusDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 8);
}
/**
* Calculates Palm Sunday. Also known as "Κυριακή των Βαίων"
*
* @return a Calendar object representing the day.
*/
public Calendar getPalmSunday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 7);
}
/**
* Calculates Holy Monday. Also known as "Μεγάλη Δευτέρα"
*
* @return a Calendar object representing the day.
*/
public Calendar getHolyMonday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 6);
}
/**
* Calculates Holy Tuesday. Also known as "Μεγάλη Τρίτη"
*
* @return a Calendar object representing the day.
*/
public Calendar getHolyTuesday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 5);
}
/**
* Calculates Holy Wednesday. Also known as "Μεγάλη Τετάρτη"
*
* @return a Calendar object representing the day.
*/
public Calendar getHolyWednesday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 4);
}
/**
* Calculates Holy Thursday. Also known as "Μεγάλη Πέμπτη"
*
* @return a Calendar object representing the day.
*/
public Calendar getHolyThursday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 3);
}
/**
* Calculates Holy Friday. Also known as "Μεγάλη Παρασκευή"
*
* @return a Calendar object representing the day.
*/
public Calendar getHolyFriday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 2);
}
/**
* Calculates Holy Saturday. Also known as "Μεγάλο Σάββατο"
*
* @return a Calendar object representing the day.
*/
public Calendar getHolySaturday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) - 1);
}
/**
* Calculates Easter Monday. Also known as "Δευτέρα του Πάσχα"
*
* @return a Calendar object representing the day.
*/
public Calendar getEasterMonday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 1);
}
/**
* Calculates Easter Tuesday. Also known as "Τρίτη του Πάσχα"
*
* @return a Calendar object representing the day.
*/
public Calendar getEasterTuesday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 2);
}
/**
* Calculates Easter Wednesday. Also known as "Τετάρτη του Πάσχα"
*
* @return a Calendar object representing the day.
*/
public Calendar getEasterWednesday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 3);
}
/**
* Calculates Easter Thursday. Also known as "Πέμπτη του Πάσχα"
*
* @return a Calendar object representing the day.
*/
public Calendar getEasterThursday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 4);
}
/**
* Calculates Easter Friday. Also known as "Παρασκεύη του Πάσχα"
*
* @return a Calendar object representing the day.
*/
public Calendar getEasterFriday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 5);
}
/**
* Calculates Easter Saturday. Also known as "Σάββατο του Πάσχα"
*
* @return a Calendar object representing the day.
*/
public Calendar getEasterSaturday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 6);
}
/**
* Calculates the Life Giving Spring day. Also known as "Ζωοδόχου Πηγής"
*
* @return a Calendar object representing the day.
*/
public Calendar getLifeGivingSpringDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 5);
}
/**
* Calculates Thomas Sunday. Also known as "Κυριακή του Θωμά"
*
* @return a Calendar object representing the day.
*/
public Calendar getThomasSunday() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 7);
}
/**
* Calculates the Myrrhbearers day. Also known as "Μυροφόρα"
*
* @return a Calendar object representing the day.
*/
public Calendar getMyrrhbearersDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 14);
}
/**
* Calculates the Paralytic's day. Also known as "Βηθεσδά"
*
* @return a Calendar object representing the day.
*/
public Calendar getParalyticDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 21);
}
/**
* Calculates the Ascension day. Also known as "Ανάληψη"
*
* @return a Calendar object representing the day.
*/
public Calendar getAscensionDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 39);
}
/**
* Calculates the Pentecost day. Also known as "Πεντηκοστή"
*
* @return a Calendar object representing the day.
*/
public Calendar getPentecostDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 49);
}
/**
* Calculates the All Saints day. Also known as "Αγίων Πάντων"
*
* @return a Calendar object representing the day.
*/
public Calendar getAllSaintsDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 56);
}
/**
* Calculates the Holy Spirit's day. Also known as "Αγίου Πνεύματος"
*
* @return a Calendar object representing the day.
*/
public Calendar getHolySpiritDay() {
return new GregorianCalendar(easter.get(Calendar.YEAR), easter.get(Calendar.MONTH), easter.get(Calendar.DAY_OF_MONTH) + 50);
}
}