Search in sources :

Example 11 with GregorianCalendar

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");
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 12 with GregorianCalendar

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");
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) Test(org.junit.Test)

Example 13 with GregorianCalendar

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");
    }
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 14 with GregorianCalendar

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);
        }
    }
}
Also used : SimpleTimeZone(android.icu.util.SimpleTimeZone) TimeZone(android.icu.util.TimeZone) GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 15 with GregorianCalendar

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");
                        }
                    }
                }
            }
        }
    }
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Aggregations

GregorianCalendar (android.icu.util.GregorianCalendar)111 Test (org.junit.Test)102 Date (java.util.Date)63 Calendar (android.icu.util.Calendar)40 SimpleDateFormat (android.icu.text.SimpleDateFormat)34 SimpleTimeZone (android.icu.util.SimpleTimeZone)28 TimeZone (android.icu.util.TimeZone)28 DateFormat (android.icu.text.DateFormat)24 JapaneseCalendar (android.icu.util.JapaneseCalendar)17 ULocale (android.icu.util.ULocale)16 ChineseCalendar (android.icu.util.ChineseCalendar)15 IslamicCalendar (android.icu.util.IslamicCalendar)14 BuddhistCalendar (android.icu.util.BuddhistCalendar)12 ChineseDateFormat (android.icu.text.ChineseDateFormat)8 IOException (java.io.IOException)8 ParsePosition (java.text.ParsePosition)8 CalendarAstronomer (android.icu.impl.CalendarAstronomer)7 HebrewCalendar (android.icu.util.HebrewCalendar)7 FieldPosition (java.text.FieldPosition)7 ParseException (java.text.ParseException)6