Java Code Examples for android.icu.util.Calendar#set()

The following examples show how to use android.icu.util.Calendar#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Called when the user clicks on a day. Handles callbacks to the
 * {@link OnDayClickListener} if one is set.
 *
 * @param day the day that was clicked
 */
private boolean onDayClicked(int day) {
    if (!isValidDayOfMonth(day) || !isDayEnabled(day)) {
        return false;
    }

    if (mOnDayClickListener != null) {
        final Calendar date = Calendar.getInstance();
        date.set(mYear, mMonth, day);
        mOnDayClickListener.onDayClick(this, date);
    }

    // This is a no-op if accessibility is turned off.
    mTouchHelper.sendEventForVirtualView(day, AccessibilityEvent.TYPE_VIEW_CLICKED);
    return true;
}
 
Example 2
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestYearJump3279() {
    final long time = 1041148800000L;
    Calendar c = new GregorianCalendar();
    DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.US);

    c.setTimeInMillis(time);
    int year1 = c.get(Calendar.YEAR);
    
    logln("time: " + fmt.format(new Date(c.getTimeInMillis())));

    logln("setting DOW to " + c.getFirstDayOfWeek());
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
    logln("week: " + c.getTime());
    logln("week adjust: " + fmt.format(new Date(c.getTimeInMillis())));
    int year2 = c.get(Calendar.YEAR);
    
    if(year1 != year2) {
        errln("Error: adjusted day of week, and year jumped from " + year1 + " to " + year2);
    } else {
        logln("Year remained " + year2 + " - PASS.");
    }
}
 
Example 3
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @bug 4103340
 * @bug 4138203
 * This bug really only works in Locale.US, since that's what the locale
 * used for Date.toString() is.  Bug 4138203 reports that it fails on Korean
 * NT; it would actually have failed on any non-US locale.  Now it should
 * work on all locales.
 */
@Test
public void Test4103340() {

    // choose a date that is the FIRST of some month 
    // and some arbitrary time
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(1997, 3, 1, 1, 1, 1);
    Date d = cal.getTime(); 
    SimpleDateFormat df = new SimpleDateFormat("MMMM", Locale.US);
    String s = d.toString();
    StringBuffer s2 = new StringBuffer("");
    FieldPosition pos = new FieldPosition(0);
    s2 = df.format(d, s2, pos);
    logln("Date=" + s); 
    logln("DF=" + s2);
    String substr = s2.substring(0,2);
    if (s.indexOf(substr) == -1)
      errln("Months should match");
}
 
Example 4
Source File: DangiTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Test minimum and maximum functions.
 */
@Test
public void TestLimits() {
    // The number of days and the start date can be adjusted
    // arbitrarily to either speed up the test or make it more
    // thorough, but try to test at least a full year, preferably a
    // full non-leap and a full leap year.

    // Final parameter is either number of days, if > 0, or test
    // duration in seconds, if < 0.
    Calendar tempcal = Calendar.getInstance();
    tempcal.clear();
    tempcal.set(1989, Calendar.NOVEMBER, 1);
    Calendar dangi = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
    doLimitsTest(dangi, null, tempcal.getTime());
    doTheoreticalLimitsTest(dangi, true);
}
 
Example 5
Source File: DateIntervalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestTicket9919GetInstance() {
    // Creating a DateIntervalFormat with a custom DateIntervalInfo
    // object used to corrupt the cache.
    DateIntervalFormat dif = DateIntervalFormat.getInstance(
            "yMd", ULocale.ENGLISH);
    Calendar from = Calendar.getInstance();
    Calendar to = Calendar.getInstance();
    from.set(2013, 3, 26);
    to.set(2013, 3, 28);

    // Save. This is the correct answer
    String expected =
            dif.format(from, to, new StringBuffer(), new FieldPosition(0))
            .toString();

    // Now create a DateIntervalFormat with same skeleton and
    // locale, but with a custom DateIntervalInfo. This used
    // to corrupt the cache.
    DateIntervalInfo dateIntervalInfo =
            new DateIntervalInfo(ULocale.ENGLISH);
    dateIntervalInfo.setIntervalPattern(
            "yMd", Calendar.DATE, "M/d/y \u2013 d");
    DateIntervalFormat.getInstance(
            "yMd", ULocale.ENGLISH, dateIntervalInfo);

    // Now create a DateIntervalFormat with same skeleton and
    // locale, but with default DateIntervalInfo. The cache should
    // not be corrupted, and we should get the same answer as before.
    dif = DateIntervalFormat.getInstance("yMd", ULocale.ENGLISH);

    assertEquals(
            "Custom DateIntervalInfo objects should not mess up cache",
            expected,
            dif.format(from, to, new StringBuffer(), new FieldPosition(0))
            .toString()); 

}
 
