Die Katholiken und ihre Feste …und Java

Das mit den Ostertagen, Adventssontagen oder der Christi Himmelfahrt ist so eine Sache. Der kirchliche Kalender geht nach dem Mond (Teilweise jedenfalls). Für diejenigen, die – genauso wie ich – wissen wollen, ob an einem bestimmten Tag der normale Fahrplan zu präsentieren ist oder der vom Sonntag [ aber auch für alle Katholiken, die in ihrem java-Programm schnell prüfen wollen, ob da nicht ein wichtiger christlicher Feiertag fällt ] gibt es die schöne Klasse CatholicCalendar. Es ist meine eigene Entwicklung. Sie enthält zwar nicht alle katholischen Feiertage (25.03 oder 15.08 sind nicht dabei, weil sie nicht überall gelten und sonst wie geprüft werden können).
Die methoden sind statisch, so kann man es ohne eine Initialisierung (ad hoc) verwenden:

if(CatholicCalendar.isMaundyThursday(new Date()))
{
System.out.println("Heute ist Gründonnerstag");
}


…und siehe da: Heute ist Gründonnerstag (was auch stimmt)
BTW: „Gründonnerstag“ hat nichts mit „Grün“ zu tun, sondern mit „Greinen“ (altertümlich für „Weinen“)!
Eine Antwort auf die Frage „Warum ist Ostern mal Früher, mal später?“ sucht findet diese hier.
Und hier ist die Klasse (CatholicCalendar.java):

/**
* A class to check if a date (Date object) is a catholic holiday (or one of special days)
* @author RK
* @license GPLv3
*/
import java.util.*;
public class CatholicCalendar {

public static GregorianCalendar prepareDate(Date d)
{
Calendar c = Calendar.getInstance();
c.setTime(d);
return new GregorianCalendar(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
}

/**
* Return true if given date is first sunday in advent (Ad te levavi)
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isFirstAdvent(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 12-1, 24);
e.add(Calendar.DAY_OF_YEAR, -21);
for (int i = 0; e.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY; i++) {
e.add(Calendar.DAY_OF_YEAR, -1);
}
if (e.compareTo(t) == 0) {
return true;
}
return false;
}

/**
* Return true if given date is second sunday in advent (Populus Sion)
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isSecondAdvent(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 12-1, 24);
e.add(Calendar.DAY_OF_YEAR, -14);
for (int i = 0; e.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY; i++) {
e.add(Calendar.DAY_OF_YEAR, -1);
}
if (e.compareTo(t) == 0) {
return true;
}
return false;
}

/**
* Return true if given date is third sunday in advent (Gaudete)
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isThirsAdvent(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 12-1, 24);
e.add(Calendar.DAY_OF_YEAR, -7);
for (int i = 0; e.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY; i++) {
e.add(Calendar.DAY_OF_YEAR, -1);
}
if (e.compareTo(t) == 0) {
return true;
}
return false;
}

/**
* Return true if given date is fourth sunday in advent (Rorate)
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isFourthAdvent(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 12-1, 24);
for (int i = 0; e.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY; i++) {
e.add(GregorianCalendar.DAY_OF_YEAR, -1);
}
if (e.compareTo(t) == 0) {
return true;
}
return false;
}

/**
* Return true if given date is first Christmas day
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isChristmasDay(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 12-1, 25);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is second christmas day
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isStStephansDay(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 12-1, 26);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is second christmas day
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isHollyFamilySunday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 12-1, 26);
if (e.compareTo(t) == -1) {
for (int i = 0; e.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY; i++) {
e.add(Calendar.DAY_OF_YEAR, +1);
}
if (e.compareTo(t) == 0) {
return true;
}
}
return false;
}
/**
* Return true if given date is New Year's Day
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isNewYearsDay(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 1-1, 1);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Epiphany (Three Kings)
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isEpiphany(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar(c.get(Calendar.YEAR), 1-1, 6);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Ash Wednesday
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isAshWednesday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, -46);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Laetare Sunday
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isLaetare(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, -21);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Palm Sunday
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isPalmSunday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, -7);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Maundy Thursday de: "Gründonnerstag"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isMaundyThursday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, -3);
System.out.println(e.toString());
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Good Friday de: "Karfreitag"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isGoodFriday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, -2);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Holy Saturday de: "Karsammstag"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isHolySaturday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, -1);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return Easter date for a given year
*
* @param year
* int must be > 1583
* @return Easter date as GregorianCalendar object
*/
public static Calendar easterDate(int year) {
int modulo19 = year % 19;
int cent = (int) (year / 100);
int centAdd = year % 100;
int i = (19 * modulo19 + cent - (cent / 4)
- ((cent - ((cent + 8 ) / 25) + 1) / 3) + 15) % 30;
int j = (32 + 2 * (cent % 4) + 2 * (centAdd / 4) - i - (centAdd % 4)) % 7;
int k = i + j - 7 * ((modulo19 + 11 * i + 22 * j) / 451) + 114;
int month = k / 31;
int day = (k % 31) + 1;
return new GregorianCalendar(year, month - 1, day);
}
/**
* Return true if given date is Easter Sunday de: "Ostersonntag"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isEasterSunday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Easter Monday de: "Ostermontag"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isEasterMonday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, +1);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Ascension de: "Christi Himmelfahrt"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isAscension(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, +39);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Pentecost Sunday de: "Pfingstsonntag"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isPentecostSunday(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, +49);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Pentecost Monday de: "Pfingstmontag"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isPentecostMontag(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, +50);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Corpus Christi de: "Fronleichnahm"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isCorpusChristi(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, +60);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is Trinitas de: "Dreifaltigkeitssontag"
*
* @param d
* Date to check
* @return boolean true if so
*/
public static boolean isTrinitas(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = easterDate(c.get(Calendar.YEAR));
e.add(Calendar.DAY_OF_YEAR, +66);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
/**
* Return true if given date is All Saints' Day de: "Allerheiligen"
*
* @param d
* @return
*/
public static boolean isAllSaintsDay(Date d) {
GregorianCalendar t = prepareDate(d);
Calendar c = Calendar.getInstance();
c.setTime(d);
Calendar e = new GregorianCalendar (c.get(Calendar.YEAR), 11-1, 1);
if (e.compareTo(t) == 0) {
return true;
}
return false;
}
}

Hoffe, habe keinen Fehler. Getestet habe ich es jedenfalls nur teilweise!

Ach so! habe ich schon erwähnt, dass der erste Tag der Woche Sonntag ist? Jedenfalls nach der jüdisch-christlichen Tradition. Nach ISO-schlagmichtot ist es der Montag…