001: /*
002: *******************************************************************************
003: * Copyright (C) 1996-2006, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007:
008: package com.ibm.icu.util;
009:
010: import java.util.Date;
011: import com.ibm.icu.util.Calendar;
012: import com.ibm.icu.util.GregorianCalendar;
013:
014: /**
015: * A holiday whose date can be represented by a month, day, and optionally day of week
016: * in the Gregorian calendar.
017: *
018: * @draft ICU 2.8 (retainAll)
019: * @provisional This API might change or be removed in a future release.
020: */
021: public class SimpleHoliday extends Holiday {
022: /**
023: * Construct an object representing a holiday
024: *
025: * @param month The month in which this holiday occurs (0-based)
026: * @param dayOfMonth The date within the month (1-based).
027: *
028: * @param name The name of this holiday. This string is used as a key
029: * to look up the holiday's name a resource bundle.
030: * If the name is not found in the resource bundle,
031: * getDisplayName will return this string instead.
032: *
033: * @see Holiday#getDisplayName(java.util.Locale)
034: * @draft ICU 2.8
035: * @provisional This API might change or be removed in a future release.
036: */
037: public SimpleHoliday(int month, int dayOfMonth, String name) {
038: super (name, new SimpleDateRule(month, dayOfMonth));
039: }
040:
041: /**
042: * Construct an object representing a holiday
043: *
044: * @param month The month in which this holiday occurs (0-based)
045: * @param dayOfMonth The date within the month (1-based).
046: *
047: * @param name The name of this holiday. This string is used as a key
048: * to look up the holiday's name a resource bundle.
049: * If the name is not found in the resource bundle,
050: * getDisplayName will return this string instead.
051: *
052: * @see Holiday#getDisplayName(java.util.Locale)
053: * @draft ICU 2.8
054: * @provisional This API might change or be removed in a future release.
055: */
056: public SimpleHoliday(int month, int dayOfMonth, String name,
057: int startYear) {
058: super (name, rangeRule(startYear, 0, new SimpleDateRule(month,
059: dayOfMonth)));
060: }
061:
062: /**
063: * Construct an object representing a holiday
064: *
065: * @param month The month in which this holiday occurs (0-based)
066: * @param dayOfMonth The date within the month (1-based).
067: *
068: * @param name The name of this holiday. This string is used as a key
069: * to look up the holiday's name a resource bundle.
070: * If the name is not found in the resource bundle,
071: * getDisplayName will return this string instead.
072: *
073: * @see Holiday#getDisplayName(java.util.Locale)
074: * @draft ICU 2.8
075: * @provisional This API might change or be removed in a future release.
076: */
077: public SimpleHoliday(int month, int dayOfMonth, String name,
078: int startYear, int endYear) {
079: super (name, rangeRule(startYear, endYear, new SimpleDateRule(
080: month, dayOfMonth)));
081: }
082:
083: /** // TODO: remove
084: * Construct an object representing a holiday
085: *
086: * @param month The month in which this holiday occurs (0-based)
087: *
088: * @param dayOfMonth A date within the month (1-based). The
089: * interpretation of this parameter depends on the value of
090: * <code>dayOfWeek</code>.
091: *
092: * @param dayOfWeek The day of the week on which this holiday occurs.
093: * The following values are legal: <ul>
094: * <li>dayOfWeek == 0 - use dayOfMonth only
095: * <li>dayOfWeek < 0 - use last -dayOfWeek before or on dayOfMonth
096: * <li>dayOfWeek > 0 - use first dayOfWeek after or on dayOfMonth
097: * </ul>
098: *
099: * @param name The name of this holiday. This string is used as a key
100: * to look up the holiday's name a resource bundle.
101: * If the name is not found in the resource bundle,
102: * getDisplayName will return this string instead.
103: *
104: * @see Holiday#getDisplayName(java.util.Locale)
105: * @draft ICU 2.8
106: * @provisional This API might change or be removed in a future release.
107: */
108: public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek,
109: String name) {
110: super (name, new SimpleDateRule(month, dayOfMonth,
111: dayOfWeek > 0 ? dayOfWeek : -dayOfWeek, dayOfWeek > 0));
112: }
113:
114: /**
115: * @draft ICU 2.8
116: * @provisional This API might change or be removed in a future release.
117: */
118: public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek,
119: String name, int startYear) {
120: super (name, rangeRule(startYear, 0, new SimpleDateRule(month,
121: dayOfMonth, dayOfWeek > 0 ? dayOfWeek : -dayOfWeek,
122: dayOfWeek > 0)));
123: }
124:
125: /**
126: * @draft ICU 2.8
127: * @provisional This API might change or be removed in a future release.
128: */
129: public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek,
130: String name, int startYear, int endYear) {
131: super (name, rangeRule(startYear, endYear, new SimpleDateRule(
132: month, dayOfMonth, dayOfWeek > 0 ? dayOfWeek
133: : -dayOfWeek, dayOfWeek > 0)));
134: }
135:
136: private static DateRule rangeRule(int startYear, int endYear,
137: DateRule rule) {
138: if (startYear == 0 && endYear == 0) {
139: return rule;
140: }
141:
142: RangeDateRule rangeRule = new RangeDateRule();
143:
144: if (startYear != 0) {
145: Calendar start = new GregorianCalendar(startYear,
146: Calendar.JANUARY, 1);
147: rangeRule.add(start.getTime(), rule);
148: } else {
149: rangeRule.add(rule);
150: }
151: if (endYear != 0) {
152: Date end = new GregorianCalendar(endYear,
153: Calendar.DECEMBER, 31).getTime();
154: rangeRule.add(end, null);
155: }
156:
157: return rangeRule;
158: }
159:
160: /* Constants for holidays that are common throughout the Western
161: * and Christian worlds.... */
162:
163: /**
164: * New Year's Day - January 1st
165: * @draft ICU 2.8
166: * @provisional This API might change or be removed in a future release.
167: */
168: public static final SimpleHoliday NEW_YEARS_DAY = new SimpleHoliday(
169: Calendar.JANUARY, 1, "New Year's Day");
170:
171: /**
172: * Epiphany, January 6th
173: * @draft ICU 2.8
174: * @provisional This API might change or be removed in a future release.
175: */
176: public static final SimpleHoliday EPIPHANY = new SimpleHoliday(
177: Calendar.JANUARY, 6, "Epiphany");
178:
179: /**
180: * May Day, May 1st
181: * @draft ICU 2.8
182: * @provisional This API might change or be removed in a future release.
183: */
184: public static final SimpleHoliday MAY_DAY = new SimpleHoliday(
185: Calendar.MAY, 1, "May Day");
186:
187: /**
188: * Assumption, August 15th
189: * @draft ICU 2.8
190: * @provisional This API might change or be removed in a future release.
191: */
192: public static final SimpleHoliday ASSUMPTION = new SimpleHoliday(
193: Calendar.AUGUST, 15, "Assumption");
194:
195: /**
196: * All Saints' Day, November 1st
197: * @draft ICU 2.8
198: * @provisional This API might change or be removed in a future release.
199: */
200: public static final SimpleHoliday ALL_SAINTS_DAY = new SimpleHoliday(
201: Calendar.NOVEMBER, 1, "All Saints' Day");
202:
203: /**
204: * All Souls' Day, November 1st
205: * @draft ICU 2.8
206: * @provisional This API might change or be removed in a future release.
207: */
208: public static final SimpleHoliday ALL_SOULS_DAY = new SimpleHoliday(
209: Calendar.NOVEMBER, 2, "All Souls' Day");
210:
211: /**
212: * Immaculate Conception, December 8th
213: * @draft ICU 2.8
214: * @provisional This API might change or be removed in a future release.
215: */
216: public static final SimpleHoliday IMMACULATE_CONCEPTION = new SimpleHoliday(
217: Calendar.DECEMBER, 8, "Immaculate Conception");
218:
219: /**
220: * Christmas Eve, December 24th
221: * @draft ICU 2.8
222: * @provisional This API might change or be removed in a future release.
223: */
224: public static final SimpleHoliday CHRISTMAS_EVE = new SimpleHoliday(
225: Calendar.DECEMBER, 24, "Christmas Eve");
226:
227: /**
228: * Christmas, December 25th
229: * @draft ICU 2.8
230: * @provisional This API might change or be removed in a future release.
231: */
232: public static final SimpleHoliday CHRISTMAS = new SimpleHoliday(
233: Calendar.DECEMBER, 25, "Christmas");
234:
235: /**
236: * Boxing Day, December 26th
237: * @draft ICU 2.8
238: * @provisional This API might change or be removed in a future release.
239: */
240: public static final SimpleHoliday BOXING_DAY = new SimpleHoliday(
241: Calendar.DECEMBER, 26, "Boxing Day");
242:
243: /**
244: * Saint Stephen's Day, December 26th
245: * @draft ICU 2.8
246: * @provisional This API might change or be removed in a future release.
247: */
248: public static final SimpleHoliday ST_STEPHENS_DAY = new SimpleHoliday(
249: Calendar.DECEMBER, 26, "St. Stephen's Day");
250:
251: /**
252: * New Year's Eve, December 31st
253: * @draft ICU 2.8
254: * @provisional This API might change or be removed in a future release.
255: */
256: public static final SimpleHoliday NEW_YEARS_EVE = new SimpleHoliday(
257: Calendar.DECEMBER, 31, "New Year's Eve");
258:
259: }
|