Search in sources :

Example 51 with Calendar

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

the class CalendarRegressionTest method Test4096231.

@Test
public void Test4096231() {
    TimeZone GMT = TimeZone.getTimeZone("GMT");
    TimeZone PST = TimeZone.getTimeZone("PST");
    int sec = 0, min = 0, hr = 0, day = 1, month = 10, year = 1997;
    Calendar cal1 = new GregorianCalendar(PST);
    cal1.setTime(new Date(880698639000L));
    int p;
    logln("PST 1 is: " + (p = cal1.get(Calendar.HOUR_OF_DAY)));
    cal1.setTimeZone(GMT);
    // Issue 1: Changing the timezone doesn't change the
    // represented time.
    int h1, h2;
    logln("GMT 1 is: " + (h1 = cal1.get(Calendar.HOUR_OF_DAY)));
    cal1.setTime(new Date(880698639000L));
    logln("GMT 2 is: " + (h2 = cal1.get(Calendar.HOUR_OF_DAY)));
    // to 4177484.
    if (p == h1 || h1 != h2)
        errln("Fail: Hour same in different zones");
    Calendar cal2 = new GregorianCalendar(GMT);
    Calendar cal3 = new GregorianCalendar(PST);
    cal2.set(Calendar.MILLISECOND, 0);
    cal3.set(Calendar.MILLISECOND, 0);
    cal2.set(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), cal1.get(Calendar.DAY_OF_MONTH), cal1.get(Calendar.HOUR_OF_DAY), cal1.get(Calendar.MINUTE), cal1.get(Calendar.SECOND));
    long t1, t2, t3, t4;
    logln("RGMT 1 is: " + (t1 = cal2.getTime().getTime()));
    cal3.set(year, month, day, hr, min, sec);
    logln("RPST 1 is: " + (t2 = cal3.getTime().getTime()));
    cal3.setTimeZone(GMT);
    logln("RGMT 2 is: " + (t3 = cal3.getTime().getTime()));
    cal3.set(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), cal1.get(Calendar.DAY_OF_MONTH), cal1.get(Calendar.HOUR_OF_DAY), cal1.get(Calendar.MINUTE), cal1.get(Calendar.SECOND));
    // Issue 2: Calendar continues to use the timezone in its
    // constructor for set() conversions, regardless
    // of calls to setTimeZone()
    logln("RGMT 3 is: " + (t4 = cal3.getTime().getTime()));
    if (t1 == t2 || t1 != t4 || t2 != t3)
        errln("Fail: Calendar zone behavior faulty");
}
Also used : SimpleTimeZone(android.icu.util.SimpleTimeZone) TimeZone(android.icu.util.TimeZone) GregorianCalendar(android.icu.util.GregorianCalendar) Calendar(android.icu.util.Calendar) GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 52 with Calendar

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

the class CalendarRegressionTest method TestCalendarType6816.

@Test
public void TestCalendarType6816() {
    Locale loc = new Locale("en", "TH");
    Calendar cal = Calendar.getInstance(loc);
    String calType = cal.getType();
    // Android patch: Force default Gregorian calendar.
    if (!calType.equals("gregorian")) {
        errln("FAIL: Calendar type for en_TH should still be gregorian");
    }
// Android patch end.
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) GregorianCalendar(android.icu.util.GregorianCalendar) Calendar(android.icu.util.Calendar) Test(org.junit.Test)

Example 53 with Calendar

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

the class JapaneseTest method TestJapaneseYear3282.

@Test
public void TestJapaneseYear3282() {
    Calendar c = Calendar.getInstance(ULocale.ENGLISH);
    c.set(2003, Calendar.SEPTEMBER, 25);
    JapaneseCalendar jcal = new JapaneseCalendar();
    // jcal.setTime(new Date(1187906308151L));  alternate value
    jcal.setTime(c.getTime());
    logln("Now is: " + jcal.getTime());
    c.setTime(jcal.getTime());
    int nowYear = c.get(Calendar.YEAR);
    logln("Now year: " + nowYear);
    SimpleDateFormat jdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(jcal, SimpleDateFormat.DEFAULT, Locale.getDefault());
    jdf.applyPattern("G yy/MM/dd");
    String text = jdf.format(jcal.getTime());
    logln("Now is: " + text + " (in Japan)");
    try {
        Date date = jdf.parse(text);
        logln("But is this not the date?: " + date);
        c.setTime(date);
        int thenYear = c.get(Calendar.YEAR);
        logln("Then year: " + thenYear);
        if (thenYear != nowYear) {
            errln("Nowyear " + nowYear + " is not thenyear " + thenYear);
        } else {
            logln("Nowyear " + nowYear + " == thenyear " + thenYear);
        }
    } catch (java.text.ParseException ex) {
        ex.printStackTrace();
    }
}
Also used : Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) ParseException(java.text.ParseException) SimpleDateFormat(android.icu.text.SimpleDateFormat) JapaneseCalendar(android.icu.util.JapaneseCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 54 with Calendar

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

the class CopticTest method TestYear.

@Test
public void TestYear() {
    // Gregorian Calendar
    Calendar gCal = new GregorianCalendar();
    Date gToday = gCal.getTime();
    gCal.add(GregorianCalendar.MONTH, 2);
    Date gFuture = gCal.getTime();
    DateFormat gDF = DateFormat.getDateInstance(gCal, DateFormat.FULL);
    logln("gregorian calendar: " + gDF.format(gToday) + " + 2 months = " + gDF.format(gFuture));
    // Coptic Calendar
    CopticCalendar cCal = new CopticCalendar();
    Date cToday = cCal.getTime();
    cCal.add(CopticCalendar.MONTH, 2);
    Date cFuture = cCal.getTime();
    DateFormat cDF = DateFormat.getDateInstance(cCal, DateFormat.FULL);
    logln("coptic calendar: " + cDF.format(cToday) + " + 2 months = " + cDF.format(cFuture));
    // EthiopicCalendar
    EthiopicCalendar eCal = new EthiopicCalendar();
    Date eToday = eCal.getTime();
    // add 2 months
    eCal.add(EthiopicCalendar.MONTH, 2);
    eCal.setAmeteAlemEra(false);
    Date eFuture = eCal.getTime();
    DateFormat eDF = DateFormat.getDateInstance(eCal, DateFormat.FULL);
    logln("ethiopic calendar: " + eDF.format(eToday) + " + 2 months = " + eDF.format(eFuture));
}
Also used : EthiopicCalendar(android.icu.util.EthiopicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) CopticCalendar(android.icu.util.CopticCalendar) EthiopicCalendar(android.icu.util.EthiopicCalendar) Calendar(android.icu.util.Calendar) SimpleDateFormat(android.icu.text.SimpleDateFormat) DateFormat(android.icu.text.DateFormat) GregorianCalendar(android.icu.util.GregorianCalendar) CopticCalendar(android.icu.util.CopticCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 55 with Calendar

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

the class CopticTest method TestLimits.

/**
 * Test limits of the Coptic calendar
 */
@Test
public void TestLimits() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 1);
    CopticCalendar coptic = new CopticCalendar();
    doLimitsTest(coptic, null, cal.getTime());
    doTheoreticalLimitsTest(coptic, true);
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) CopticCalendar(android.icu.util.CopticCalendar) EthiopicCalendar(android.icu.util.EthiopicCalendar) Calendar(android.icu.util.Calendar) CopticCalendar(android.icu.util.CopticCalendar) 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