Example 6
Source File: IBMCalendarTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test behavior of fieldDifference around leap years.  Also test a large
 * field difference to check binary search.
 */
@Test
public void TestLeapFieldDifference() {
    Calendar cal = Calendar.getInstance();
    cal.set(2004, Calendar.FEBRUARY, 29);
    Date date2004 = cal.getTime();
    cal.set(2000, Calendar.FEBRUARY, 29);
    Date date2000 = cal.getTime();
    int y = cal.fieldDifference(date2004, Calendar.YEAR);
    int d = cal.fieldDifference(date2004, Calendar.DAY_OF_YEAR);
    if (d == 0) {
        logln("Ok: 2004/Feb/29 - 2000/Feb/29 = " + y + " years, " + d + " days");
    } else {
        errln("FAIL: 2004/Feb/29 - 2000/Feb/29 = " + y + " years, " + d + " days");
    }
    cal.setTime(date2004);
    y = cal.fieldDifference(date2000, Calendar.YEAR);
    d = cal.fieldDifference(date2000, Calendar.DAY_OF_YEAR);
    if (d == 0) {
        logln("Ok: 2000/Feb/29 - 2004/Feb/29 = " + y + " years, " + d + " days");
    } else {
        errln("FAIL: 2000/Feb/29 - 2004/Feb/29 = " + y + " years, " + d + " days");
    }
    // Test large difference
    cal.set(2001, Calendar.APRIL, 5); // 2452005
    Date ayl = cal.getTime();
    cal.set(1964, Calendar.SEPTEMBER, 7); // 2438646
    Date asl = cal.getTime();
    d = cal.fieldDifference(ayl, Calendar.DAY_OF_MONTH);
    cal.setTime(ayl);
    int d2 = cal.fieldDifference(asl, Calendar.DAY_OF_MONTH);
    if (d == -d2 && d == 13359) {
        logln("Ok: large field difference symmetrical " + d);
    } else {
        logln("FAIL: large field difference incorrect " + d + ", " + d2 +
              ", expect +/- 13359");
    }
}
 
Example 7
Source File: HebrewTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test limits of the Hebrew calendar
 */
@Test
public void TestLimits() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 1);
    HebrewCalendar hebrew = new HebrewCalendar();
    doLimitsTest(hebrew, null, cal.getTime());
    doTheoreticalLimitsTest(hebrew, true);
}
 
Example 8
Source File: DateIntervalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestTicket9919Setter() {

    // Creating a DateIntervalFormat with a custom DateIntervalInfo
    // object used to corrupt the cache.
    DateIntervalFormat dif = DateIntervalFormat.getInstance(
            "yMd", ULocale.ENGLISH);
    Calendar from = Calendar.getInstance();
    Calendar to = Calendar.getInstance();
    from.set(2013, 3, 26);
    to.set(2013, 3, 28);

    // Save. This is the correct answer
    String expected =
            dif.format(from, to, new StringBuffer(), new FieldPosition(0))
            .toString();

    // Now create a DateIntervalFormat with same skeleton and
    // locale, but with a custom DateIntervalInfo. This used
    // to corrupt the cache.
    DateIntervalInfo dateIntervalInfo =
            new DateIntervalInfo(ULocale.ENGLISH);
    dateIntervalInfo.setIntervalPattern(
            "yMd", Calendar.DATE, "M/d/y \u2013 d");
    DateIntervalFormat bad = DateIntervalFormat.getInstance(
            "yMd", ULocale.ENGLISH);
    bad.setDateIntervalInfo(dateIntervalInfo);

    // Now create a DateIntervalFormat with same skeleton and
    // locale, but with default DateIntervalInfo. The cache should
    // not be corrupted, and we should get the same answer as before.
    dif = DateIntervalFormat.getInstance("yMd", ULocale.ENGLISH);
    assertEquals(
            "Custom DateIntervalInfo objects should not mess up cache",
            expected,
            dif.format(from, to, new StringBuffer(), new FieldPosition(0))
            .toString()); 
}
 
