2 *******************************************************************************
\r
3 * Copyright (C) 1996-2010, 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
13 * <b>Note:</b> The Holiday framework is a technology preview.
\r
14 * Despite its age, is still draft API, and clients should treat it as such.
\r
16 * A holiday whose date can be represented by a month, day, and optionally day of week
\r
17 * in the Gregorian calendar.
\r
19 * @draft ICU 2.8 (retainAll)
\r
20 * @provisional This API might change or be removed in a future release.
\r
22 public class SimpleHoliday extends Holiday {
\r
24 * Construct an object representing a holiday
\r
26 * @param month The month in which this holiday occurs (0-based)
\r
27 * @param dayOfMonth The date within the month (1-based).
\r
29 * @param name The name of this holiday. This string is used as a key
\r
30 * to look up the holiday's name a resource bundle.
\r
31 * If the name is not found in the resource bundle,
\r
32 * getDisplayName will return this string instead.
\r
34 * @see Holiday#getDisplayName(java.util.Locale)
\r
36 * @provisional This API might change or be removed in a future release.
\r
38 public SimpleHoliday(int month, int dayOfMonth, String name)
\r
40 super(name, new SimpleDateRule(month, dayOfMonth));
\r
44 * Construct an object representing a holiday
\r
46 * @param month The month in which this holiday occurs (0-based)
\r
47 * @param dayOfMonth The date within the month (1-based).
\r
49 * @param name The name of this holiday. This string is used as a key
\r
50 * to look up the holiday's name a resource bundle.
\r
51 * If the name is not found in the resource bundle,
\r
52 * getDisplayName will return this string instead.
\r
54 * @see Holiday#getDisplayName(java.util.Locale)
\r
56 * @provisional This API might change or be removed in a future release.
\r
58 public SimpleHoliday(int month, int dayOfMonth, String name,
\r
61 super(name, rangeRule(startYear, 0, new SimpleDateRule(month, dayOfMonth)));
\r
65 * Construct an object representing a holiday
\r
67 * @param month The month in which this holiday occurs (0-based)
\r
68 * @param dayOfMonth The date within the month (1-based).
\r
70 * @param name The name of this holiday. This string is used as a key
\r
71 * to look up the holiday's name a resource bundle.
\r
72 * If the name is not found in the resource bundle,
\r
73 * getDisplayName will return this string instead.
\r
75 * @see Holiday#getDisplayName(java.util.Locale)
\r
77 * @provisional This API might change or be removed in a future release.
\r
79 public SimpleHoliday(int month, int dayOfMonth, String name,
\r
80 int startYear, int endYear)
\r
82 super(name, rangeRule(startYear, endYear, new SimpleDateRule(month, dayOfMonth)));
\r
86 * Construct an object representing a holiday
\r
88 * @param month The month in which this holiday occurs (0-based)
\r
90 * @param dayOfMonth A date within the month (1-based). The
\r
91 * interpretation of this parameter depends on the value of
\r
92 * <code>dayOfWeek</code>.
\r
94 * @param dayOfWeek The day of the week on which this holiday occurs.
\r
95 * The following values are legal: <ul>
\r
96 * <li>dayOfWeek == 0 - use dayOfMonth only
\r
97 * <li>dayOfWeek < 0 - use last -dayOfWeek before or on dayOfMonth
\r
98 * <li>dayOfWeek > 0 - use first dayOfWeek after or on dayOfMonth
\r
101 * @param name The name of this holiday. This string is used as a key
\r
102 * to look up the holiday's name a resource bundle.
\r
103 * If the name is not found in the resource bundle,
\r
104 * getDisplayName will return this string instead.
\r
106 * @see Holiday#getDisplayName(java.util.Locale)
\r
108 * @provisional This API might change or be removed in a future release.
\r
110 public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name)
\r
112 super(name, new SimpleDateRule(month, dayOfMonth,
\r
113 dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
\r
119 * @provisional This API might change or be removed in a future release.
\r
121 public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name,
\r
124 super(name, rangeRule(startYear, 0,
\r
125 new SimpleDateRule(month, dayOfMonth,
\r
126 dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
\r
133 * @provisional This API might change or be removed in a future release.
\r
135 public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name,
\r
136 int startYear, int endYear)
\r
138 super(name, rangeRule(startYear, endYear,
\r
139 new SimpleDateRule(month, dayOfMonth,
\r
140 dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
\r
144 private static DateRule rangeRule(int startYear, int endYear, DateRule rule)
\r
146 if (startYear == 0 && endYear == 0) {
\r
150 RangeDateRule rangeRule = new RangeDateRule();
\r
152 if (startYear != 0) {
\r
153 Calendar start = new GregorianCalendar(startYear, Calendar.JANUARY, 1);
\r
154 rangeRule.add(start.getTime(), rule);
\r
156 rangeRule.add(rule);
\r
158 if (endYear != 0) {
\r
159 Date end = new GregorianCalendar(endYear, Calendar.DECEMBER, 31).getTime();
\r
160 rangeRule.add(end, null);
\r
166 /* Constants for holidays that are common throughout the Western
\r
167 * and Christian worlds.... */
\r
170 * New Year's Day - January 1st
\r
172 * @provisional This API might change or be removed in a future release.
\r
174 public static final SimpleHoliday NEW_YEARS_DAY =
\r
175 new SimpleHoliday(Calendar.JANUARY, 1, "New Year's Day");
\r
178 * Epiphany, January 6th
\r
180 * @provisional This API might change or be removed in a future release.
\r
182 public static final SimpleHoliday EPIPHANY =
\r
183 new SimpleHoliday(Calendar.JANUARY, 6, "Epiphany");
\r
188 * @provisional This API might change or be removed in a future release.
\r
190 public static final SimpleHoliday MAY_DAY =
\r
191 new SimpleHoliday(Calendar.MAY, 1, "May Day");
\r
194 * Assumption, August 15th
\r
196 * @provisional This API might change or be removed in a future release.
\r
198 public static final SimpleHoliday ASSUMPTION =
\r
199 new SimpleHoliday(Calendar.AUGUST, 15, "Assumption");
\r
202 * All Saints' Day, November 1st
\r
204 * @provisional This API might change or be removed in a future release.
\r
206 public static final SimpleHoliday ALL_SAINTS_DAY =
\r
207 new SimpleHoliday(Calendar.NOVEMBER, 1, "All Saints' Day");
\r
210 * All Souls' Day, November 1st
\r
212 * @provisional This API might change or be removed in a future release.
\r
214 public static final SimpleHoliday ALL_SOULS_DAY =
\r
215 new SimpleHoliday(Calendar.NOVEMBER, 2, "All Souls' Day");
\r
218 * Immaculate Conception, December 8th
\r
220 * @provisional This API might change or be removed in a future release.
\r
222 public static final SimpleHoliday IMMACULATE_CONCEPTION =
\r
223 new SimpleHoliday(Calendar.DECEMBER, 8, "Immaculate Conception");
\r
226 * Christmas Eve, December 24th
\r
228 * @provisional This API might change or be removed in a future release.
\r
230 public static final SimpleHoliday CHRISTMAS_EVE =
\r
231 new SimpleHoliday(Calendar.DECEMBER, 24, "Christmas Eve");
\r
234 * Christmas, December 25th
\r
236 * @provisional This API might change or be removed in a future release.
\r
238 public static final SimpleHoliday CHRISTMAS =
\r
239 new SimpleHoliday(Calendar.DECEMBER, 25, "Christmas");
\r
242 * Boxing Day, December 26th
\r
244 * @provisional This API might change or be removed in a future release.
\r
246 public static final SimpleHoliday BOXING_DAY =
\r
247 new SimpleHoliday(Calendar.DECEMBER, 26, "Boxing Day");
\r
250 * Saint Stephen's Day, December 26th
\r
252 * @provisional This API might change or be removed in a future release.
\r
254 public static final SimpleHoliday ST_STEPHENS_DAY =
\r
255 new SimpleHoliday(Calendar.DECEMBER, 26, "St. Stephen's Day");
\r
258 * New Year's Eve, December 31st
\r
260 * @provisional This API might change or be removed in a future release.
\r
262 public static final SimpleHoliday NEW_YEARS_EVE =
\r
263 new SimpleHoliday(Calendar.DECEMBER, 31, "New Year's Eve");
\r