2 *******************************************************************************
\r
3 * Copyright (C) 1996-2006, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.util;
\r
10 import java.util.Date;
\r
11 import com.ibm.icu.util.Calendar;
\r
12 import com.ibm.icu.util.GregorianCalendar;
\r
15 * A holiday whose date can be represented by a month, day, and optionally day of week
\r
16 * in the Gregorian calendar.
\r
18 * @draft ICU 2.8 (retainAll)
\r
19 * @provisional This API might change or be removed in a future release.
\r
21 public class SimpleHoliday extends Holiday {
\r
23 * Construct an object representing a holiday
\r
25 * @param month The month in which this holiday occurs (0-based)
\r
26 * @param dayOfMonth The date within the month (1-based).
\r
28 * @param name The name of this holiday. This string is used as a key
\r
29 * to look up the holiday's name a resource bundle.
\r
30 * If the name is not found in the resource bundle,
\r
31 * getDisplayName will return this string instead.
\r
33 * @see Holiday#getDisplayName(java.util.Locale)
\r
35 * @provisional This API might change or be removed in a future release.
\r
37 public SimpleHoliday(int month, int dayOfMonth, String name)
\r
39 super(name, new SimpleDateRule(month, dayOfMonth));
\r
43 * Construct an object representing a holiday
\r
45 * @param month The month in which this holiday occurs (0-based)
\r
46 * @param dayOfMonth The date within the month (1-based).
\r
48 * @param name The name of this holiday. This string is used as a key
\r
49 * to look up the holiday's name a resource bundle.
\r
50 * If the name is not found in the resource bundle,
\r
51 * getDisplayName will return this string instead.
\r
53 * @see Holiday#getDisplayName(java.util.Locale)
\r
55 * @provisional This API might change or be removed in a future release.
\r
57 public SimpleHoliday(int month, int dayOfMonth, String name,
\r
60 super(name, rangeRule(startYear, 0, new SimpleDateRule(month, dayOfMonth)));
\r
64 * Construct an object representing a holiday
\r
66 * @param month The month in which this holiday occurs (0-based)
\r
67 * @param dayOfMonth The date within the month (1-based).
\r
69 * @param name The name of this holiday. This string is used as a key
\r
70 * to look up the holiday's name a resource bundle.
\r
71 * If the name is not found in the resource bundle,
\r
72 * getDisplayName will return this string instead.
\r
74 * @see Holiday#getDisplayName(java.util.Locale)
\r
76 * @provisional This API might change or be removed in a future release.
\r
78 public SimpleHoliday(int month, int dayOfMonth, String name,
\r
79 int startYear, int endYear)
\r
81 super(name, rangeRule(startYear, endYear, new SimpleDateRule(month, dayOfMonth)));
\r
85 * Construct an object representing a holiday
\r
87 * @param month The month in which this holiday occurs (0-based)
\r
89 * @param dayOfMonth A date within the month (1-based). The
\r
90 * interpretation of this parameter depends on the value of
\r
91 * <code>dayOfWeek</code>.
\r
93 * @param dayOfWeek The day of the week on which this holiday occurs.
\r
94 * The following values are legal: <ul>
\r
95 * <li>dayOfWeek == 0 - use dayOfMonth only
\r
96 * <li>dayOfWeek < 0 - use last -dayOfWeek before or on dayOfMonth
\r
97 * <li>dayOfWeek > 0 - use first dayOfWeek after or on dayOfMonth
\r
100 * @param name The name of this holiday. This string is used as a key
\r
101 * to look up the holiday's name a resource bundle.
\r
102 * If the name is not found in the resource bundle,
\r
103 * getDisplayName will return this string instead.
\r
105 * @see Holiday#getDisplayName(java.util.Locale)
\r
107 * @provisional This API might change or be removed in a future release.
\r
109 public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name)
\r
111 super(name, new SimpleDateRule(month, dayOfMonth,
\r
112 dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
\r
118 * @provisional This API might change or be removed in a future release.
\r
120 public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name,
\r
123 super(name, rangeRule(startYear, 0,
\r
124 new SimpleDateRule(month, dayOfMonth,
\r
125 dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
\r
132 * @provisional This API might change or be removed in a future release.
\r
134 public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name,
\r
135 int startYear, int endYear)
\r
137 super(name, rangeRule(startYear, endYear,
\r
138 new SimpleDateRule(month, dayOfMonth,
\r
139 dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
\r
143 private static DateRule rangeRule(int startYear, int endYear, DateRule rule)
\r
145 if (startYear == 0 && endYear == 0) {
\r
149 RangeDateRule rangeRule = new RangeDateRule();
\r
151 if (startYear != 0) {
\r
152 Calendar start = new GregorianCalendar(startYear, Calendar.JANUARY, 1);
\r
153 rangeRule.add(start.getTime(), rule);
\r
155 rangeRule.add(rule);
\r
157 if (endYear != 0) {
\r
158 Date end = new GregorianCalendar(endYear, Calendar.DECEMBER, 31).getTime();
\r
159 rangeRule.add(end, null);
\r
165 /* Constants for holidays that are common throughout the Western
\r
166 * and Christian worlds.... */
\r
169 * New Year's Day - January 1st
\r
171 * @provisional This API might change or be removed in a future release.
\r
173 public static final SimpleHoliday NEW_YEARS_DAY =
\r
174 new SimpleHoliday(Calendar.JANUARY, 1, "New Year's Day");
\r
177 * Epiphany, January 6th
\r
179 * @provisional This API might change or be removed in a future release.
\r
181 public static final SimpleHoliday EPIPHANY =
\r
182 new SimpleHoliday(Calendar.JANUARY, 6, "Epiphany");
\r
187 * @provisional This API might change or be removed in a future release.
\r
189 public static final SimpleHoliday MAY_DAY =
\r
190 new SimpleHoliday(Calendar.MAY, 1, "May Day");
\r
193 * Assumption, August 15th
\r
195 * @provisional This API might change or be removed in a future release.
\r
197 public static final SimpleHoliday ASSUMPTION =
\r
198 new SimpleHoliday(Calendar.AUGUST, 15, "Assumption");
\r
201 * All Saints' Day, November 1st
\r
203 * @provisional This API might change or be removed in a future release.
\r
205 public static final SimpleHoliday ALL_SAINTS_DAY =
\r
206 new SimpleHoliday(Calendar.NOVEMBER, 1, "All Saints' Day");
\r
209 * All Souls' Day, November 1st
\r
211 * @provisional This API might change or be removed in a future release.
\r
213 public static final SimpleHoliday ALL_SOULS_DAY =
\r
214 new SimpleHoliday(Calendar.NOVEMBER, 2, "All Souls' Day");
\r
217 * Immaculate Conception, December 8th
\r
219 * @provisional This API might change or be removed in a future release.
\r
221 public static final SimpleHoliday IMMACULATE_CONCEPTION =
\r
222 new SimpleHoliday(Calendar.DECEMBER, 8, "Immaculate Conception");
\r
225 * Christmas Eve, December 24th
\r
227 * @provisional This API might change or be removed in a future release.
\r
229 public static final SimpleHoliday CHRISTMAS_EVE =
\r
230 new SimpleHoliday(Calendar.DECEMBER, 24, "Christmas Eve");
\r
233 * Christmas, December 25th
\r
235 * @provisional This API might change or be removed in a future release.
\r
237 public static final SimpleHoliday CHRISTMAS =
\r
238 new SimpleHoliday(Calendar.DECEMBER, 25, "Christmas");
\r
241 * Boxing Day, December 26th
\r
243 * @provisional This API might change or be removed in a future release.
\r
245 public static final SimpleHoliday BOXING_DAY =
\r
246 new SimpleHoliday(Calendar.DECEMBER, 26, "Boxing Day");
\r
249 * Saint Stephen's Day, December 26th
\r
251 * @provisional This API might change or be removed in a future release.
\r
253 public static final SimpleHoliday ST_STEPHENS_DAY =
\r
254 new SimpleHoliday(Calendar.DECEMBER, 26, "St. Stephen's Day");
\r
257 * New Year's Eve, December 31st
\r
259 * @provisional This API might change or be removed in a future release.
\r
261 public static final SimpleHoliday NEW_YEARS_EVE =
\r
262 new SimpleHoliday(Calendar.DECEMBER, 31, "New Year's Eve");
\r