Example 9
Source File: DateIntervalFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestTicket9914() {
    DateIntervalInfo dateIntervalInfo =
            new DateIntervalInfo(ULocale.ENGLISH);

    Calendar from = Calendar.getInstance();
    Calendar to = Calendar.getInstance();
    from.set(113, 3, 26);
    to.set(113, 3, 28);
    DateIntervalFormat dif = DateIntervalFormat.getInstance(
            "yyyyMd", ULocale.ENGLISH, dateIntervalInfo);
    assertEquals(
            "yyyyMd skeleton.",
            "4/26/0113 \u2013 4/28/0113",
            dif.format(from, to, new StringBuffer(), new FieldPosition(0))
            .toString());

    dif = DateIntervalFormat.getInstance(
            "yyMd", ULocale.ENGLISH, dateIntervalInfo);
    assertEquals(
            "yyMd skeleton.",
            "4/26/13 \u2013 4/28/13",
            dif.format(from, to, new StringBuffer(), new FieldPosition(0))
            .toString());

    dif = DateIntervalFormat.getInstance(
            "yMd", ULocale.ENGLISH, dateIntervalInfo);
    assertEquals(
            "yMd skeleton.",
            "4/26/113 \u2013 4/28/113",
            dif.format(from, to, new StringBuffer(), new FieldPosition(0))
            .toString());
}
 
Example 10
Source File: TimeZoneTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestVariousAPI518()
{
    TimeZone time_zone = TimeZone.getTimeZone("PST");
    Calendar cal = Calendar.getInstance();
    cal.set(1997, Calendar.APRIL, 30);
    Date d = cal.getTime();

    logln("The timezone is " + time_zone.getID());

    if (time_zone.inDaylightTime(d) != true)
        errln("FAIL: inDaylightTime returned false");

    if (time_zone.useDaylightTime() != true)
        errln("FAIL: useDaylightTime returned false");

    if (time_zone.getRawOffset() != -8*millisPerHour)
        errln( "FAIL: getRawOffset returned wrong value");

    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(d);
    if (time_zone.getOffset(GregorianCalendar.AD, gc.get(GregorianCalendar.YEAR), gc.get(GregorianCalendar.MONTH),
                            gc.get(GregorianCalendar.DAY_OF_MONTH),
                            gc.get(GregorianCalendar.DAY_OF_WEEK), 0)
        != -7*millisPerHour)
        errln("FAIL: getOffset returned wrong value");
}
 
Example 11
Source File: TimeZoneRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void Test4073215() {
    SimpleTimeZone z = new SimpleTimeZone(0, "GMT");
    if (z.useDaylightTime())
        errln("Fail: Fix test to start with non-DST zone");
    z.setStartRule(Calendar.FEBRUARY, 1, Calendar.SUNDAY, 0);
    z.setEndRule(Calendar.MARCH, -1, Calendar.SUNDAY, 0);
    if (!z.useDaylightTime())
        errln("Fail: DST not active");
    Calendar tempcal = Calendar.getInstance();
    tempcal.clear();
    tempcal.setTimeZone(z);
    tempcal.set(1997, Calendar.JANUARY, 31);
    Date d1 = tempcal.getTime();
    if (z.inDaylightTime(d1)) {
        errln("Fail: DST not working as expected");
    } 

    tempcal.set(1997, Calendar.MARCH, 1);
    Date d2 = tempcal.getTime();
    if (!z.inDaylightTime(d2)) {
        errln("Fail: DST not working as expected");
    }
    tempcal.clear();
    tempcal.set(1997, Calendar.MARCH, 31);
    Date d3 = tempcal.getTime();
    if (z.inDaylightTime(d3)) {
        errln("Fail: DST not working as expected");
    } 
}
 
Example 12
Source File: EthiopicTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test limits of the Coptic calendar
 */
@Test
public void TestLimits() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 1);
    EthiopicCalendar ethiopic = new EthiopicCalendar();
    doLimitsTest(ethiopic, null, cal.getTime());
    doTheoreticalLimitsTest(ethiopic, true);
}
 
Example 13
Source File: DangiTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test the behavior of fields that are out of range.
 */
