Initial isWeekend etc implementation, data, and test, with temporary API

X-SVN-Rev: 945
This commit is contained in:
Alan Liu 2000-03-14 18:09:36 +00:00
parent c2c02cd525
commit 67173452de
33 changed files with 1105 additions and 2 deletions

View File

@ -0,0 +1,129 @@
/*
*******************************************************************************
* Copyright (C) 2000, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/calendar/IBMCalendarTest.java,v $
* $Date: 2000/03/14 18:09:36 $
* $Revision: 1.1 $
*******************************************************************************
*/
package com.ibm.test.calendar;
import com.ibm.test.TestFmwk;
import com.ibm.util.*;
import java.text.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* @test
* @summary Tests of new functionality in IBMCalendar
*/
public class IBMCalendarTest extends TestFmwk {
public static void main(String[] args) throws Exception {
new IBMCalendarTest().run(args);
}
/**
* Test weekend support in IBMCalendar.
*
* NOTE: This test will have to be updated when the isWeekend() etc.
* API is finalized later.
*
* In particular, the test will have to be rewritten to instantiate
* a Calendar in the given locale (using getInstance()) and call
* that Calendar's isWeekend() etc. methods.
*/
public void TestWeekend() {
SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd yyyy G HH:mm:ss.SSS");
// NOTE
// This test tests for specific locale data. This is probably okay
// as far as US data is concerned, but if the Arabic/Bahrain data
// changes, this test will have to be updated.
// Test specific days
Object[] DATA1 = {
Locale.US, new int[] { // Saturday:Sunday
2000, Calendar.MARCH, 17, 23, 0, 0, // Fri 23:00
2000, Calendar.MARCH, 18, 0, -1, 0, // Fri 23:59:59.999
2000, Calendar.MARCH, 18, 0, 0, 1, // Sat 00:00
2000, Calendar.MARCH, 18, 15, 0, 1, // Sat 15:00
2000, Calendar.MARCH, 19, 23, 0, 1, // Sun 23:00
2000, Calendar.MARCH, 20, 0, -1, 1, // Sun 23:59:59.999
2000, Calendar.MARCH, 20, 0, 0, 0, // Mon 00:00
2000, Calendar.MARCH, 20, 8, 0, 0, // Mon 08:00
},
new Locale("ar", "BH"), new int[] { // Thursday:Friday
2000, Calendar.MARCH, 15, 23, 0, 0, // Wed 23:00
2000, Calendar.MARCH, 16, 0, -1, 0, // Wed 23:59:59.999
2000, Calendar.MARCH, 16, 0, 0, 1, // Thu 00:00
2000, Calendar.MARCH, 16, 15, 0, 1, // Thu 15:00
2000, Calendar.MARCH, 17, 23, 0, 1, // Fri 23:00
2000, Calendar.MARCH, 18, 0, -1, 1, // Fri 23:59:59.999
2000, Calendar.MARCH, 18, 0, 0, 0, // Sat 00:00
2000, Calendar.MARCH, 18, 8, 0, 0, // Sat 08:00
},
};
// Test days of the week
Object[] DATA2 = {
Locale.US, new int[] {
Calendar.MONDAY, IBMCalendar.WEEKDAY,
Calendar.FRIDAY, IBMCalendar.WEEKDAY,
Calendar.SATURDAY, IBMCalendar.WEEKEND,
Calendar.SUNDAY, IBMCalendar.WEEKEND,
},
new Locale("ar", "BH"), new int[] { // Thursday:Friday
Calendar.WEDNESDAY,IBMCalendar.WEEKDAY,
Calendar.SATURDAY, IBMCalendar.WEEKDAY,
Calendar.THURSDAY, IBMCalendar.WEEKEND,
Calendar.FRIDAY, IBMCalendar.WEEKEND,
},
};
// We only test the getDayOfWeekType() and isWeekend() APIs.
// The getWeekendTransition() API is tested indirectly via the
// isWeekend() API, which calls it.
for (int i1=0; i1<DATA1.length; i1+=2) {
Locale loc = (Locale)DATA1[i1];
int[] data = (int[]) DATA1[i1+1];
Calendar cal = Calendar.getInstance(loc);
logln("Locale: " + loc);
for (int i=0; i<data.length; i+=6) {
cal.clear();
cal.set(data[i], data[i+1], data[i+2], data[i+3], 0, 0);
if (data[i+4] != 0) {
cal.setTime(new Date(cal.getTime().getTime() + data[i+4]));
}
boolean isWeekend = IBMCalendar.isWeekend(loc, cal.getTime());
boolean ok = isWeekend == (data[i+5] != 0);
if (ok) {
logln("Ok: " + fmt.format(cal.getTime()) + " isWeekend=" + isWeekend);
} else {
errln("FAIL: " + fmt.format(cal.getTime()) + " isWeekend=" + isWeekend +
", expected=" + (!isWeekend));
}
}
}
for (int i2=0; i2<DATA2.length; i2+=2) {
Locale loc = (Locale)DATA2[i2];
int[] data = (int[]) DATA2[i2+1];
logln("Locale: " + loc);
for (int i=0; i<data.length; i+=2) {
int type = IBMCalendar.getDayOfWeekType(loc, data[i]);
int exp = data[i+1];
if (type == exp) {
logln("Ok: DOW " + data[i] + " type=" + type);
} else {
errln("FAIL: DOW " + data[i] + " type=" + type +
", expected=" + exp);
}
}
}
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Default
public class CalendarData extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Saturday:Sunday
"7", "0", // onset dow, millis in day
"2", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, United Arab Emirates
public class CalendarData_ar_AE extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Bahrain
public class CalendarData_ar_BH extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Algeria
public class CalendarData_ar_DZ extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Egypt
public class CalendarData_ar_EG extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Friday:Saturday
"6", "0", // onset dow, millis in day
"1", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Jordan
public class CalendarData_ar_JO extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Kuwait
public class CalendarData_ar_KW extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Oman
public class CalendarData_ar_OM extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Qatar
public class CalendarData_ar_QA extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Saudi Arabia
public class CalendarData_ar_SA extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Syria
public class CalendarData_ar_SY extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Friday:Saturday
"6", "0", // onset dow, millis in day
"1", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Yemen
public class CalendarData_ar_YE extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Hebrew, Israel
public class CalendarData_iw_IL extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Friday:Saturday
"6", "0", // onset dow, millis in day
"1", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Bahasa Malaysia, Malaysia
public class CalendarData_ms_MY extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Saturday - half day in some offices:Sunday
"", "0", // onset dow, millis in day
"", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Telugu, India
public class CalendarData_te_IN extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Sunday
"1", "0", // onset dow, millis in day
"2", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,129 @@
/*
*******************************************************************************
* Copyright (C) 2000, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/test/calendar/Attic/IBMCalendarTest.java,v $
* $Date: 2000/03/14 18:09:36 $
* $Revision: 1.1 $
*******************************************************************************
*/
package com.ibm.test.calendar;
import com.ibm.test.TestFmwk;
import com.ibm.util.*;
import java.text.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* @test
* @summary Tests of new functionality in IBMCalendar
*/
public class IBMCalendarTest extends TestFmwk {
public static void main(String[] args) throws Exception {
new IBMCalendarTest().run(args);
}
/**
* Test weekend support in IBMCalendar.
*
* NOTE: This test will have to be updated when the isWeekend() etc.
* API is finalized later.
*
* In particular, the test will have to be rewritten to instantiate
* a Calendar in the given locale (using getInstance()) and call
* that Calendar's isWeekend() etc. methods.
*/
public void TestWeekend() {
SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd yyyy G HH:mm:ss.SSS");
// NOTE
// This test tests for specific locale data. This is probably okay
// as far as US data is concerned, but if the Arabic/Bahrain data
// changes, this test will have to be updated.
// Test specific days
Object[] DATA1 = {
Locale.US, new int[] { // Saturday:Sunday
2000, Calendar.MARCH, 17, 23, 0, 0, // Fri 23:00
2000, Calendar.MARCH, 18, 0, -1, 0, // Fri 23:59:59.999
2000, Calendar.MARCH, 18, 0, 0, 1, // Sat 00:00
2000, Calendar.MARCH, 18, 15, 0, 1, // Sat 15:00
2000, Calendar.MARCH, 19, 23, 0, 1, // Sun 23:00
2000, Calendar.MARCH, 20, 0, -1, 1, // Sun 23:59:59.999
2000, Calendar.MARCH, 20, 0, 0, 0, // Mon 00:00
2000, Calendar.MARCH, 20, 8, 0, 0, // Mon 08:00
},
new Locale("ar", "BH"), new int[] { // Thursday:Friday
2000, Calendar.MARCH, 15, 23, 0, 0, // Wed 23:00
2000, Calendar.MARCH, 16, 0, -1, 0, // Wed 23:59:59.999
2000, Calendar.MARCH, 16, 0, 0, 1, // Thu 00:00
2000, Calendar.MARCH, 16, 15, 0, 1, // Thu 15:00
2000, Calendar.MARCH, 17, 23, 0, 1, // Fri 23:00
2000, Calendar.MARCH, 18, 0, -1, 1, // Fri 23:59:59.999
2000, Calendar.MARCH, 18, 0, 0, 0, // Sat 00:00
2000, Calendar.MARCH, 18, 8, 0, 0, // Sat 08:00
},
};
// Test days of the week
Object[] DATA2 = {
Locale.US, new int[] {
Calendar.MONDAY, IBMCalendar.WEEKDAY,
Calendar.FRIDAY, IBMCalendar.WEEKDAY,
Calendar.SATURDAY, IBMCalendar.WEEKEND,
Calendar.SUNDAY, IBMCalendar.WEEKEND,
},
new Locale("ar", "BH"), new int[] { // Thursday:Friday
Calendar.WEDNESDAY,IBMCalendar.WEEKDAY,
Calendar.SATURDAY, IBMCalendar.WEEKDAY,
Calendar.THURSDAY, IBMCalendar.WEEKEND,
Calendar.FRIDAY, IBMCalendar.WEEKEND,
},
};
// We only test the getDayOfWeekType() and isWeekend() APIs.
// The getWeekendTransition() API is tested indirectly via the
// isWeekend() API, which calls it.
for (int i1=0; i1<DATA1.length; i1+=2) {
Locale loc = (Locale)DATA1[i1];
int[] data = (int[]) DATA1[i1+1];
Calendar cal = Calendar.getInstance(loc);
logln("Locale: " + loc);
for (int i=0; i<data.length; i+=6) {
cal.clear();
cal.set(data[i], data[i+1], data[i+2], data[i+3], 0, 0);
if (data[i+4] != 0) {
cal.setTime(new Date(cal.getTime().getTime() + data[i+4]));
}
boolean isWeekend = IBMCalendar.isWeekend(loc, cal.getTime());
boolean ok = isWeekend == (data[i+5] != 0);
if (ok) {
logln("Ok: " + fmt.format(cal.getTime()) + " isWeekend=" + isWeekend);
} else {
errln("FAIL: " + fmt.format(cal.getTime()) + " isWeekend=" + isWeekend +
", expected=" + (!isWeekend));
}
}
}
for (int i2=0; i2<DATA2.length; i2+=2) {
Locale loc = (Locale)DATA2[i2];
int[] data = (int[]) DATA2[i2+1];
logln("Locale: " + loc);
for (int i=0; i<data.length; i+=2) {
int type = IBMCalendar.getDayOfWeekType(loc, data[i]);
int exp = data[i+1];
if (type == exp) {
logln("Ok: DOW " + data[i] + " type=" + type);
} else {
errln("FAIL: DOW " + data[i] + " type=" + type +
", expected=" + exp);
}
}
}
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/util/Attic/IBMCalendar.java,v $
* $Date: 2000/03/10 04:17:58 $
* $Revision: 1.5 $
* $Date: 2000/03/14 18:07:42 $
* $Revision: 1.6 $
*
*****************************************************************************************
*/
@ -99,6 +99,32 @@ import com.ibm.text.SimpleDateFormat;
*/
public abstract class IBMCalendar extends java.util.Calendar {
/**
* Value returned by getDayOfWeekType(int dayOfWeek) to indicate a
* weekday.
*/
public static final int WEEKDAY = 0;
/**
* Value returned by getDayOfWeekType(int dayOfWeek) to indicate a
* weekend day.
*/
public static final int WEEKEND = 1;
/**
* Value returned by getDayOfWeekType(int dayOfWeek) to indicate a
* day that starts as a weekday and transitions to the weekend.
* Call getWeekendTransition() to get the point of transition.
*/
public static final int WEEKEND_ONSET = 2;
/**
* Value returned by getDayOfWeekType(int dayOfWeek) to indicate a
* day that starts as the weekend and transitions to a weekday.
* Call getWeekendTransition() to get the point of transition.
*/
public static final int WEEKEND_CEASE = 3;
private static String copyright = "Copyright \u00a9 1997-1998 IBM Corp. All Rights Reserved.";
protected IBMCalendar(TimeZone zone, Locale aLocale) {
@ -1229,6 +1255,255 @@ public abstract class IBMCalendar extends java.util.Calendar {
return result;
}
//-------------------------------------------------------------------------
// Weekend support -- determining which days of the week are the weekend
// in a given locale
//
// THIS SECTION IS WORK IN PROGRESS -- ANY CODE USING IT WILL HAVE TO BE
// CHANGED IN THE FUTURE.
//-------------------------------------------------------------------------
/**
* Single cached Weekend object; improves performance.
*/
private static Weekend cachedWeekend = null;
/**
* TEMPORARY API AND IMPLEMENTATION
*
* Return whether the given day of the week is a weekday, a
* weekend day, or a day that transitions from one to the other,
* in this calendar system. If a transition occurs at midnight,
* then the days before and after the transition will have the
* type WEEKDAY or WEEKEND. If a transition occurs at a time
* other than midnight, then the day of the transition will have
* the type WEEKEND_ONSET or WEEKEND_CEASE. In this case, the
* method getWeekendTransition() will return the point of
* transition.
* @param dayOfWeek either SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
* THURSDAY, FRIDAY, or SATURDAY
* @return either WEEKDAY, WEEKEND, WEEKEND_ONSET, or
* WEEKEND_CEASE
* @exception IllegalArgumentException if dayOfWeek is not
* between SUNDAY and SATURDAY, inclusive
*/
public static int getDayOfWeekType(Locale loc, int dayOfWeek) {
if (cachedWeekend == null ||
cachedWeekend.getLocale() != loc) {
cachedWeekend = new Weekend(loc);
}
return cachedWeekend.getDayOfWeekType(dayOfWeek);
}
/**
* TEMPORARY API AND IMPLEMENTATION
*
* Return the time during the day at which the weekend begins in
* this calendar system, if getDayOfWeekType(dayOfWeek) ==
* WEEKEND_ONSET, or at which the weekend ends, if
* getDayOfWeekType(dayOfWeek) == WEEKEND_CEASE. If
* getDayOfWeekType(dayOfWeek) has some other value, then an
* exception is thrown.
* @param dayOfWeek either SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
* THURSDAY, FRIDAY, or SATURDAY
* @return the milliseconds after midnight at which the
* weekend begins or ends
* @exception IllegalArgumentException if dayOfWeek is not
* WEEKEND_ONSET or WEEKEND_CEASE
*/
public static int getWeekendTransition(Locale loc, int dayOfWeek) {
if (cachedWeekend == null ||
cachedWeekend.getLocale() != loc) {
cachedWeekend = new Weekend(loc);
}
return cachedWeekend.getWeekendTransition(dayOfWeek);
}
/**
* TEMPORARY API AND IMPLEMENTATION
*
* Return true if the given date and time is in the weekend in
* this calendar system. Equivalent to calling setTime() followed
* by isWeekend(). Note: This method changes the time this
* calendar is set to.
* @param date the date and time
* @return true if the given date and time is part of the
* weekend
*/
public static boolean isWeekend(Locale loc, Date date) {
if (cachedWeekend == null ||
cachedWeekend.getLocale() != loc) {
cachedWeekend = new Weekend(loc);
}
return cachedWeekend.isWeekend(date);
}
/**
* ********************** TEMPORARY **************************************
*
* Wrapper for temporary implementation. In the future, these methods and
* fields will migrate to the IBM Calendar class itself. This is not
* done at this point because the hierarchy is currently in flux.
*
* ********************** TEMPORARY **************************************
*/
static class Weekend {
Locale loc;
Calendar cal;
int weekendOnset;
int weekendOnsetMillis;
int weekendCease;
int weekendCeaseMillis;
public Weekend(Locale loc, Calendar cal) {
loadWeekendData(loc);
this.loc = loc;
this.cal = cal;
}
public Weekend(Locale loc) {
this(loc, null);
}
public Weekend() {
this(Locale.getDefault(), null);
}
public Locale getLocale() {
return loc;
}
/**
* Read the locale weekend data for the given locale.
*
* This is the initial placement and format of this data -- it may very
* well change in the future. See the locale files themselves for
* details.
*/
private void loadWeekendData(Locale loc) {
ResourceBundle resource =
ResourceBundle.getBundle("com.ibm.util.resources.CalendarData",
loc);
String[] data = resource.getStringArray("Weekend");
weekendOnset = Integer.parseInt(data[0]);
weekendOnsetMillis = Integer.parseInt(data[1]);
weekendCease = Integer.parseInt(data[2]);
weekendCeaseMillis = Integer.parseInt(data[3]);
}
/**
* Return whether the given day of the week is a weekday, a
* weekend day, or a day that transitions from one to the other,
* in this calendar system. If a transition occurs at midnight,
* then the days before and after the transition will have the
* type WEEKDAY or WEEKEND. If a transition occurs at a time
* other than midnight, then the day of the transition will have
* the type WEEKEND_ONSET or WEEKEND_CEASE. In this case, the
* method getWeekendTransition() will return the point of
* transition.
* @param dayOfWeek either SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
* THURSDAY, FRIDAY, or SATURDAY
* @return either WEEKDAY, WEEKEND, WEEKEND_ONSET, or
* WEEKEND_CEASE
* @exception IllegalArgumentException if dayOfWeek is not
* between SUNDAY and SATURDAY, inclusive
*/
public int getDayOfWeekType(int dayOfWeek) {
if (dayOfWeek < SUNDAY || dayOfWeek > SATURDAY) {
throw new IllegalArgumentException("Invalid day of week");
}
if (weekendOnset < weekendCease) {
if (dayOfWeek < weekendOnset || dayOfWeek > weekendCease) {
return WEEKDAY;
}
} else {
if (dayOfWeek > weekendCease && dayOfWeek < weekendOnset) {
return WEEKDAY;
}
}
if (dayOfWeek == weekendOnset) {
return (weekendOnsetMillis == 0) ? WEEKEND : WEEKEND_ONSET;
}
if (dayOfWeek == weekendCease) {
return (weekendCeaseMillis == 0) ? WEEKDAY : WEEKEND_CEASE;
}
return WEEKEND;
}
/**
* Return the time during the day at which the weekend begins in
* this calendar system, if getDayOfWeekType(dayOfWeek) ==
* WEEKEND_ONSET, or at which the weekend ends, if
* getDayOfWeekType(dayOfWeek) == WEEKEND_CEASE. If
* getDayOfWeekType(dayOfWeek) has some other value, then an
* exception is thrown.
* @param dayOfWeek either SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
* THURSDAY, FRIDAY, or SATURDAY
* @return the milliseconds after midnight at which the
* weekend begins or ends
* @exception IllegalArgumentException if dayOfWeek is not
* WEEKEND_ONSET or WEEKEND_CEASE
*/
public int getWeekendTransition(int dayOfWeek) {
if (dayOfWeek == weekendOnset) {
return weekendOnsetMillis;
} else if (dayOfWeek == weekendCease) {
return weekendCeaseMillis;
}
throw new IllegalArgumentException("Not weekend transition day");
}
/**
* Return true if the given date and time is in the weekend in
* this calendar system. Equivalent to calling setTime() followed
* by isWeekend(). Note: This method changes the time this
* calendar is set to.
* @param date the date and time
* @return true if the given date and time is part of the
* weekend
*/
public boolean isWeekend(Date date) {
if (cal == null) {
cal = Calendar.getInstance(loc);
}
cal.setTime(date);
return isWeekend();
}
/**
* Return true if this Calendar's current date and time is in the
* weekend in this calendar system.
* @return true if the given date and time is part of the
* weekend
*/
public boolean isWeekend() {
if (cal == null) {
cal = Calendar.getInstance(loc);
}
int dow = cal.get(DAY_OF_WEEK);
int dowt = getDayOfWeekType(dow);
switch (dowt) {
case WEEKDAY:
return false;
case WEEKEND:
return true;
default: // That is, WEEKEND_ONSET or WEEKEND_CEASE
// Use internalGet() because the above call to get() populated
// all fields.
// [Note: There should be a better way to get millis in day.
// For ICU4J, submit request for a MILLIS_IN_DAY field
// and a DAY_NUMBER field (could be Julian day #). - aliu]
int millisInDay = cal.get(MILLISECOND) + 1000 * (cal.get(SECOND) +
60 * (cal.get(MINUTE) + 60 * cal.get(HOUR_OF_DAY)));
int transition = getWeekendTransition(dow);
return (dowt == WEEKEND_ONSET)
? (millisInDay >= transition)
: (millisInDay < transition);
}
// (We can never reach this point.)
}
}
//-------------------------------------------------------------------------
// Protected utility methods for use by subclasses. These are very handy

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Default
public class CalendarData extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Saturday:Sunday
"7", "0", // onset dow, millis in day
"2", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, United Arab Emirates
public class CalendarData_ar_AE extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Bahrain
public class CalendarData_ar_BH extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Algeria
public class CalendarData_ar_DZ extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Egypt
public class CalendarData_ar_EG extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Friday:Saturday
"6", "0", // onset dow, millis in day
"1", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Jordan
public class CalendarData_ar_JO extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Kuwait
public class CalendarData_ar_KW extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Oman
public class CalendarData_ar_OM extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Qatar
public class CalendarData_ar_QA extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Saudi Arabia
public class CalendarData_ar_SA extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Syria
public class CalendarData_ar_SY extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Friday:Saturday
"6", "0", // onset dow, millis in day
"1", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Arabic, Yemen
public class CalendarData_ar_YE extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Thursday:Friday
"5", "0", // onset dow, millis in day
"7", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Hebrew, Israel
public class CalendarData_iw_IL extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Friday:Saturday
"6", "0", // onset dow, millis in day
"1", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Bahasa Malaysia, Malaysia
public class CalendarData_ms_MY extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Saturday - half day in some offices:Sunday
"", "0", // onset dow, millis in day
"", "0" // cease dow, millis in day
}
},
};
}
}

View File

@ -0,0 +1,19 @@
package com.ibm.util.resources;
import java.util.ListResourceBundle;
// Telugu, India
public class CalendarData_te_IN extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return new Object[][] {
{ "Weekend",
new String[] { // Sunday
"1", "0", // onset dow, millis in day
"2", "0" // cease dow, millis in day
}
},
};
}
}