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