Search in sources :

Example 96 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class DateFormatTest method TestDateFormatZone146.

/**
 * Test the formatting of time zones.
 */
@Test
public void TestDateFormatZone146() {
    TimeZone saveDefault = TimeZone.getDefault();
    // try {
    TimeZone thedefault = TimeZone.getTimeZone("GMT");
    TimeZone.setDefault(thedefault);
    // java.util.Locale.setDefault(new java.util.Locale("ar", "", ""));
    // check to be sure... its GMT all right
    TimeZone testdefault = TimeZone.getDefault();
    String testtimezone = testdefault.getID();
    if (testtimezone.equals("GMT"))
        logln("Test timezone = " + testtimezone);
    else
        errln("Test timezone should be GMT, not " + testtimezone);
    // now try to use the default GMT time zone
    GregorianCalendar greenwichcalendar = new GregorianCalendar(1997, 3, 4, 23, 0);
    // *****************************greenwichcalendar.setTimeZone(TimeZone.getDefault());
    // greenwichcalendar.set(1997, 3, 4, 23, 0);
    // try anything to set hour to 23:00 !!!
    greenwichcalendar.set(Calendar.HOUR_OF_DAY, 23);
    // get time
    Date greenwichdate = greenwichcalendar.getTime();
    // format every way
    String[] DATA = { "simple format:  ", "04/04/97 23:00 GMT", "MM/dd/yy HH:mm zzz", "full format:    ", "Friday, April 4, 1997 11:00:00 o'clock PM GMT", "EEEE, MMMM d, yyyy h:mm:ss 'o''clock' a zzz", "long format:    ", "April 4, 1997 11:00:00 PM GMT", "MMMM d, yyyy h:mm:ss a z", "default format: ", "04-Apr-97 11:00:00 PM", "dd-MMM-yy h:mm:ss a", "short format:   ", "4/4/97 11:00 PM", "M/d/yy h:mm a" };
    int DATA_length = DATA.length;
    for (int i = 0; i < DATA_length; i += 3) {
        DateFormat fmt = new SimpleDateFormat(DATA[i + 2], Locale.ENGLISH);
        fmt.setCalendar(greenwichcalendar);
        String result = fmt.format(greenwichdate);
        logln(DATA[i] + result);
        if (!result.equals(DATA[i + 1]))
            errln("FAIL: Expected " + DATA[i + 1] + ", got " + result);
    }
    // }
    // finally {
    TimeZone.setDefault(saveDefault);
// }
}
Also used : TimeZone(android.icu.util.TimeZone) DateFormat(android.icu.text.DateFormat) ChineseDateFormat(android.icu.text.ChineseDateFormat) SimpleDateFormat(android.icu.text.SimpleDateFormat) GregorianCalendar(android.icu.util.GregorianCalendar) SimpleDateFormat(android.icu.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 97 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class DateFormatTest method TestContext.

@Test
public void TestContext() {
    class TestContextItem {

        public String locale;

        public String pattern;

        public DisplayContext capitalizationContext;

        public String expectedFormat;

        // Simple constructor
        public TestContextItem(String loc, String pat, DisplayContext capCtxt, String expFmt) {
            locale = loc;
            pattern = pat;
            capitalizationContext = capCtxt;
            expectedFormat = expFmt;
        }
    }
    ;
    final TestContextItem[] items = { new TestContextItem("fr", "MMMM y", DisplayContext.CAPITALIZATION_NONE, "juillet 2008"), new TestContextItem("fr", "MMMM y", DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, "juillet 2008"), new TestContextItem("fr", "MMMM y", DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, "Juillet 2008"), new TestContextItem("fr", "MMMM y", DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU, "juillet 2008"), new TestContextItem("fr", "MMMM y", DisplayContext.CAPITALIZATION_FOR_STANDALONE, "Juillet 2008"), new TestContextItem("cs", "LLLL y", DisplayContext.CAPITALIZATION_NONE, "\u010Dervenec 2008"), new TestContextItem("cs", "LLLL y", DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, "\u010Dervenec 2008"), new TestContextItem("cs", "LLLL y", DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, "\u010Cervenec 2008"), new TestContextItem("cs", "LLLL y", DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU, "\u010Cervenec 2008"), new TestContextItem("cs", "LLLL y", DisplayContext.CAPITALIZATION_FOR_STANDALONE, "\u010Dervenec 2008") };
    class TestRelativeContextItem {

        public String locale;

        public DisplayContext capitalizationContext;

        public String expectedFormatToday;

        public String expectedFormatYesterday;

        // Simple constructor
        public TestRelativeContextItem(String loc, DisplayContext capCtxt, String expFmtToday, String expFmtYesterday) {
            locale = loc;
            capitalizationContext = capCtxt;
            expectedFormatToday = expFmtToday;
            expectedFormatYesterday = expFmtYesterday;
        }
    }
    ;
    final TestRelativeContextItem[] relItems = { new TestRelativeContextItem("en", DisplayContext.CAPITALIZATION_NONE, "today", "yesterday"), new TestRelativeContextItem("en", DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, "today", "yesterday"), new TestRelativeContextItem("en", DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, "Today", "Yesterday"), new TestRelativeContextItem("en", DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU, "Today", "Yesterday"), new TestRelativeContextItem("en", DisplayContext.CAPITALIZATION_FOR_STANDALONE, "Today", "Yesterday"), new TestRelativeContextItem("nb", DisplayContext.CAPITALIZATION_NONE, "i dag", "i g\u00E5r"), new TestRelativeContextItem("nb", DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, "i dag", "i g\u00E5r"), new TestRelativeContextItem("nb", DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, "I dag", "I g\u00E5r"), new TestRelativeContextItem("nb", DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU, "i dag", "i g\u00E5r"), new TestRelativeContextItem("nb", DisplayContext.CAPITALIZATION_FOR_STANDALONE, "I dag", "I g\u00E5r") };
    Calendar cal = new GregorianCalendar(2008, Calendar.JULY, 2);
    for (TestContextItem item : items) {
        ULocale locale = new ULocale(item.locale);
        SimpleDateFormat sdfmt = new SimpleDateFormat(item.pattern, locale);
        // now try context & standard format call
        sdfmt.setContext(item.capitalizationContext);
        SimpleDateFormat sdfmtClone = (SimpleDateFormat) sdfmt.clone();
        if (!sdfmtClone.equals(sdfmt)) {
            errln("FAIL: for locale " + item.locale + ", capitalizationContext " + item.capitalizationContext + ", sdfmt.clone() != sdfmt (for SimpleDateFormat)");
        }
        StringBuffer result2 = new StringBuffer();
        FieldPosition fpos2 = new FieldPosition(0);
        sdfmt.format(cal, result2, fpos2);
        if (result2.toString().compareTo(item.expectedFormat) != 0) {
            errln("FAIL: format for locale " + item.locale + ", capitalizationContext " + item.capitalizationContext + ", expected \"" + item.expectedFormat + "\", got \"" + result2 + "\"");
        }
        // now read back context, make sure it is what we set (testing with DateFormat subclass)
        DisplayContext capitalizationContext = sdfmt.getContext(DisplayContext.Type.CAPITALIZATION);
        if (capitalizationContext != item.capitalizationContext) {
            errln("FAIL: getContext for locale " + item.locale + ", capitalizationContext " + item.capitalizationContext + ", but got context " + capitalizationContext);
        }
    }
    for (TestRelativeContextItem relItem : relItems) {
        ULocale locale = new ULocale(relItem.locale);
        DateFormat dfmt = DateFormat.getDateInstance(DateFormat.RELATIVE_LONG, locale);
        Date today = new Date();
        // now try context & standard format call
        dfmt.setContext(relItem.capitalizationContext);
        // write to stream, then read a copy from stream & compare
        boolean serializeTestFail = false;
        ByteArrayOutputStream baos = null;
        DateFormat dfmtFromStream = null;
        try {
            baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(dfmt);
            oos.close();
        } catch (IOException i) {
            errln("FAIL: for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", serialization of RELATIVE_LONG DateFormat fails with IOException");
            serializeTestFail = true;
        }
        if (!serializeTestFail) {
            byte[] buf = baos.toByteArray();
            try {
                ByteArrayInputStream bais = new ByteArrayInputStream(buf);
                ObjectInputStream ois = new ObjectInputStream(bais);
                dfmtFromStream = (DateFormat) ois.readObject();
                ois.close();
            } catch (IOException i) {
                errln("FAIL: for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", deserialization of RELATIVE_LONG DateFormat fails with IOException");
                serializeTestFail = true;
            } catch (ClassNotFoundException c) {
                errln("FAIL: for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", deserialization of RELATIVE_LONG DateFormat fails with ClassNotFoundException");
                serializeTestFail = true;
            }
        }
        if (!serializeTestFail && dfmtFromStream == null) {
            errln("FAIL: for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", dfmtFromStream is null (for RELATIVE_LONG)");
            serializeTestFail = true;
        }
        if (!serializeTestFail && !dfmtFromStream.equals(dfmt)) {
            errln("FAIL: for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", dfmtFromStream != dfmt (for RELATIVE_LONG)");
            serializeTestFail = true;
        }
        cal.setTime(today);
        StringBuffer result2 = new StringBuffer();
        FieldPosition fpos2 = new FieldPosition(0);
        dfmt.format(cal, result2, fpos2);
        if (result2.toString().compareTo(relItem.expectedFormatToday) != 0) {
            errln("FAIL: format today for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", expected \"" + relItem.expectedFormatToday + "\", got \"" + result2 + "\"");
        }
        if (!serializeTestFail) {
            result2.setLength(0);
            dfmtFromStream.format(cal, result2, fpos2);
            if (result2.toString().compareTo(relItem.expectedFormatToday) != 0) {
                errln("FAIL: use dfmtFromStream to format today for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", expected \"" + relItem.expectedFormatToday + "\", got \"" + result2 + "\"");
            }
        }
        cal.add(Calendar.DATE, -1);
        result2.setLength(0);
        dfmt.format(cal, result2, fpos2);
        if (result2.toString().compareTo(relItem.expectedFormatYesterday) != 0) {
            errln("FAIL: format yesterday for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", expected \"" + relItem.expectedFormatYesterday + "\", got \"" + result2 + "\"");
        }
        // now read back context, make sure it is what we set (testing with DateFormat itself)
        DisplayContext capitalizationContext = dfmt.getContext(DisplayContext.Type.CAPITALIZATION);
        if (capitalizationContext != relItem.capitalizationContext) {
            errln("FAIL: getContext for locale " + relItem.locale + ", capitalizationContext " + relItem.capitalizationContext + ", but got context " + capitalizationContext);
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) DisplayContext(android.icu.text.DisplayContext) BuddhistCalendar(android.icu.util.BuddhistCalendar) HebrewCalendar(android.icu.util.HebrewCalendar) IslamicCalendar(android.icu.util.IslamicCalendar) ChineseCalendar(android.icu.util.ChineseCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FieldPosition(java.text.FieldPosition) ObjectOutputStream(java.io.ObjectOutputStream) Date(java.util.Date) ByteArrayInputStream(java.io.ByteArrayInputStream) DateFormat(android.icu.text.DateFormat) ChineseDateFormat(android.icu.text.ChineseDateFormat) SimpleDateFormat(android.icu.text.SimpleDateFormat) SimpleDateFormat(android.icu.text.SimpleDateFormat) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 98 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class GlobalizationPreferencesTest method TestJB5380.

/*
     * JB#5380 GlobalizationPreferences#getCalendar() should return a Calendar object
     * initialized with the current time
     */
@Test
public void TestJB5380() {
    GlobalizationPreferences gp = new GlobalizationPreferences();
    GregorianCalendar gcal = new GregorianCalendar();
    // set way old date
    gcal.set(Calendar.YEAR, 1950);
    // set calendar to GP
    gp.setCalendar(gcal);
    Calendar cal = gp.getCalendar();
    // Calendar instance returned from GP should be initialized
    // by the current time
    long timeDiff = System.currentTimeMillis() - cal.getTimeInMillis();
    if (Math.abs(timeDiff) > 1000) {
        // if difference is more than 1 second..
        errln("FAIL: The Calendar was not initialized by current time - difference:" + timeDiff);
    }
}
Also used : GlobalizationPreferences(android.icu.util.GlobalizationPreferences) IslamicCalendar(android.icu.util.IslamicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) BuddhistCalendar(android.icu.util.BuddhistCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) Test(org.junit.Test)

Example 99 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class CompatibilityTest method TestMapping.

/**
 * Test the mapping between millis and fields.  For the purposes
 * of this test, we don't care about timezones and week data
 * (first day of week, minimal days in first week).
 */
@Test
public void TestMapping() {
    if (false) {
        Date PURE_GREGORIAN = new Date(Long.MIN_VALUE);
        Date PURE_JULIAN = new Date(Long.MAX_VALUE);
        GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
        final int EPOCH_JULIAN = 2440588;
        final long ONE_DAY = 24 * 60 * 60 * 1000L;
        android.icu.text.SimpleDateFormat fmt = new android.icu.text.SimpleDateFormat("EEE MMM dd yyyy G");
        for (int type = 0; type < 2; ++type) {
            System.out.println(type == 0 ? "Gregorian" : "Julian");
            cal.setGregorianChange(type == 0 ? PURE_GREGORIAN : PURE_JULIAN);
            fmt.setCalendar(cal);
            int[] J = { 0x7FFFFFFF, 0x7FFFFFF0, 0x7F000000, 0x78000000, 0x70000000, 0x60000000, 0x50000000, 0x40000000, 0x30000000, 0x20000000, 0x10000000 };
            for (int i = 0; i < J.length; ++i) {
                String[] lim = new String[2];
                long[] ms = new long[2];
                int jd = J[i];
                for (int sign = 0; sign < 2; ++sign) {
                    int julian = jd;
                    if (sign == 0)
                        julian = -julian;
                    long millis = ((long) julian - EPOCH_JULIAN) * ONE_DAY;
                    ms[sign] = millis;
                    cal.setTime(new Date(millis));
                    lim[sign] = fmt.format(cal.getTime());
                }
                System.out.println("JD +/-" + Long.toString(jd, 16) + ": " + ms[0] + ".." + ms[1] + ": " + lim[0] + ".." + lim[1]);
            }
        }
    }
    TimeZone saveZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
        // NEWCAL
        Date PURE_GREGORIAN = new Date(Long.MIN_VALUE);
        Date PURE_JULIAN = new Date(Long.MAX_VALUE);
        GregorianCalendar cal = new GregorianCalendar();
        final int EPOCH_JULIAN = 2440588;
        final long ONE_DAY = 24 * 60 * 60 * 1000L;
        int[] DATA = { // Julian#   Year  Month               DOM   JULIAN:Year, Month,       DOM
        2440588, 1970, Calendar.JANUARY, 1, 1969, Calendar.DECEMBER, 19, 2415080, 1900, Calendar.MARCH, 1, 1900, Calendar.FEBRUARY, 17, 2451604, 2000, Calendar.FEBRUARY, 29, 2000, Calendar.FEBRUARY, 16, 2452269, 2001, Calendar.DECEMBER, 25, 2001, Calendar.DECEMBER, 12, 2416526, 1904, Calendar.FEBRUARY, 15, 1904, Calendar.FEBRUARY, 2, 2416656, 1904, Calendar.JUNE, 24, 1904, Calendar.JUNE, 11, 1721426, 1, Calendar.JANUARY, 1, 1, Calendar.JANUARY, 3, 2000000, 763, Calendar.SEPTEMBER, 18, 763, Calendar.SEPTEMBER, 14, 4000000, 6239, Calendar.JULY, 12, 6239, Calendar.MAY, 28, 8000000, 17191, Calendar.FEBRUARY, 26, 17190, Calendar.OCTOBER, 22, 10000000, 22666, Calendar.DECEMBER, 20, 22666, Calendar.JULY, 5 };
        for (int i = 0; i < DATA.length; i += 7) {
            int julian = DATA[i];
            int year = DATA[i + 1];
            int month = DATA[i + 2];
            int dom = DATA[i + 3];
            int year2, month2, dom2;
            long millis = (julian - EPOCH_JULIAN) * ONE_DAY;
            String s;
            // Test Gregorian computation
            cal.setGregorianChange(PURE_GREGORIAN);
            cal.clear();
            cal.set(year, month, dom);
            long calMillis = cal.getTime().getTime();
            long delta = calMillis - millis;
            cal.setTime(new Date(millis));
            year2 = cal.get(Calendar.YEAR);
            month2 = cal.get(Calendar.MONTH);
            dom2 = cal.get(Calendar.DAY_OF_MONTH);
            s = "G " + year + "-" + (month + 1 - Calendar.JANUARY) + "-" + dom + " => " + calMillis + " (" + ((float) delta / ONE_DAY) + " day delta) => " + year2 + "-" + (month2 + 1 - Calendar.JANUARY) + "-" + dom2;
            if (delta != 0 || year != year2 || month != month2 || dom != dom2)
                errln(s + " FAIL");
            else
                logln(s);
            // Test Julian computation
            year = DATA[i + 4];
            month = DATA[i + 5];
            dom = DATA[i + 6];
            cal.setGregorianChange(PURE_JULIAN);
            cal.clear();
            cal.set(year, month, dom);
            calMillis = cal.getTime().getTime();
            delta = calMillis - millis;
            cal.setTime(new Date(millis));
            year2 = cal.get(Calendar.YEAR);
            month2 = cal.get(Calendar.MONTH);
            dom2 = cal.get(Calendar.DAY_OF_MONTH);
            s = "J " + year + "-" + (month + 1 - Calendar.JANUARY) + "-" + dom + " => " + calMillis + " (" + ((float) delta / ONE_DAY) + " day delta) => " + year2 + "-" + (month2 + 1 - Calendar.JANUARY) + "-" + dom2;
            if (delta != 0 || year != year2 || month != month2 || dom != dom2)
                errln(s + " FAIL");
            else
                logln(s);
        }
        java.util.Calendar tempcal = java.util.Calendar.getInstance();
        tempcal.clear();
        tempcal.set(1582, Calendar.OCTOBER, 15);
        cal.setGregorianChange(tempcal.getTime());
        auxMapping(cal, 1582, Calendar.OCTOBER, 4);
        auxMapping(cal, 1582, Calendar.OCTOBER, 15);
        auxMapping(cal, 1582, Calendar.OCTOBER, 16);
        for (int y = 800; y < 3000; y += 1 + (int) (100 * Math.random())) {
            for (int m = Calendar.JANUARY; m <= Calendar.DECEMBER; ++m) {
                auxMapping(cal, y, m, 15);
            }
        }
    } finally {
        TimeZone.setDefault(saveZone);
    }
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) SimpleTimeZone(android.icu.util.SimpleTimeZone) TimeZone(android.icu.util.TimeZone) Test(org.junit.Test)

Example 100 with GregorianCalendar

use of android.icu.util.GregorianCalendar in project j2objc by google.

the class CompatibilityTest method TestGenericAPI.

@Test
public void TestGenericAPI() {
    // not used String str;
    java.util.Calendar tempcal = java.util.Calendar.getInstance();
    tempcal.clear();
    tempcal.set(1990, Calendar.APRIL, 15);
    Date when = tempcal.getTime();
    String tzid = "TestZone";
    int tzoffset = 123400;
    SimpleTimeZone zone = new SimpleTimeZone(tzoffset, tzid);
    Calendar cal = (Calendar) Calendar.getInstance((SimpleTimeZone) zone.clone());
    if (!zone.equals(cal.getTimeZone()))
        errln("FAIL: Calendar.getTimeZone failed");
    Calendar cal2 = Calendar.getInstance(cal.getTimeZone());
    cal.setTime(when);
    cal2.setTime(when);
    if (!(cal.equals(cal2)))
        errln("FAIL: Calendar.operator== failed");
    // if ((*cal != *cal2))  errln("FAIL: Calendar.operator!= failed");
    if (!cal.equals(cal2) || cal.before(cal2) || cal.after(cal2))
        errln("FAIL: equals/before/after failed");
    cal2.setTime(new Date(when.getTime() + 1000));
    if (cal.equals(cal2) || cal2.before(cal) || cal.after(cal2))
        errln("FAIL: equals/before/after failed");
    cal.roll(Calendar.SECOND, true);
    if (!cal.equals(cal2) || cal.before(cal2) || cal.after(cal2))
        errln("FAIL: equals/before/after failed");
    // Roll back to January
    cal.roll(Calendar.MONTH, (int) (1 + Calendar.DECEMBER - cal.get(Calendar.MONTH)));
    if (cal.equals(cal2) || cal2.before(cal) || cal.after(cal2))
        errln("FAIL: equals/before/after failed");
    for (int i = 0; i < 2; ++i) {
        boolean lenient = (i > 0);
        cal.setLenient(lenient);
        if (lenient != cal.isLenient())
            errln("FAIL: setLenient/isLenient failed");
    // Later: Check for lenient behavior
    }
    int i;
    for (i = Calendar.SUNDAY; i <= Calendar.SATURDAY; ++i) {
        cal.setFirstDayOfWeek(i);
        if (cal.getFirstDayOfWeek() != i)
            errln("FAIL: set/getFirstDayOfWeek failed");
    }
    for (i = 1; i <= 7; ++i) {
        cal.setMinimalDaysInFirstWeek(i);
        if (cal.getMinimalDaysInFirstWeek() != i)
            errln("FAIL: set/getFirstDayOfWeek failed");
    }
    for (i = 0; i < cal.getFieldCount(); ++i) {
        if (cal.getMinimum(i) > cal.getGreatestMinimum(i))
            errln("FAIL: getMinimum larger than getGreatestMinimum for field " + i);
        if (cal.getLeastMaximum(i) > cal.getMaximum(i))
            errln("FAIL: getLeastMaximum larger than getMaximum for field " + i);
        if (cal.getMinimum(i) >= cal.getMaximum(i))
            errln("FAIL: getMinimum not less than getMaximum for field " + i);
    }
    cal.setTimeZone(TimeZone.getDefault());
    cal.clear();
    cal.set(1984, 5, 24);
    tempcal.clear();
    tempcal.set(1984, 5, 24);
    if (cal.getTime().getTime() != tempcal.getTime().getTime()) {
        errln("FAIL: Calendar.set(3 args) failed");
        logln(" Got: " + cal.getTime() + "  Expected: " + tempcal.getTime());
    }
    cal.clear();
    cal.set(1985, 2, 2, 11, 49);
    tempcal.clear();
    tempcal.set(1985, 2, 2, 11, 49);
    if (cal.getTime().getTime() != tempcal.getTime().getTime()) {
        errln("FAIL: Calendar.set(5 args) failed");
        logln(" Got: " + cal.getTime() + "  Expected: " + tempcal.getTime());
    }
    cal.clear();
    cal.set(1995, 9, 12, 1, 39, 55);
    tempcal.clear();
    tempcal.set(1995, 9, 12, 1, 39, 55);
    if (cal.getTime().getTime() != tempcal.getTime().getTime()) {
        errln("FAIL: Calendar.set(6 args) failed");
        logln(" Got: " + cal.getTime() + "  Expected: " + tempcal.getTime());
    }
    cal.getTime();
    // others not to be?  Revisit the appropriateness of this.  - Alan NEWCAL
    for (i = 0; i < cal.getFieldCount(); ++i) {
        switch(i) {
            case Calendar.YEAR:
            case Calendar.MONTH:
            case Calendar.DATE:
            case Calendar.HOUR_OF_DAY:
            case Calendar.MINUTE:
            case Calendar.SECOND:
            case Calendar.EXTENDED_YEAR:
                if (!cal.isSet(i))
                    errln("FAIL: " + FIELD_NAME[i] + " is not set");
                break;
            default:
                if (cal.isSet(i))
                    errln("FAIL: " + FIELD_NAME[i] + " is set");
        }
        cal.clear(i);
        if (cal.isSet(i))
            errln("FAIL: Calendar.clear/isSet failed");
    }
    // delete cal;
    // delete cal2;
    Locale[] loc = Calendar.getAvailableLocales();
    long count = loc.length;
    if (count < 1 || loc == null) {
        errln("FAIL: getAvailableLocales failed");
    } else {
        for (i = 0; i < count; ++i) {
            cal = Calendar.getInstance(loc[i]);
        // delete cal;
        }
    }
    cal = Calendar.getInstance(TimeZone.getDefault(), Locale.ENGLISH);
    // delete cal;
    cal = Calendar.getInstance(zone, Locale.ENGLISH);
    // delete cal;
    GregorianCalendar gc = new GregorianCalendar(zone);
    // delete gc;
    gc = new GregorianCalendar(Locale.ENGLISH);
    // delete gc;
    gc = new GregorianCalendar(Locale.ENGLISH);
    // delete gc;
    gc = new GregorianCalendar(zone, Locale.ENGLISH);
    // delete gc;
    gc = new GregorianCalendar(zone);
    // delete gc;
    gc = new GregorianCalendar(1998, 10, 14, 21, 43);
    tempcal.clear();
    tempcal.set(1998, 10, 14, 21, 43);
    if (gc.getTime().getTime() != tempcal.getTime().getTime())
        errln("FAIL: new GregorianCalendar(ymdhm) failed");
    // delete gc;
    gc = new GregorianCalendar(1998, 10, 14, 21, 43, 55);
    tempcal.clear();
    tempcal.set(1998, 10, 14, 21, 43, 55);
    if (gc.getTime().getTime() != tempcal.getTime().getTime())
        errln("FAIL: new GregorianCalendar(ymdhms) failed");
// C++ only:
// GregorianCalendar gc2 = new GregorianCalendar(Locale.ENGLISH);
// gc2 = gc;
// if (gc2 != gc || !(gc2 == gc)) errln("FAIL: GregorianCalendar assignment/operator==/operator!= failed");
// delete gc;
// delete z;
}
Also used : Locale(java.util.Locale) SimpleTimeZone(android.icu.util.SimpleTimeZone) GregorianCalendar(android.icu.util.GregorianCalendar) Calendar(android.icu.util.Calendar) GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Aggregations

GregorianCalendar (android.icu.util.GregorianCalendar)114 Test (org.junit.Test)102 Date (java.util.Date)64 Calendar (android.icu.util.Calendar)41 SimpleDateFormat (android.icu.text.SimpleDateFormat)34 TimeZone (android.icu.util.TimeZone)29 SimpleTimeZone (android.icu.util.SimpleTimeZone)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