Search in sources :

Example 86 with Calendar

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

the class IBMCalendarTest method TestTypes.

@Test
public void TestTypes() {
    String[] locs = { "en_US_VALLEYGIRL", "en_US_VALLEYGIRL@collation=phonebook;calendar=japanese", "en_US_VALLEYGIRL@collation=phonebook;calendar=gregorian", "ja_JP@calendar=japanese", "th_TH@calendar=buddhist", "th-TH-u-ca-gregory", "ja_JP_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH_TRADITIONAL@calendar=gregorian", "en_US", // Default calendar for th_TH is buddhist
    "th_TH", // th's default region is TH and buddhist is used as default for TH
    "th", // Default calendar for any locales with region TH is buddhist
    "en_TH", // iso8601 calendar type
    "th_TH@calendar=iso8601", "fr_CH", "fr_SA", "fr_CH@rg=sazzzz", "fr_CH@calendar=japanese;rg=sazzzz", // ignore malformed rg tag, use buddhist
    "fr_TH@rg=SA", // ignore malformed rg tag, use buddhist
    "th@rg=SA" };
    // Android patch: Force default Gregorian calendar.
    String[] types = { "gregorian", "japanese", "gregorian", "japanese", "buddhist", "gregorian", "japanese", "buddhist", "gregorian", "gregorian", "gregorian", "gregorian", "gregorian", // iso8601 is a gregorian sub type
    "gregorian", "gregorian", "gregorian", "gregorian", "japanese", "gregorian", "gregorian" };
    for (int i = 0; i < locs.length; i++) {
        Calendar cal = Calendar.getInstance(new ULocale(locs[i]));
        if (!cal.getType().equals(types[i])) {
            errln(locs[i] + " Calendar type " + cal.getType() + " instead of " + types[i]);
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) ChineseCalendar(android.icu.util.ChineseCalendar) TaiwanCalendar(android.icu.util.TaiwanCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) BuddhistCalendar(android.icu.util.BuddhistCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) Test(org.junit.Test)

Example 87 with Calendar

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

the class IBMCalendarTest method TestMalaysianInstance.

/**
 * Test ms_MY "Malay (Malaysia)" locale.  Bug 1543.
 */
@Test
public void TestMalaysianInstance() {
    // Malay (Malaysia)
    Locale loc = new Locale("ms", "MY");
    Calendar cal = Calendar.getInstance(loc);
    if (cal == null) {
        errln("could not create Malaysian instance");
    }
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) ChineseCalendar(android.icu.util.ChineseCalendar) TaiwanCalendar(android.icu.util.TaiwanCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) BuddhistCalendar(android.icu.util.BuddhistCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) Test(org.junit.Test)

Example 88 with Calendar

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

the class IBMCalendarTest method TestISO8601.

@Test
public void TestISO8601() {
    final ULocale[] TEST_LOCALES = { new ULocale("en_US@calendar=iso8601"), new ULocale("en_US@calendar=Iso8601"), new ULocale("th_TH@calendar=iso8601"), new ULocale("ar_EG@calendar=iso8601") };
    final int[][] TEST_DATA = { // {<year>, <week# of Jan 1>, <week# year of Jan 1>}
    { 2008, 1, 2008 }, { 2009, 1, 2009 }, { 2010, 53, 2009 }, { 2011, 52, 2010 }, { 2012, 52, 2011 }, { 2013, 1, 2013 }, { 2014, 1, 2014 } };
    for (ULocale locale : TEST_LOCALES) {
        Calendar cal = Calendar.getInstance(locale);
        // calendar type must be Gregorian
        if (!cal.getType().equals("gregorian")) {
            errln("Error: Gregorian calendar is not used for locale: " + locale);
        }
        for (int[] data : TEST_DATA) {
            cal.set(data[0], Calendar.JANUARY, 1);
            int weekNum = cal.get(Calendar.WEEK_OF_YEAR);
            int weekYear = cal.get(Calendar.YEAR_WOY);
            if (weekNum != data[1] || weekYear != data[2]) {
                errln("Error: Incorrect week of year on January 1st, " + data[0] + " for locale " + locale + ": Returned [weekNum=" + weekNum + ", weekYear=" + weekYear + "], Expected [weekNum=" + data[1] + ", weekYear=" + data[2] + "]");
            }
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) ChineseCalendar(android.icu.util.ChineseCalendar) TaiwanCalendar(android.icu.util.TaiwanCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) BuddhistCalendar(android.icu.util.BuddhistCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) Test(org.junit.Test)

Example 89 with Calendar

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

the class IBMCalendarTest method TestJB4541.

// Tests for jb 4541
@Test
public void TestJB4541() {
    ULocale loc = new ULocale("en_US");
    // !!! Shouldn't we have an api like this?
    // !!! Question: should this reflect those actually available in this copy of ICU, or
    // the list of types we assume is available?
    // String[] calTypes = Calendar.getAvailableTypes();
    final String[] calTypes = { "buddhist", "chinese", "coptic", "ethiopic", "gregorian", "hebrew", "islamic", "islamic-civil", "japanese", "roc" };
    // constructing a DateFormat with a locale indicating a calendar type should construct a
    // date format appropriate to that calendar
    final Date time = new Date();
    for (int i = 0; i < calTypes.length; ++i) {
        ULocale aLoc = loc.setKeywordValue("calendar", calTypes[i]);
        logln("locale: " + aLoc);
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, aLoc);
        logln("df type: " + df.getClass().getName() + " loc: " + df.getLocale(ULocale.VALID_LOCALE));
        Calendar cal = df.getCalendar();
        assertEquals("calendar types", cal.getType(), calTypes[i]);
        DateFormat df2 = cal.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, ULocale.US);
        logln("df2 type: " + df2.getClass().getName() + " loc: " + df2.getLocale(ULocale.VALID_LOCALE));
        assertEquals("format results", df.format(time), df2.format(time));
    }
    // dateFormat.setCalendar should throw exception if wrong format for calendar
    if (false) {
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, new ULocale("en_US@calendar=chinese"));
        logln("dateformat type: " + df.getClass().getName());
        Calendar cal = Calendar.getInstance(new ULocale("en_US@calendar=chinese"));
        logln("calendar type: " + cal.getClass().getName());
    }
}
Also used : ULocale(android.icu.util.ULocale) DateFormat(android.icu.text.DateFormat) SimpleDateFormat(android.icu.text.SimpleDateFormat) ChineseCalendar(android.icu.util.ChineseCalendar) TaiwanCalendar(android.icu.util.TaiwanCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) BuddhistCalendar(android.icu.util.BuddhistCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 90 with Calendar

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

the class IslamicTest method TestLimits.

/**
 * Test limits of the Islamic calendar
 */
@Test
public void TestLimits() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 1);
    IslamicCalendar islamic = newCivil();
    doLimitsTest(islamic, null, cal.getTime());
    doTheoreticalLimitsTest(islamic, true);
    // number of days to test - Islamic calendar starts to exhibit
    // rounding errors after year AH3954 - about 2500 years out.
    IslamicCalendar islamic2 = new IslamicCalendar();
    islamic2.setCalculationType(CalculationType.ISLAMIC);
    int testTime = TestFmwk.getExhaustiveness() <= 5 ? 20000 : 800000;
    doLimitsTest(islamic2, null, cal.getTime(), testTime);
    doTheoreticalLimitsTest(islamic2, true);
}
Also used : IslamicCalendar(android.icu.util.IslamicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) Calendar(android.icu.util.Calendar) IslamicCalendar(android.icu.util.IslamicCalendar) Test(org.junit.Test)

Aggregations

Calendar (android.icu.util.Calendar)233 Test (org.junit.Test)155 GregorianCalendar (android.icu.util.GregorianCalendar)135 Date (java.util.Date)96 JapaneseCalendar (android.icu.util.JapaneseCalendar)72 SimpleDateFormat (android.icu.text.SimpleDateFormat)69 ULocale (android.icu.util.ULocale)60 BuddhistCalendar (android.icu.util.BuddhistCalendar)53 ChineseCalendar (android.icu.util.ChineseCalendar)52 IslamicCalendar (android.icu.util.IslamicCalendar)48 TimeZone (android.icu.util.TimeZone)41 DateFormat (android.icu.text.DateFormat)37 HebrewCalendar (android.icu.util.HebrewCalendar)32 FieldPosition (java.text.FieldPosition)29 SimpleTimeZone (android.icu.util.SimpleTimeZone)26 ParsePosition (java.text.ParsePosition)23 TaiwanCalendar (android.icu.util.TaiwanCalendar)22 ParseException (java.text.ParseException)21 ChineseDateFormat (android.icu.text.ChineseDateFormat)17 IOException (java.io.IOException)16