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