use of android.icu.util.TimeZone in project j2objc by google.
the class CalendarRegressionTest method Test4288792.
/**
* WEEK_OF_YEAR computed incorrectly. A failure of this test can indicate a problem in several different places in
* the
*/
@Test
public void Test4288792() throws Exception {
TimeZone savedTZ = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
GregorianCalendar cal = new GregorianCalendar();
for (int i = 1900; i < 2100; i++) {
for (int j1 = 1; j1 <= 7; j1++) {
// Loop for MinimalDaysInFirstWeek: 1..7
for (int j = Calendar.SUNDAY; j <= Calendar.SATURDAY; j++) {
// Loop for FirstDayOfWeek: SUNDAY..SATURDAY
cal.clear();
cal.setMinimalDaysInFirstWeek(j1);
cal.setFirstDayOfWeek(j);
// Set the calendar to the first day of the last week
// of the year. This may overlap some of the start of
// the next year; that is, the last week of 1999 may
// include some of January 2000. Use the add() method
// to advance through the week. For each day, call
// get(WEEK_OF_YEAR). The result should be the same
// for the whole week. Note that a bug in
// getActualMaximum() will break this test.
// Set date to the mid year first before getActualMaximum(WEEK_OF_YEAR).
// getActualMaximum(WEEK_OF_YEAR) is based on the current calendar's
// year of week of year. After clear(), calendar is set to January 1st,
// which may belongs to previous year of week of year.
cal.set(i, Calendar.JULY, 1);
int maxWeek = cal.getActualMaximum(Calendar.WEEK_OF_YEAR);
cal.set(Calendar.WEEK_OF_YEAR, maxWeek);
cal.set(Calendar.DAY_OF_WEEK, j);
for (int k = 1; k < 7; k++) {
cal.add(Calendar.DATE, 1);
int WOY = cal.get(Calendar.WEEK_OF_YEAR);
if (WOY != maxWeek) {
errln(cal.getTime() + ",got=" + WOY + ",expected=" + maxWeek + ",min=" + j1 + ",first=" + j);
}
}
// Now advance the calendar one more day. This should
// put it at the first day of week 1 of the next year.
cal.add(Calendar.DATE, 1);
int WOY = cal.get(Calendar.WEEK_OF_YEAR);
if (WOY != 1) {
errln(cal.getTime() + ",got=" + WOY + ",expected=1,min=" + j1 + ",first" + j);
}
}
}
}
TimeZone.setDefault(savedTZ);
}
use of android.icu.util.TimeZone in project j2objc by google.
the class CalendarRegressionTest method Test4149677.
/**
* Reported bug is that a GregorianCalendar with a cutover of
* Date(Long.MAX_VALUE) doesn't behave as a pure Julian calendar. CANNOT
* REPRODUCE THIS BUG
*/
@Test
public void Test4149677() {
TimeZone[] zones = { TimeZone.getTimeZone("GMT"), TimeZone.getTimeZone("PST"), TimeZone.getTimeZone("EAT") };
for (int i = 0; i < zones.length; ++i) {
GregorianCalendar calendar = new GregorianCalendar(zones[i]);
// Make sure extreme values don't wrap around
calendar.setTime(new Date(Long.MIN_VALUE));
if (calendar.get(Calendar.ERA) != GregorianCalendar.BC) {
errln("Fail: Long.MIN_VALUE ms has an AD year");
}
calendar.setTime(new Date(Long.MAX_VALUE));
if (calendar.get(Calendar.ERA) != GregorianCalendar.AD) {
errln("Fail: Long.MAX_VALUE ms has a BC year");
}
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
// to obtain a pure Julian calendar
boolean is100Leap = calendar.isLeapYear(100);
if (!is100Leap) {
errln("test failed with zone " + zones[i].getID());
errln(" cutover date is Calendar.MAX_DATE");
errln(" isLeapYear(100) returns: " + is100Leap);
}
}
}
use of android.icu.util.TimeZone in project j2objc by google.
the class CalendarRegressionTest method Test4096231.
@Test
public void Test4096231() {
TimeZone GMT = TimeZone.getTimeZone("GMT");
TimeZone PST = TimeZone.getTimeZone("PST");
int sec = 0, min = 0, hr = 0, day = 1, month = 10, year = 1997;
Calendar cal1 = new GregorianCalendar(PST);
cal1.setTime(new Date(880698639000L));
int p;
logln("PST 1 is: " + (p = cal1.get(Calendar.HOUR_OF_DAY)));
cal1.setTimeZone(GMT);
// Issue 1: Changing the timezone doesn't change the
// represented time.
int h1, h2;
logln("GMT 1 is: " + (h1 = cal1.get(Calendar.HOUR_OF_DAY)));
cal1.setTime(new Date(880698639000L));
logln("GMT 2 is: " + (h2 = cal1.get(Calendar.HOUR_OF_DAY)));
// to 4177484.
if (p == h1 || h1 != h2)
errln("Fail: Hour same in different zones");
Calendar cal2 = new GregorianCalendar(GMT);
Calendar cal3 = new GregorianCalendar(PST);
cal2.set(Calendar.MILLISECOND, 0);
cal3.set(Calendar.MILLISECOND, 0);
cal2.set(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), cal1.get(Calendar.DAY_OF_MONTH), cal1.get(Calendar.HOUR_OF_DAY), cal1.get(Calendar.MINUTE), cal1.get(Calendar.SECOND));
long t1, t2, t3, t4;
logln("RGMT 1 is: " + (t1 = cal2.getTime().getTime()));
cal3.set(year, month, day, hr, min, sec);
logln("RPST 1 is: " + (t2 = cal3.getTime().getTime()));
cal3.setTimeZone(GMT);
logln("RGMT 2 is: " + (t3 = cal3.getTime().getTime()));
cal3.set(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), cal1.get(Calendar.DAY_OF_MONTH), cal1.get(Calendar.HOUR_OF_DAY), cal1.get(Calendar.MINUTE), cal1.get(Calendar.SECOND));
// Issue 2: Calendar continues to use the timezone in its
// constructor for set() conversions, regardless
// of calls to setTimeZone()
logln("RGMT 3 is: " + (t4 = cal3.getTime().getTime()));
if (t1 == t2 || t1 != t4 || t2 != t3)
errln("Fail: Calendar zone behavior faulty");
}
use of android.icu.util.TimeZone in project j2objc by google.
the class CalendarRegressionTest method Test4162587.
/**
* Calendar and Date HOUR broken. If HOUR is out-of-range, Calendar and Date
* classes will misbehave.
*/
@Test
public void Test4162587() {
TimeZone tz = TimeZone.getTimeZone("PST");
TimeZone.setDefault(tz);
GregorianCalendar cal = new GregorianCalendar(tz);
Date d;
for (int i = 0; i < 5; ++i) {
if (i > 0)
logln("---");
cal.clear();
cal.set(1998, Calendar.APRIL, 5, i, 0);
d = cal.getTime();
String s0 = d.toString();
logln("0 " + i + ": " + s0);
cal.clear();
cal.set(1998, Calendar.APRIL, 4, i + 24, 0);
d = cal.getTime();
String sPlus = d.toString();
logln("+ " + i + ": " + sPlus);
cal.clear();
cal.set(1998, Calendar.APRIL, 6, i - 24, 0);
d = cal.getTime();
String sMinus = d.toString();
logln("- " + i + ": " + sMinus);
if (!s0.equals(sPlus) || !s0.equals(sMinus)) {
errln("Fail: All three lines must match");
}
}
}
use of android.icu.util.TimeZone in project j2objc by google.
the class CalendarRegressionTest method Test4059654.
/*
* User error - no bug here public void Test4059524() { // Create calendar
* for April 10, 1997 GregorianCalendar calendar = new GregorianCalendar(); //
* print out a bunch of interesting things logln("ERA: " +
* calendar.get(calendar.ERA)); logln("YEAR: " +
* calendar.get(calendar.YEAR)); logln("MONTH: " +
* calendar.get(calendar.MONTH)); logln("WEEK_OF_YEAR: " +
* calendar.get(calendar.WEEK_OF_YEAR)); logln("WEEK_OF_MONTH: " +
* calendar.get(calendar.WEEK_OF_MONTH)); logln("DATE: " +
* calendar.get(calendar.DATE)); logln("DAY_OF_MONTH: " +
* calendar.get(calendar.DAY_OF_MONTH)); logln("DAY_OF_YEAR: " +
* calendar.get(calendar.DAY_OF_YEAR)); logln("DAY_OF_WEEK: " +
* calendar.get(calendar.DAY_OF_WEEK)); logln("DAY_OF_WEEK_IN_MONTH: " +
* calendar.get(calendar.DAY_OF_WEEK_IN_MONTH)); logln("AM_PM: " +
* calendar.get(calendar.AM_PM)); logln("HOUR: " +
* calendar.get(calendar.HOUR)); logln("HOUR_OF_DAY: " +
* calendar.get(calendar.HOUR_OF_DAY)); logln("MINUTE: " +
* calendar.get(calendar.MINUTE)); logln("SECOND: " +
* calendar.get(calendar.SECOND)); logln("MILLISECOND: " +
* calendar.get(calendar.MILLISECOND)); logln("ZONE_OFFSET: " +
* (calendar.get(calendar.ZONE_OFFSET)/(60*60*1000))); logln("DST_OFFSET: " +
* (calendar.get(calendar.DST_OFFSET)/(60*60*1000))); calendar = new
* GregorianCalendar(1997,3,10); calendar.getTime(); logln("April 10,
* 1997"); logln("ERA: " + calendar.get(calendar.ERA)); logln("YEAR: " +
* calendar.get(calendar.YEAR)); logln("MONTH: " +
* calendar.get(calendar.MONTH)); logln("WEEK_OF_YEAR: " +
* calendar.get(calendar.WEEK_OF_YEAR)); logln("WEEK_OF_MONTH: " +
* calendar.get(calendar.WEEK_OF_MONTH)); logln("DATE: " +
* calendar.get(calendar.DATE)); logln("DAY_OF_MONTH: " +
* calendar.get(calendar.DAY_OF_MONTH)); logln("DAY_OF_YEAR: " +
* calendar.get(calendar.DAY_OF_YEAR)); logln("DAY_OF_WEEK: " +
* calendar.get(calendar.DAY_OF_WEEK)); logln("DAY_OF_WEEK_IN_MONTH: " +
* calendar.get(calendar.DAY_OF_WEEK_IN_MONTH)); logln("AM_PM: " +
* calendar.get(calendar.AM_PM)); logln("HOUR: " +
* calendar.get(calendar.HOUR)); logln("HOUR_OF_DAY: " +
* calendar.get(calendar.HOUR_OF_DAY)); logln("MINUTE: " +
* calendar.get(calendar.MINUTE)); logln("SECOND: " +
* calendar.get(calendar.SECOND)); logln("MILLISECOND: " +
* calendar.get(calendar.MILLISECOND)); logln("ZONE_OFFSET: " +
* (calendar.get(calendar.ZONE_OFFSET)/(60*60*1000))); // in hours
* logln("DST_OFFSET: " + (calendar.get(calendar.DST_OFFSET)/(60*60*1000))); //
* in hours }
*/
@Test
public void Test4059654() {
// try {
// work around bug for jdk1.4 on solaris 2.6, which uses funky
// timezone names
// jdk1.4.1 will drop support for 2.6 so we should be ok when it
// comes out
java.util.TimeZone javazone = java.util.TimeZone.getTimeZone("GMT");
TimeZone icuzone = TimeZone.getTimeZone("GMT");
GregorianCalendar gc = new GregorianCalendar(icuzone);
// April 1, 1997
gc.set(1997, 3, 1, 15, 16, 17);
gc.set(Calendar.HOUR, 0);
gc.set(Calendar.AM_PM, Calendar.AM);
gc.set(Calendar.MINUTE, 0);
gc.set(Calendar.SECOND, 0);
gc.set(Calendar.MILLISECOND, 0);
Date cd = gc.getTime();
java.util.Calendar cal = java.util.Calendar.getInstance(javazone);
cal.clear();
cal.set(1997, 3, 1, 0, 0, 0);
Date exp = cal.getTime();
if (!cd.equals(exp))
errln("Fail: Calendar.set broken. Got " + cd + " Want " + exp);
// } catch (RuntimeException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
// }
}
Aggregations