use of android.icu.util.GregorianCalendar in project j2objc by google.
the class CalendarRegressionTest method Test4100311.
@Test
public void Test4100311() {
GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
cal.set(Calendar.YEAR, 1997);
cal.set(Calendar.DAY_OF_YEAR, 1);
// Should be Jan 1
Date d = cal.getTime();
logln(d.toString());
if (cal.get(Calendar.DAY_OF_YEAR) != 1)
errln("Fail: DAY_OF_YEAR not set");
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class CalendarRegressionTest method Test4092362.
@Test
public void Test4092362() {
GregorianCalendar cal1 = new GregorianCalendar(1997, 10, 11, 10, 20, 40);
/*
* cal1.set( Calendar.YEAR, 1997 ); cal1.set( Calendar.MONTH, 10 );
* cal1.set( Calendar.DATE, 11 ); cal1.set( Calendar.HOUR, 10 );
* cal1.set( Calendar.MINUTE, 20 ); cal1.set( Calendar.SECOND, 40 );
*/
logln(" Cal1 = " + cal1.getTime().getTime());
logln(" Cal1 time in ms = " + cal1.get(Calendar.MILLISECOND));
for (int k = 0; k < 100; k++) {
System.out.print("");
}
GregorianCalendar cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40);
/*
* cal2.set( Calendar.YEAR, 1997 ); cal2.set( Calendar.MONTH, 10 );
* cal2.set( Calendar.DATE, 11 ); cal2.set( Calendar.HOUR, 10 );
* cal2.set( Calendar.MINUTE, 20 ); cal2.set( Calendar.SECOND, 40 );
*/
logln(" Cal2 = " + cal2.getTime().getTime());
logln(" Cal2 time in ms = " + cal2.get(Calendar.MILLISECOND));
if (!cal1.equals(cal2))
errln("Fail: Milliseconds randomized");
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class CalendarRegressionTest method Test4165343.
/**
* Adding 12 months behaves differently from adding 1 year
*/
@Test
public void Test4165343() {
GregorianCalendar calendar = new GregorianCalendar(1996, Calendar.FEBRUARY, 29);
Date start = calendar.getTime();
logln("init date: " + start);
calendar.add(Calendar.MONTH, 12);
Date date1 = calendar.getTime();
logln("after adding 12 months: " + date1);
calendar.setTime(start);
calendar.add(Calendar.YEAR, 1);
Date date2 = calendar.getTime();
logln("after adding one year : " + date2);
if (date1.equals(date2)) {
logln("Test passed");
} else {
errln("Test failed");
}
}
use of android.icu.util.GregorianCalendar 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.GregorianCalendar in project j2objc by google.
the class CalendarRegressionTest method Test4173516.
/**
* Calendar.roll broken This bug relies on the TimeZone bug 4173604 to also
* be fixed.
*/
@Test
public void Test4173516() {
int[][] fieldsList = { { 1997, Calendar.FEBRUARY, 1, 10, 45, 15, 900 }, { 1999, Calendar.DECEMBER, 22, 23, 59, 59, 999 } };
int limit = 40;
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date(0));
cal.roll(Calendar.HOUR, 0x7F000000);
cal.roll(Calendar.HOUR, -0x7F000000);
if (cal.getTime().getTime() != 0) {
errln("Hour rolling broken");
}
for (int op = 0; op < 2; ++op) {
logln("Testing GregorianCalendar " + (op == 0 ? "add" : "roll"));
for (int field = 0; field < cal.getFieldCount(); ++field) {
if (field != Calendar.ZONE_OFFSET && field != Calendar.DST_OFFSET && field != Calendar.IS_LEAP_MONTH) {
for (int j = 0; j < fieldsList.length; ++j) {
int[] fields = fieldsList[j];
cal.clear();
cal.set(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5]);
cal.set(Calendar.MILLISECOND, fields[6]);
cal.setMinimalDaysInFirstWeek(1);
for (int i = 0; i < 2 * limit; i++) {
if (op == 0) {
cal.add(field, i < limit ? 1 : -1);
} else {
cal.roll(field, i < limit ? 1 : -1);
}
}
if (cal.get(Calendar.YEAR) != fields[0] || cal.get(Calendar.MONTH) != fields[1] || cal.get(Calendar.DATE) != fields[2] || cal.get(Calendar.HOUR_OF_DAY) != fields[3] || cal.get(Calendar.MINUTE) != fields[4] || cal.get(Calendar.SECOND) != fields[5] || cal.get(Calendar.MILLISECOND) != fields[6]) {
errln("Field " + field + " (" + FIELD_NAME[field] + ") FAIL, expected " + fields[0] + "/" + (fields[1] + 1) + "/" + fields[2] + " " + fields[3] + ":" + fields[4] + ":" + fields[5] + "." + fields[6] + ", got " + cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND) + "." + cal.get(Calendar.MILLISECOND));
cal.clear();
cal.set(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5]);
cal.set(Calendar.MILLISECOND, fields[6]);
logln("Start date: " + cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND) + "." + cal.get(Calendar.MILLISECOND));
long prev = cal.getTime().getTime();
for (int i = 0; i < 2 * limit; i++) {
if (op == 0) {
cal.add(field, i < limit ? 1 : -1);
} else {
cal.roll(field, i < limit ? 1 : -1);
}
long t = cal.getTime().getTime();
long delta = t - prev;
prev = t;
logln((op == 0 ? "add(" : "roll(") + FIELD_NAME[field] + (i < limit ? ", +1) => " : ", -1) => ") + cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND) + "." + cal.get(Calendar.MILLISECOND) + " delta=" + delta + " ms");
}
}
}
}
}
}
}
Aggregations