]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/util/SimpleHoliday.java
Added flags.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / util / SimpleHoliday.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 1996-2010, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7
8 package com.ibm.icu.util;
9
10 import java.util.Date;
11
12 /**
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.
15  * 
16  * A holiday whose date can be represented by a month, day, and optionally day of week
17  * in the Gregorian calendar.
18  *
19  * @draft ICU 2.8 (retainAll)
20  * @provisional This API might change or be removed in a future release.
21  */
22 public class SimpleHoliday extends Holiday {
23     /**
24      * Construct an object representing a holiday
25      *
26      * @param month         The month in which this holiday occurs (0-based)
27      * @param dayOfMonth    The date within the month (1-based).
28      *
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.
33      *
34      * @see Holiday#getDisplayName(java.util.Locale)
35      * @draft ICU 2.8
36      * @provisional This API might change or be removed in a future release.
37      */
38     public SimpleHoliday(int month, int dayOfMonth, String name)
39     {
40         super(name, new SimpleDateRule(month, dayOfMonth));
41     }
42
43     /**
44      * Construct an object representing a holiday
45      *
46      * @param month         The month in which this holiday occurs (0-based)
47      * @param dayOfMonth    The date within the month (1-based).
48      *
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.
53      *
54      * @see Holiday#getDisplayName(java.util.Locale)
55      * @draft ICU 2.8
56      * @provisional This API might change or be removed in a future release.
57      */
58     public SimpleHoliday(int month, int dayOfMonth, String name,
59                             int startYear)
60     {
61         super(name, rangeRule(startYear, 0, new SimpleDateRule(month, dayOfMonth)));
62     }
63
64     /**
65      * Construct an object representing a holiday
66      *
67      * @param month         The month in which this holiday occurs (0-based)
68      * @param dayOfMonth    The date within the month (1-based).
69      *
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.
74      *
75      * @see Holiday#getDisplayName(java.util.Locale)
76      * @draft ICU 2.8
77      * @provisional This API might change or be removed in a future release.
78      */
79     public SimpleHoliday(int month, int dayOfMonth, String name,
80                             int startYear, int endYear)
81     {
82         super(name, rangeRule(startYear, endYear, new SimpleDateRule(month, dayOfMonth)));
83     }
84
85     /** // TODO: remove
86      * Construct an object representing a holiday
87      *
88      * @param month The month in which this holiday occurs (0-based)
89      *
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>.
93      *
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
99      *      </ul>
100      *
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.
105      *
106      * @see Holiday#getDisplayName(java.util.Locale)
107      * @draft ICU 2.8
108      * @provisional This API might change or be removed in a future release.
109      */
110     public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name)
111     {
112         super(name, new SimpleDateRule(month, dayOfMonth,
113                                         dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
114                                         dayOfWeek > 0));
115     }
116
117     /**
118      * @draft ICU 2.8
119      * @provisional This API might change or be removed in a future release.
120      */
121     public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name,
122                         int startYear)
123     {
124         super(name, rangeRule(startYear, 0, 
125                               new SimpleDateRule(month, dayOfMonth,
126                                                  dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
127                                                  dayOfWeek > 0)));
128     }
129
130
131     /**
132      * @draft ICU 2.8
133      * @provisional This API might change or be removed in a future release.
134      */
135     public SimpleHoliday(int month, int dayOfMonth, int dayOfWeek, String name,
136                         int startYear, int endYear)
137     {
138         super(name, rangeRule(startYear, endYear, 
139                               new SimpleDateRule(month, dayOfMonth,
140                                                  dayOfWeek > 0 ? dayOfWeek : - dayOfWeek,
141                                                  dayOfWeek > 0)));
142     }
143
144     private static DateRule rangeRule(int startYear, int endYear, DateRule rule)
145     {
146         if (startYear == 0 && endYear == 0) {
147             return rule;
148         }
149
150         RangeDateRule rangeRule = new RangeDateRule();
151
152         if (startYear != 0) {
153             Calendar start = new GregorianCalendar(startYear, Calendar.JANUARY, 1);
154             rangeRule.add(start.getTime(), rule);
155         } else {
156             rangeRule.add(rule);
157         }
158         if (endYear != 0) {
159             Date end = new GregorianCalendar(endYear, Calendar.DECEMBER, 31).getTime();
160             rangeRule.add(end, null);
161         }
162
163         return rangeRule;
164     }
165
166     /* Constants for holidays that are common throughout the Western
167      * and Christian worlds.... */
168
169     /**
170      * New Year's Day - January 1st
171      * @draft ICU 2.8
172      * @provisional This API might change or be removed in a future release.
173      */
174     public static final SimpleHoliday NEW_YEARS_DAY =
175         new SimpleHoliday(Calendar.JANUARY,    1,  "New Year's Day");
176
177     /**
178      * Epiphany, January 6th
179      * @draft ICU 2.8
180      * @provisional This API might change or be removed in a future release.
181      */
182     public static final SimpleHoliday EPIPHANY =
183         new SimpleHoliday(Calendar.JANUARY,    6,  "Epiphany");
184
185     /**
186      * May Day, May 1st
187      * @draft ICU 2.8
188      * @provisional This API might change or be removed in a future release.
189      */
190     public static final SimpleHoliday MAY_DAY =
191         new SimpleHoliday(Calendar.MAY,        1,  "May Day");
192
193     /**
194      * Assumption, August 15th
195      * @draft ICU 2.8
196      * @provisional This API might change or be removed in a future release.
197      */
198     public static final SimpleHoliday ASSUMPTION =
199         new SimpleHoliday(Calendar.AUGUST,    15,  "Assumption");
200
201     /**
202      * All Saints' Day, November 1st
203      * @draft ICU 2.8
204      * @provisional This API might change or be removed in a future release.
205      */
206     public static final SimpleHoliday ALL_SAINTS_DAY =
207         new SimpleHoliday(Calendar.NOVEMBER,   1,  "All Saints' Day");
208
209     /**
210      * All Souls' Day, November 1st
211      * @draft ICU 2.8
212      * @provisional This API might change or be removed in a future release.
213      */
214     public static final SimpleHoliday ALL_SOULS_DAY =
215         new SimpleHoliday(Calendar.NOVEMBER,   2,  "All Souls' Day");
216
217     /**
218      * Immaculate Conception, December 8th
219      * @draft ICU 2.8
220      * @provisional This API might change or be removed in a future release.
221      */
222     public static final SimpleHoliday IMMACULATE_CONCEPTION =
223         new SimpleHoliday(Calendar.DECEMBER,   8,  "Immaculate Conception");
224
225     /**
226      * Christmas Eve, December 24th
227      * @draft ICU 2.8
228      * @provisional This API might change or be removed in a future release.
229      */
230     public static final SimpleHoliday CHRISTMAS_EVE =
231         new SimpleHoliday(Calendar.DECEMBER,  24,  "Christmas Eve");
232
233     /**
234      * Christmas, December 25th
235      * @draft ICU 2.8
236      * @provisional This API might change or be removed in a future release.
237      */
238     public static final SimpleHoliday CHRISTMAS =
239         new SimpleHoliday(Calendar.DECEMBER,  25,  "Christmas");
240
241     /**
242      * Boxing Day, December 26th
243      * @draft ICU 2.8
244      * @provisional This API might change or be removed in a future release.
245      */
246     public static final SimpleHoliday BOXING_DAY =
247         new SimpleHoliday(Calendar.DECEMBER,  26,  "Boxing Day");
248
249     /**
250      * Saint Stephen's Day, December 26th
251      * @draft ICU 2.8
252      * @provisional This API might change or be removed in a future release.
253      */
254     public static final SimpleHoliday ST_STEPHENS_DAY =
255         new SimpleHoliday(Calendar.DECEMBER,  26,  "St. Stephen's Day");
256
257     /**
258      * New Year's Eve, December 31st
259      * @draft ICU 2.8
260      * @provisional This API might change or be removed in a future release.
261      */
262     public static final SimpleHoliday NEW_YEARS_EVE =
263         new SimpleHoliday(Calendar.DECEMBER,  31,  "New Year's Eve");
264
265 }