use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRegressionTest method Test4084933.
/**
* The expected behavior of TimeZone around the boundaries is:
* (Assume transition time of 2:00 AM)
* day of onset 1:59 AM STD = display name 1:59 AM ST
* 2:00 AM STD = display name 3:00 AM DT
* day of end 0:59 AM STD = display name 1:59 AM DT
* 1:00 AM STD = display name 1:00 AM ST
*/
@Test
public void Test4084933() {
TimeZone tz = TimeZone.getTimeZone("PST");
long offset1 = tz.getOffset(1, 1997, Calendar.OCTOBER, 26, Calendar.SUNDAY, (2 * 60 * 60 * 1000));
long offset2 = tz.getOffset(1, 1997, Calendar.OCTOBER, 26, Calendar.SUNDAY, (2 * 60 * 60 * 1000) - 1);
long offset3 = tz.getOffset(1, 1997, Calendar.OCTOBER, 26, Calendar.SUNDAY, (1 * 60 * 60 * 1000));
long offset4 = tz.getOffset(1, 1997, Calendar.OCTOBER, 26, Calendar.SUNDAY, (1 * 60 * 60 * 1000) - 1);
/*
* The following was added just for consistency. It shows that going *to* Daylight
* Savings Time (PDT) does work at 2am.
*/
long offset5 = tz.getOffset(1, 1997, Calendar.APRIL, 6, Calendar.SUNDAY, (2 * 60 * 60 * 1000));
long offset6 = tz.getOffset(1, 1997, Calendar.APRIL, 6, Calendar.SUNDAY, (2 * 60 * 60 * 1000) - 1);
long offset7 = tz.getOffset(1, 1997, Calendar.APRIL, 6, Calendar.SUNDAY, (1 * 60 * 60 * 1000));
long offset8 = tz.getOffset(1, 1997, Calendar.APRIL, 6, Calendar.SUNDAY, (1 * 60 * 60 * 1000) - 1);
long SToffset = -8 * 60 * 60 * 1000L;
long DToffset = -7 * 60 * 60 * 1000L;
if (offset1 != SToffset || offset2 != SToffset || offset3 != SToffset || offset4 != DToffset || offset5 != DToffset || offset6 != SToffset || offset7 != SToffset || offset8 != SToffset)
warnln("Fail: TimeZone misbehaving");
}
use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRegressionTest method Test4073209.
@Test
public void Test4073209() {
TimeZone z1 = TimeZone.getTimeZone("PST");
TimeZone z2 = TimeZone.getTimeZone("PST");
if (z1 == z2)
errln("Fail: TimeZone should return clones");
}
use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRegressionTest method Test4109314.
@Test
public void Test4109314() {
GregorianCalendar testCal = (GregorianCalendar) Calendar.getInstance();
TimeZone PST = TimeZone.getTimeZone("PST");
java.util.Calendar tempcal = java.util.Calendar.getInstance();
tempcal.clear();
tempcal.set(1998, Calendar.APRIL, 4, 22, 0);
Date d1 = tempcal.getTime();
tempcal.set(1998, Calendar.APRIL, 5, 6, 0);
Date d2 = tempcal.getTime();
tempcal.set(1998, Calendar.OCTOBER, 24, 22, 0);
Date d3 = tempcal.getTime();
tempcal.set(1998, Calendar.OCTOBER, 25, 6, 0);
Date d4 = tempcal.getTime();
Object[] testData = { PST, d1, d2, PST, d3, d4 };
boolean pass = true;
for (int i = 0; i < testData.length; i += 3) {
testCal.setTimeZone((TimeZone) testData[i]);
long t = ((Date) testData[i + 1]).getTime();
Date end = (Date) testData[i + 2];
while (t < end.getTime()) {
testCal.setTime(new Date(t));
if (!checkCalendar314(testCal, (TimeZone) testData[i]))
pass = false;
t += 60 * 60 * 1000L;
}
}
if (!pass)
errln("Fail: TZ API inconsistent");
}
use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRegressionTest method Test4126678.
/**
* CANNOT REPRODUDE
*
* Yet another _alleged_ bug in TimeZone.getOffset(), a method that never
* should have been made public. It's simply too hard to use correctly.
*
* The original test code failed to do the following:
* (1) Call Calendar.setTime() before getting the fields!
* (2) Use the right millis (as usual) for getOffset(); they were passing
* in the MILLIS field, instead of the STANDARD MILLIS IN DAY.
* When you fix these two problems, the test passes, as expected.
*/
@Test
public void Test4126678() {
// Note: this test depends on the PST time zone.
TimeZone initialZone = TimeZone.getDefault();
Calendar cal = Calendar.getInstance();
TimeZone tz = TimeZone.getTimeZone("PST");
TimeZone.setDefault(tz);
cal.setTimeZone(tz);
java.util.Calendar tempcal = java.util.Calendar.getInstance();
tempcal.clear();
tempcal.set(1998, Calendar.APRIL, 5, 10, 0);
Date dt = tempcal.getTime();
// the dt value is local time in PST.
if (!tz.inDaylightTime(dt))
errln("We're not in Daylight Savings Time and we should be.\n");
cal.setTime(dt);
int era = cal.get(Calendar.ERA);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DATE);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int millis = cal.get(Calendar.MILLISECOND) + (cal.get(Calendar.SECOND) + (cal.get(Calendar.MINUTE) + (cal.get(Calendar.HOUR) * 60) * 60) * 1000) - cal.get(Calendar.DST_OFFSET);
long offset = tz.getOffset(era, year, month, day, dayOfWeek, millis);
long raw_offset = tz.getRawOffset();
if (offset == raw_offset)
errln("Offsets should not match when in DST");
// restore the initial time zone so that this test case
// doesn't affect the others.
TimeZone.setDefault(initialZone);
}
use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRegressionTest method Test4154650.
/**
* SimpleTimeZone.getOffset accepts illegal arguments.
*/
@Test
public void Test4154650() {
final int GOOD = 1, BAD = 0;
final int GOOD_ERA = GregorianCalendar.AD, GOOD_YEAR = 1998, GOOD_MONTH = Calendar.AUGUST;
final int GOOD_DAY = 2, GOOD_DOW = Calendar.SUNDAY, GOOD_TIME = 16 * 3600000;
int[] DATA = { GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GregorianCalendar.BC, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GregorianCalendar.AD, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD, GregorianCalendar.BC - 1, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD, GregorianCalendar.AD + 1, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, Calendar.DECEMBER, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY - 1, GOOD_DAY, GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.DECEMBER + 1, GOOD_DAY, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 1, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 31, GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 0, GOOD_DOW, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 32, GOOD_DOW, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SUNDAY, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SATURDAY, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SUNDAY - 1, GOOD_TIME, BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SATURDAY + 1, GOOD_TIME, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 0, GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 24 * 3600000 - 1, BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, -1, BAD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 24 * 3600000 };
TimeZone tz = TimeZone.getDefault();
for (int i = 0; i < DATA.length; i += 7) {
boolean good = DATA[i] == GOOD;
IllegalArgumentException e = null;
try {
/*int offset =*/
tz.getOffset(DATA[i + 1], DATA[i + 2], DATA[i + 3], DATA[i + 4], DATA[i + 5], DATA[i + 6]);
// offset = 0;
} catch (IllegalArgumentException ex) {
e = ex;
}
if (good != (e == null)) {
errln("Fail: getOffset(" + DATA[i + 1] + ", " + DATA[i + 2] + ", " + DATA[i + 3] + ", " + DATA[i + 4] + ", " + DATA[i + 5] + ", " + DATA[i + 6] + (good ? (") threw " + e) : ") accepts invalid args"));
}
}
}
Aggregations