@Test
public void TestOutOfRange() {
    int[] DATA = new int[] {
        // Input       Output
        4334, 13,  1,   4335,  1,  1,
        4334, 18,  1,   4335,  6,  1,
        4335,  0,  1,   4334, 12,  1,
        4335, -6,  1,   4334,  6,  1,
        4334,  1, 32,   4334,  2,  2, // 1-4334 has 30 days
        4334,  2, -1,   4334,  1, 29,
    };
    Calendar cal = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
    for (int i = 0; i < DATA.length;) {
        int y1 = DATA[i++];
        int m1 = DATA[i++] - 1;
        int d1 = DATA[i++];
        int y2 = DATA[i++];
        int m2 = DATA[i++] - 1;
        int d2 = DATA[i++];
        cal.clear();
        cal.set(Calendar.EXTENDED_YEAR, y1);
        cal.set(MONTH, m1);
        cal.set(DATE, d1);
        int y = cal.get(Calendar.EXTENDED_YEAR);
        int m = cal.get(MONTH);
        int d = cal.get(DATE);
        if (y != y2 || m != m2 || d != d2) {
            errln("Fail: " + y1 + "/" + (m1 + 1) + "/" + d1 + " resolves to " + y + "/" + (m + 1) + "/" + d
                    + ", expected " + y2 + "/" + (m2 + 1) + "/" + d2);
        } else if (isVerbose()) {
            logln("OK: " + y1 + "/" + (m1 + 1) + "/" + d1 + " resolves to " + y + "/" + (m + 1) + "/" + d);
        }
    }
}
 
Example 14
Source File: IBMCalendarTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test limits of the Taiwan calendar.
 */
@Test
public void TestTaiwanLimits() {
    // Final parameter is either number of days, if > 0, or test
    // duration in seconds, if < 0.
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 1);
    TaiwanCalendar taiwan = new TaiwanCalendar();
    doLimitsTest(taiwan, null, cal.getTime());
    doTheoreticalLimitsTest(taiwan, false);
}
 
Example 15
Source File: TimePicker.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
@Override
public long getDate() {
    Calendar cal = Calendar.getInstance(mLocale);
    cal.set(Calendar.HOUR_OF_DAY, getHour());
    cal.set(Calendar.MINUTE, getMinute());
    return cal.getTimeInMillis();
}
 
Example 16
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @bug 4104136
 */
@Test
public void Test4104136() {
    SimpleDateFormat sdf = new SimpleDateFormat();
    String pattern = "'time' hh:mm";
    sdf.applyPattern(pattern);
    logln("pattern: \"" + pattern + "\"");
    String strings[] = {"time 10:30", "time 10:x", "time 10x"};
    ParsePosition ppos[] = {new ParsePosition(10), new ParsePosition(0), new ParsePosition(0)};
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(1970, Calendar.JANUARY, 1, 10, 30);
    Date dates[] = {cal.getTime(), new Date(-1), new Date(-1)};
    for (int i = 0; i < 3; i++) {
        String text = strings[i];
        ParsePosition finish = ppos[i];
        Date exp = dates[i];
        ParsePosition pos = new ParsePosition(0);
        Date d = sdf.parse(text, pos);
        logln(" text: \"" + text + "\"");
        logln(" index: %d" + pos.getIndex());
        logln(" result: " + d);
        if (pos.getIndex() != finish.getIndex())
            errln("Fail: Expected pos " + finish.getIndex());
        if (!((d == null && exp.equals(new Date(-1))) || (d.equals(exp))))
            errln( "Fail: Expected result " + exp);
    }
}
 
Example 17
Source File: IBMCalendarTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Run a test of a quasi-Gregorian calendar.  This is a calendar
 * that behaves like a Gregorian but has different year/era mappings.
 * The int[] data array should have the format:
 *
 * { era, year, gregorianYear, month, dayOfMonth, ... }
 */
void quasiGregorianTest(Calendar cal, int[] data) {
    // As of JDK 1.4.1_01, using the Sun JDK GregorianCalendar as
    // a reference throws us off by one hour.  This is most likely
    // due to the JDK 1.4 incorporation of historical time zones.
    //java.util.Calendar grego = java.util.Calendar.getInstance();
    Calendar grego = Calendar.getInstance();
    for (int i=0; i<data.length; ) {
        int era = data[i++];
        int year = data[i++];
        int gregorianYear = data[i++];
        int month = data[i++];
        int dayOfMonth = data[i++];

        grego.clear();
        grego.set(gregorianYear, month, dayOfMonth);
        Date D = grego.getTime();

        cal.clear();
        cal.set(Calendar.ERA, era);
        cal.set(year, month, dayOfMonth);
        Date d = cal.getTime();
        if (d.equals(D)) {
            logln("OK: " + era + ":" + year + "/" + (month+1) + "/" + dayOfMonth +
                  " => " + d);
        } else {
            errln("Fail: " + era + ":" + year + "/" + (month+1) + "/" + dayOfMonth +
                  " => " + d + ", expected " + D);
        }

        cal.clear();
        cal.setTime(D);
        int e = cal.get(Calendar.ERA);
        int y = cal.get(Calendar.YEAR);
        if (y == year && e == era) {
            logln("OK: " + D + " => " + cal.get(Calendar.ERA) + ":" +
                  cal.get(Calendar.YEAR) + "/" +
                  (cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.DATE));
        } else {
            logln("Fail: " + D + " => " + cal.get(Calendar.ERA) + ":" +
                  cal.get(Calendar.YEAR) + "/" +
                  (cal.get(Calendar.MONTH)+1) + "/" + cal.get(Calendar.DATE) +
                  ", expected " + era + ":" + year + "/" + (month+1) + "/" +
                  dayOfMonth);
        }
    }
}
 
