View Javadoc

1   /*
2    *  File: HolidayEnumerator_de_DE.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package de.jaret.util.date.holidayenumerator;
12  
13  import java.util.Calendar;
14  import java.util.Date;
15  import java.util.Locale;
16  
17  /**
18   * HolidayEnumerator for Germany. The Regions are used to indicate the state (Bundesland). Holidays not valid in the
19   * selected region are marked as special days. If no region is given the days are also marked as special days. <b>The
20   * calculations are without any warranty!</b>
21   * 
22   * @author Peter Kliem
23   * @version $Id: HolidayEnumerator_de_DE.java 297 2007-03-12 21:38:00Z olk $
24   */
25  public class HolidayEnumerator_de_DE extends HolidayEnumeratorBase {
26      /** RegionId for Nordrhein-Westfalen. */
27      public static final String DE_DE_REGION_NRW = "NRW";
28      /** RegionID for Berlin. */
29      public static final String DE_DE_REGION_BLN = "BLN";
30      /** RegionID for Bayern. */
31      public static final String DE_DE_REGION_BAV = "BAV";
32      /** RegionID for Hamburg. */
33      public static final String DE_DE_REGION_HH = "HH";
34      /** RegionID for Bremen. */
35      public static final String DE_DE_REGION_HB = "HB";
36      /** RegionID for Schleswig-Holstein. */
37      public static final String DE_DE_REGION_SHLST = "SHLST";
38      /** RegionID for Niedersachsen. */
39      public static final String DE_DE_REGION_NIE = "NIE";
40      /** RegionID for Mecklenburg-Vorpommern. */
41      public static final String DE_DE_REGION_MVP = "MVP";
42      /** RegionID for Brandenburg. */
43      public static final String DE_DE_REGION_BRA = "BRA";
44      /** RegionID for Thueringen. */
45      public static final String DE_DE_REGION_THUE = "THUE";
46      /** RegionID for Sachsen. */
47      public static final String DE_DE_REGION_SACH = "SACH";
48      /** RegionID for Sachsen-Anhalt. */
49      public static final String DE_DE_REGION_SAAN = "SAAN";
50      /** RegionID for Baden-Wuertenberg. */
51      public static final String DE_DE_REGION_BAWUE = "BAWUE";
52      /** RegionID for Hessen. */
53      public static final String DE_DE_REGION_HES = "HES";
54      /** RegionID for Saarland. */
55      public static final String DE_DE_REGION_SAAR = "SAAR";
56      /** RegionID for Rheinland-Pfalz. */
57      public static final String DE_DE_REGION_RHPFA = "RHPFA";
58  
59      private static final String[] REGIONIDS = {DE_DE_REGION_NRW, DE_DE_REGION_BLN, DE_DE_REGION_BAV, DE_DE_REGION_HH,
60              DE_DE_REGION_HB, DE_DE_REGION_SHLST, DE_DE_REGION_NIE, DE_DE_REGION_MVP, DE_DE_REGION_BRA,
61              DE_DE_REGION_THUE, DE_DE_REGION_SACH, DE_DE_REGION_SAAN, DE_DE_REGION_BAWUE, DE_DE_REGION_HES,
62              DE_DE_REGION_SAAR, DE_DE_REGION_RHPFA};
63  
64      /**
65       * Construct a holiday enumerator for germany.
66       * 
67       * @param regionId region id or <code>null</code> for no special region
68       */
69      public HolidayEnumerator_de_DE(String regionId) {
70          _regionId = regionId;
71          _locale = Locale.GERMANY;
72      }
73  
74  
75      /**
76       * {@inheritDoc}
77       */
78      public String[] getAvailableRegionIds() {
79          return REGIONIDS;
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      protected void fillMap(int year) {
86          // general holidays
87          addNamedDate(year, 0, 1, true, "Neujahr");
88          addNamedDate(year, 4, 1, true, "Tag der Arbeit");
89          addNamedDate(year, 9, 3, true, "Tag der deutschen Einheit");
90          addNamedDate(year, 11, 24, false, "Heiligabend");
91          addNamedDate(year, 11, 25, true, "1. Weihnachtsfeiertag");
92          addNamedDate(year, 11, 26, true, "2. Weihnachtsfeiertag");
93          addNamedDate(year, 11, 31, false, "Sylvester");
94  
95          // easter days
96          EasyDate ed = calcEaster(year);
97          addNamedDate(year, ed.month, ed.day, true, "Ostersonntag");
98          addNamedDate(year, ed.month, ed.day, 1, true, "Ostermontag");
99          addNamedDate(year, ed.month, ed.day, -2, true, "Karfreitag");
100 
101         // christi himmelfahrt
102         addNamedDate(year, ed.month, ed.day, 39, true, "Christi Himmelfahrt");
103 
104         // pfingsten
105         addNamedDate(year, ed.month, ed.day, 49, true, "Pfingstsonntag");
106         addNamedDate(year, ed.month, ed.day, 50, true, "Pfingstmontag");
107 
108         // hl drei kˆnige
109         // bayern, sachsen-anhalt und bw
110         if (_regionId != null
111                 && (_regionId.equals(DE_DE_REGION_BAV) || _regionId.equals(DE_DE_REGION_SAAN) || _regionId
112                         .equals(DE_DE_REGION_BAWUE))) {
113             addNamedDate(year, 0, 6, true, "Heilige drei Kˆnige");
114         } else {
115             addNamedDate(year, 0, 6, false, "Heilige drei Kˆnige");
116         }
117 
118         // fronleichnam
119         // bayer, bawue, hessen nrw, rheinland-pfalz, saarland
120         if (_regionId != null
121                 && (_regionId.equals(DE_DE_REGION_BAV) || _regionId.equals(DE_DE_REGION_BAWUE)
122                         || _regionId.equals(DE_DE_REGION_HES) || _regionId.equals(DE_DE_REGION_NRW)
123                         || _regionId.equals(DE_DE_REGION_RHPFA) || _regionId.equals(DE_DE_REGION_SAAR))) {
124             addNamedDate(year, ed.month, ed.day, 60, true, "Fronleichnam");
125         } else {
126             addNamedDate(year, ed.month, ed.day, 60, false, "Fronleichnam");
127         }
128 
129         // Mari‰ Himmelfahrt
130         // nur saarland
131         if (_regionId != null && (_regionId.equals(DE_DE_REGION_SAAR))) {
132             addNamedDate(year, 7, 15, true, "Mari‰ Himmelfahrt");
133         } else {
134             addNamedDate(year, 7, 15, false, "Mari‰ Himmelfahrt");
135         }
136 
137         // reformationstag
138         // brandnburg, meck vorpomm, sachen, s-anhalt, th¸ringen
139         if (_regionId != null
140                 && (_regionId.equals(DE_DE_REGION_BRA) || _regionId.equals(DE_DE_REGION_MVP)
141                         || _regionId.equals(DE_DE_REGION_SACH) || _regionId.equals(DE_DE_REGION_SAAN) || _regionId
142                         .equals(DE_DE_REGION_THUE))) {
143             addNamedDate(year, 9, 31, true, "Reformationstag");
144         } else {
145             addNamedDate(year, 9, 31, false, "Reformationstag");
146         }
147 
148         // allerheiligen
149         // bayern, bawue, nrw, rhpfalz, saarland,
150         if (_regionId != null
151                 && (_regionId.equals(DE_DE_REGION_BAV) || _regionId.equals(DE_DE_REGION_BAWUE)
152                         || _regionId.equals(DE_DE_REGION_NRW) || _regionId.equals(DE_DE_REGION_RHPFA) || _regionId
153                         .equals(DE_DE_REGION_SAAR))) {
154             addNamedDate(year, 10, 1, true, "Allerheiligen");
155         } else {
156             addNamedDate(year, 10, 1, false, "Allerheiligen");
157         }
158 
159         // buss und bettag
160         // Mittwoch vor dem letzten Sonntag im Kirchenjahr, d. h. der Mittwoch zwischen dem 16. und 22. November
161         // nur sachsen
162         EasyDate bbt = calcBussBettag(year);
163         if (_regionId != null && (_regionId.equals(DE_DE_REGION_SACH))) {
164             addNamedDate(year, bbt.month, bbt.day, true, "Bufl- und Bettag");
165         } else {
166             addNamedDate(year, bbt.month, bbt.day, false, "Bufl- und Bettag");
167         }
168 
169         // special days only
170         addNamedDate(year, ed.month, ed.day, -48, false, "Rosenmontag");
171         addNamedDate(year, ed.month, ed.day, -52, false, "Weiberfastnacht");
172     }
173 
174     /**
175      * Calculate the buss- und bettag. (Mittwoch vor dem letzten Sonntag im Kirchenjahr, d. h. der Mittwoch zwischen dem
176      * 16. und 22. November)
177      * 
178      * @param year year
179      * @return EasyDatewith the date
180      */
181     protected EasyDate calcBussBettag(int year) {
182         EasyDate result = null;
183         int i = 0;
184         while (i < 7 && result == null) {
185             Date d = getDate(year, 10, 16, i);
186             if (getWeekday(d) == Calendar.WEDNESDAY) {
187                 result = new EasyDate(d);
188             }
189             i++;
190         }
191         return result;
192     }
193 
194 }