2 *******************************************************************************
3 * Copyright (C) 1996-2011, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
8 package com.ibm.icu.util;
10 import java.util.Date;
11 import java.util.Locale;
12 import java.util.MissingResourceException;
13 import java.util.ResourceBundle;
15 import com.ibm.icu.util.ULocale.Category;
18 * <b>Note:</b> The Holiday framework is a technology preview.
19 * Despite its age, is still draft API, and clients should treat it as such.
21 * An abstract class representing a holiday.
22 * @draft ICU 2.8 (retainAll)
23 * @provisional This API might change or be removed in a future release.
25 public abstract class Holiday implements DateRule
29 * @provisional This API might change or be removed in a future release.
31 public static Holiday[] getHolidays()
33 return getHolidays(ULocale.getDefault(Category.FORMAT));
38 * @provisional This API might change or be removed in a future release.
40 public static Holiday[] getHolidays(Locale locale)
42 return getHolidays(ULocale.forLocale(locale));
47 * @provisional This API might change or be removed in a future release.
49 public static Holiday[] getHolidays(ULocale locale)
51 Holiday[] result = noHolidays;
54 ResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", locale);
56 result = (Holiday[]) bundle.getObject("holidays");
58 catch (MissingResourceException e) {
64 * Return the first occurrence of this holiday on or after the given date
66 * @param start Only holidays on or after this date are returned.
68 * @return The date on which this holiday occurs, or null if it
69 * does not occur on or after the start date.
73 * @provisional This API might change or be removed in a future release.
75 public Date firstAfter(Date start) {
76 return rule.firstAfter(start);
80 * Return the first occurrence of this holiday that is on or after
81 * the given start date and before the given end date.
83 * @param start Only occurrences on or after this date are returned.
84 * @param end Only occurrences before this date are returned.
86 * @return The date on which this event occurs, or null if it
87 * does not occur between the start and end dates.
91 * @provisional This API might change or be removed in a future release.
93 public Date firstBetween(Date start, Date end) {
94 return rule.firstBetween(start, end);
98 * Checks whether this holiday falls on the given date. This does
99 * <em>not</em> take time of day into account; instead it checks
100 * whether the holiday and the given date are on the same day.
102 * @param date The date to check.
103 * @return true if this holiday occurs on the given date.
105 * @provisional This API might change or be removed in a future release.
107 public boolean isOn(Date date) {
108 //System.out.println(name + ".isOn(" + date.toString() + "):");
109 return rule.isOn(date);
113 * Check whether this holiday occurs at least once between the two
116 * @provisional This API might change or be removed in a future release.
118 public boolean isBetween(Date start, Date end) {
119 return rule.isBetween(start, end);
123 * Construct a new Holiday object. This is for use by subclasses only.
124 * This constructs a new holiday with the given name and date rules.
126 * @param name The name of this holiday. The getDisplayName method
127 * uses this string as a key to look up the holiday's name a
128 * resource bundle object named HolidayBundle.
130 * @param rule The date rules used for determining when this holiday
131 * falls. Holiday's implementation of the DateRule interface
132 * simply delegates to this DateRule object.
134 * @provisional This API might change or be removed in a future release.
136 protected Holiday(String name, DateRule rule)
143 * Return the name of this holiday in the language of the default <code>DISPLAY</code> locale.
144 * @see Category#DISPLAY
146 * @provisional This API might change or be removed in a future release.
148 public String getDisplayName() {
149 return getDisplayName(ULocale.getDefault(Category.DISPLAY));
153 * Return the name of this holiday in the language of the specified locale.
154 * The <code>name</code> parameter passed to this object's constructor is used
155 * as a key to look up the holiday's localized name in a ResourceBundle object
156 * named HolidayBundle.
158 * @param locale A locale specifying the language in which the name is desired.
160 * @see ResourceBundle
162 * @provisional This API might change or be removed in a future release.
164 public String getDisplayName(Locale locale)
166 return getDisplayName(ULocale.forLocale(locale));
170 * Return the name of this holiday in the language of the specified locale
171 * The <code>name</code> parameter passed to this object's constructor is used
172 * as a key to look up the holiday's localized name in a ResourceBundle object
173 * named HolidayBundle.
175 * @param locale A locale specifying the language in which the name is desired.
177 * @see ResourceBundle
179 * @provisional This API might change or be removed in a future release.
181 public String getDisplayName(ULocale locale)
183 String dispName = name;
186 ResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", locale);
187 dispName = bundle.getString(name);
189 catch (MissingResourceException e) {
196 * @provisional This API might change or be removed in a future release.
198 public DateRule getRule() {
204 * @provisional This API might change or be removed in a future release.
206 public void setRule(DateRule rule) {
211 private DateRule rule;
213 private static Holiday[] noHolidays = {};