Example 18
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@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)));
    // Note: This test had a bug in it. It wanted h1!=h2, when
    // what was meant was h1!=p. Fixed this concurrent with fix
    // 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");
}
 
Example 19
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @bug 4065240
 */
@Test
public void Test4065240() {
    Date curDate;
    DateFormat shortdate, fulldate;
    String strShortDate, strFullDate;
    Locale saveLocale = Locale.getDefault();
    TimeZone saveZone = TimeZone.getDefault();

    try {
        Locale curLocale = new Locale("de", "DE");
        Locale.setDefault(curLocale);
        // {sfb} adoptDefault instead of setDefault
        //TimeZone.setDefault(TimeZone.createTimeZone("EST"));
        TimeZone.setDefault(TimeZone.getTimeZone("EST"));
        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(98 + 1900, 0, 1);
        curDate = cal.getTime();
        shortdate = DateFormat.getDateInstance(DateFormat.SHORT);
        fulldate = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
        strShortDate = "The current date (short form) is ";
        String temp;
        temp = shortdate.format(curDate);
        strShortDate += temp;
        strFullDate = "The current date (long form) is ";
        String temp2 = fulldate.format(curDate);
        strFullDate += temp2;

        logln(strShortDate);
        logln(strFullDate);

        // {sfb} What to do with resource bundle stuff?????

        // Check to see if the resource is present; if not, we can't test
        //ResourceBundle bundle = //The variable is never used
        //    ICULocaleData.getBundle("DateFormatZoneData", curLocale); 

        // {sfb} API change to ResourceBundle -- add getLocale()
        /*if (bundle.getLocale().getLanguage().equals("de")) {
            // UPDATE THIS AS ZONE NAME RESOURCE FOR <EST> in de_DE is updated
            if (!strFullDate.endsWith("GMT-05:00"))
                errln("Fail: Want GMT-05:00");
        } else {
            logln("*** TEST COULD NOT BE COMPLETED BECAUSE DateFormatZoneData ***");
            logln("*** FOR LOCALE de OR de_DE IS MISSING ***");
        }*/
    } catch (Exception e) {
        logln(e.getMessage());
    } finally {
        Locale.setDefault(saveLocale);
        TimeZone.setDefault(saveZone);
    }

}
 
Example 20
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @bug 4056591
 * Verify the function of the [s|g]et2DigitYearStart() API.
 */
@Test
public void Test4056591() {

    try {
        SimpleDateFormat fmt = new SimpleDateFormat("yyMMdd", Locale.US);
        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(1809, Calendar.DECEMBER, 25);
        Date start = cal.getTime();
        fmt.set2DigitYearStart(start);
        if ((fmt.get2DigitYearStart() != start))
            errln("get2DigitYearStart broken");
        cal.clear();
        cal.set(1809, Calendar.DECEMBER, 25);
        Date d1 = cal.getTime();
        cal.clear();
        cal.set(1909, Calendar.DECEMBER, 24);
        Date d2 = cal.getTime();
        cal.clear();
        cal.set(1809, Calendar.DECEMBER, 26);
        Date d3 = cal.getTime();
        cal.clear();
        cal.set(1861, Calendar.DECEMBER, 25);
        Date d4 = cal.getTime();
        
        Date dates[] = {d1, d2, d3, d4};

        String strings[] = {"091225", "091224", "091226", "611225"};            

        for (int i = 0; i < 4; i++) {
            String s = strings[i];
            Date exp = dates[i];
            Date got = fmt.parse(s);
            logln(s + " . " + got + "; exp " + exp);
            if (got.getTime() != exp.getTime())
                errln("set2DigitYearStart broken");
        }
    } catch (ParseException e) {
        errln("Fail: " + e);
        e.printStackTrace();
    }
}