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

The following examples show how to use android.icu.util.Calendar#get() . 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: CompatibilityTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
void verify765(String msg, Calendar c, int year, int month, int day) {
    int cy = c.get(Calendar.YEAR); // NEWCAL
    int cm = c.get(Calendar.MONTH);
    int cd = c.get(Calendar.DATE);
    if (cy == year &&
        cm == month &&
        cd == day) {
        logln("PASS: " + msg + c.getTime());
    }
    else {
        errln("FAIL: " + msg + cy + "/" + (cm+1) + "/" + cd +
              "=" + c.getTime() +
              "; expected " +
              year + "/" + (month+1) + "/" + day);
    }
}
 
Example 2
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestParsing() {
    String pattern = "EEE-WW-MMMM-yyyy";
    String text = "mon-02-march-2011";
    int expectedDay = 7;

    SimpleDateFormat format = new SimpleDateFormat(pattern);
    Calendar cal = GregorianCalendar.getInstance(Locale.US);
    ParsePosition pos = new ParsePosition(0);
    
    try {
        format.parse(text, cal, pos);
    } catch (Exception e) {
        errln("Fail parsing:  " + e);
    }

    if (cal.get(Calendar.DAY_OF_MONTH) != expectedDay) {
        errln("Parsing failed: day of month should be '7' with pattern: \"" + pattern + "\" for text: \"" + text + "\"");
    }
}
 
Example 3
Source File: TestCase.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Determine whether the fields of this calendar
 * are the same as that of the other calendar.  This method is useful
 * for determining whether the other calendar's computeFields method
 * works properly.  For example:
 * <pre>
 *    Calendar testCalendar = ...
 *    TestCase case = ...
 *    case.applyTime(testCalendar);
 *    if (!case.fieldsEqual(testCalendar)) {
 *        // Error!
 *    }
 * </pre>
 * 
 * @see #applyTime
 */
public boolean fieldsEqual(Calendar c, TestLog log) {
    for (int i=0; i < c.getFieldCount(); i++) {
        if (isSet(i) && get(i) != c.get(i)) {
            StringBuffer buf = new StringBuffer();
            buf.append("Fail: " + CalendarTestFmwk.fieldName(i) + " = " + c.get(i) +
                      ", expected " + get(i));
            for (int j=0; j<c.getFieldCount(); ++j) {
                if (isSet(j)) {
                    if (get(j) == c.get(j)) {
                        buf.append("\n  ok: " + CalendarTestFmwk.fieldName(j) + " = " +
                                  c.get(j));
                    } else {
                        buf.append("\n  fail: " + CalendarTestFmwk.fieldName(j) + " = " +
                                  c.get(j) + ", expected " + get(j));
                    }
                }
            }
            // TODO(junit): blanked out TestLog
            //log.errln(buf.toString());
            return false;
        }
    }
    
    return true;
}
 
Example 4
Source File: DangiTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Make sure no Gregorian dates map to Chinese 1-based day of
 * month zero.  This was a problem with some of the astronomical
 * new moon determinations.
 */
@Test
public void TestZeroDOM() {
    Calendar cal = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
    GregorianCalendar greg = new GregorianCalendar(1989, Calendar.SEPTEMBER, 1);
    logln("Start: " + greg.getTime());
    for (int i=0; i<1000; ++i) {
        cal.setTimeInMillis(greg.getTimeInMillis());
        if (cal.get(Calendar.DAY_OF_MONTH) == 0) {
            errln("Fail: " + greg.getTime() + " -> " +
                  cal.get(Calendar.YEAR) + "/" +
                  cal.get(Calendar.MONTH) +
                  (cal.get(Calendar.IS_LEAP_MONTH)==1?"(leap)":"") +
                  "/" + cal.get(Calendar.DAY_OF_MONTH));
        }
        greg.add(Calendar.DAY_OF_YEAR, 1);
    }
    logln("End: " + greg.getTime());
}
 
Example 5
Source File: DayPickerPagerAdapter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the selected day.
 *
 * @param day the selected day
 */
public void setSelectedDay(@Nullable Calendar day) {
    final int oldPosition = getPositionForDay(mSelectedDay);
    final int newPosition = getPositionForDay(day);

    // Clear the old position if necessary.
    if (oldPosition != newPosition && oldPosition >= 0) {
        final ViewHolder oldMonthView = mItems.get(oldPosition, null);
        if (oldMonthView != null) {
            oldMonthView.calendar.setSelectedDay(-1);
        }
    }

    // Set the new position.
    if (newPosition >= 0) {
        final ViewHolder newMonthView = mItems.get(newPosition, null);
        if (newMonthView != null) {
            final int dayOfMonth = day.get(Calendar.DAY_OF_MONTH);
            newMonthView.calendar.setSelectedDay(dayOfMonth);
        }
    }

    mSelectedDay = day;
}
 
Example 6
Source File: SimpleDateFormat.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * check whether the i-th item in 2 calendar is in different value.
 *
 * It is supposed to be used only by CLDR survey tool.
 * It is used by intervalFormatByAlgorithm().
 *
 * @param fromCalendar   one calendar
 * @param toCalendar     the other calendar
 * @param items          pattern items
 * @param i              the i-th item in pattern items
 * @exception IllegalArgumentException when there is non-recognized
 *                                     pattern letter
 * @return               true is i-th item in 2 calendar is in different
 *                       value, false otherwise.
 */
private boolean diffCalFieldValue(Calendar fromCalendar,
                                  Calendar toCalendar,
                                  Object[] items,
                                  int i) throws IllegalArgumentException {
    if ( items[i] instanceof String) {
        return false;
    }
    PatternItem item = (PatternItem)items[i];
    char ch = item.type;
    int patternCharIndex = getIndexFromChar(ch);
    if (patternCharIndex == -1) {
        throw new IllegalArgumentException("Illegal pattern character " +
                                           "'" + ch + "' in \"" +
                                           pattern + '"');
    }

    final int field = PATTERN_INDEX_TO_CALENDAR_FIELD[patternCharIndex];
    if (field >= 0) {
        int value = fromCalendar.get(field);
        int value_2 = toCalendar.get(field);
        if ( value != value_2 ) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: TimeZoneRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * CANNOT REPRODUDE
 *
 * Yet another _alleged_ bug in TimeZone.getOffset(), a method that never
 * should have been made public.  It's simply too hard to use correctly.
 *
 * The original test code failed to do the following:
 * (1) Call Calendar.setTime() before getting the fields!
 * (2) Use the right millis (as usual) for getOffset(); they were passing
 *     in the MILLIS field, instead of the STANDARD MILLIS IN DAY.
 * When you fix these two problems, the test passes, as expected.
 */
@Test
public void Test4126678() {
// Note: this test depends on the PST time zone.
TimeZone initialZone = TimeZone.getDefault();
    Calendar cal = Calendar.getInstance();
    TimeZone tz = TimeZone.getTimeZone("PST");
TimeZone.setDefault(tz);
    cal.setTimeZone(tz);

    java.util.Calendar tempcal = java.util.Calendar.getInstance();
    tempcal.clear();
    tempcal.set(1998, Calendar.APRIL, 5, 10, 0);
    Date dt = tempcal.getTime();
// the dt value is local time in PST.
    if (!tz.inDaylightTime(dt))
        errln("We're not in Daylight Savings Time and we should be.\n");

    cal.setTime(dt);
    int era = cal.get(Calendar.ERA);
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH);
    int day = cal.get(Calendar.DATE);
    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
    int millis = cal.get(Calendar.MILLISECOND) +
        (cal.get(Calendar.SECOND) +
         (cal.get(Calendar.MINUTE) +
          (cal.get(Calendar.HOUR) * 60) * 60) * 1000) -
        cal.get(Calendar.DST_OFFSET);

    long offset = tz.getOffset(era, year, month, day, dayOfWeek, millis);
    long raw_offset = tz.getRawOffset();
    if (offset == raw_offset)
        errln("Offsets should not match when in DST");

// restore the initial time zone so that this test case
// doesn't affect the others.
TimeZone.setDefault(initialZone);
}
 
Example 8
Source File: IBMCalendarTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
static CalFields createFrom(Calendar cal) {
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int min = cal.get(Calendar.MINUTE);
    int sec = cal.get(Calendar.SECOND);

    return new CalFields(year, month, day, hour, min, sec);
}
 
Example 9
Source File: YearPickerView.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
public void setRange(Calendar minDate, Calendar maxDate) {
    final int minYear = minDate.get(Calendar.YEAR);
    final int count = maxDate.get(Calendar.YEAR) - minYear + 1;

    if (mMinYear != minYear || mCount != count) {
        mMinYear = minYear;
        mCount = count;
        notifyDataSetInvalidated();
    }
}
 
Example 10
Source File: CalendarTestFmwk.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Process test cases for <code>add</code> and <code>roll</code> methods.
 * Each test case is an array of integers, as follows:
 * <ul>
 *  <li>0: input year
 *  <li>1:       month  (zero-based)
 *  <li>2:       day
 *  <li>3: field to roll or add to
 *  <li>4: amount to roll or add
 *  <li>5: result year
 *  <li>6:        month (zero-based)
 *  <li>7:        day
 * </ul>
 * For example:
 * <pre>
 *   //       input                add by          output
 *   //  year  month     day     field amount    year  month     day
 *   {   5759, HESHVAN,   2,     MONTH,   1,     5759, KISLEV,    2 },
 * </pre>
 *
 * @param roll  <code>true</code> or <code>ROLL</code> to test the <code>roll</code> method;
 *              <code>false</code> or <code>ADD</code> to test the <code>add</code method
 */
protected void doRollAdd(boolean roll, Calendar cal, int[][] tests)
{
    String name = roll ? "rolling" : "adding";
    
    for (int i = 0; i < tests.length; i++) {
        int[] test = tests[i];

        cal.clear();
        if (cal instanceof ChineseCalendar) {
            cal.set(Calendar.EXTENDED_YEAR, test[0]);
            cal.set(Calendar.MONTH, test[1]);
            cal.set(Calendar.DAY_OF_MONTH, test[2]);
        } else {
            cal.set(test[0], test[1], test[2]);
        }
        double day0 = getJulianDay(cal);
        if (roll) {
            cal.roll(test[3], test[4]);
        } else {
            cal.add(test[3], test[4]);
        }
        int y = cal.get(cal instanceof ChineseCalendar ?
                        Calendar.EXTENDED_YEAR : YEAR);
        if (y != test[5] || cal.get(MONTH) != test[6]
                || cal.get(DATE) != test[7])
        {
            errln("Fail: " + name + " "+ ymdToString(test[0], test[1], test[2])
                + " (" + day0 + ")"
                + " " + FIELD_NAME[test[3]] + " by " + test[4]
                + ": expected " + ymdToString(test[5], test[6], test[7])
                + ", got " + ymdToString(cal));
        } else if (isVerbose()) {
            logln("OK: " + name + " "+ ymdToString(test[0], test[1], test[2])
                + " (" + day0 + ")"
                + " " + FIELD_NAME[test[3]] + " by " + test[4]
                + ": got " + ymdToString(cal));
        }
    }
}
 
Example 11
Source File: CompatibilityTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private void auxMapping(Calendar cal, int y, int m, int d) {
    cal.clear();
    cal.set(y, m, d);
    long millis = cal.getTime().getTime();
    cal.setTime(new Date(millis));
    int year2 = cal.get(Calendar.YEAR);
    int month2 = cal.get(Calendar.MONTH);
    int dom2 = cal.get(Calendar.DAY_OF_MONTH);
    if (y != year2 || m != month2 || dom2 != d)
        errln("Round-trip failure: " + y + "-" + (m+1) + "-"+d+" =>ms=> " +
              year2 + "-" + (month2+1) + "-" + dom2);
}
 
Example 12
Source File: DayPickerPagerAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int getPositionForDay(@Nullable Calendar day) {
    if (day == null) {
        return -1;
    }

    final int yearOffset = day.get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR);
    final int monthOffset = day.get(Calendar.MONTH) - mMinDate.get(Calendar.MONTH);
    final int position = yearOffset * MONTHS_IN_YEAR + monthOffset;
    return position;
}
 
Example 13
Source File: DayPickerPagerAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public boolean getBoundsForDate(Calendar day, Rect outBounds) {
    final int position = getPositionForDay(day);
    final ViewHolder monthView = mItems.get(position, null);
    if (monthView == null) {
        return false;
    } else {
        final int dayOfMonth = day.get(Calendar.DAY_OF_MONTH);
        return monthView.calendar.getBoundsForDay(dayOfMonth, outBounds);
    }
}
 
Example 14
Source File: YearPickerView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void setRange(Calendar minDate, Calendar maxDate) {
    final int minYear = minDate.get(Calendar.YEAR);
    final int count = maxDate.get(Calendar.YEAR) - minYear + 1;

    if (mMinYear != minYear || mCount != count) {
        mMinYear = minYear;
        mCount = count;
        notifyDataSetInvalidated();
    }
}
 
Example 15
Source File: CalendarViewLegacyDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public boolean getBoundsForDate(Calendar date, Rect outBounds) {
    Calendar currDay = Calendar.getInstance();
    currDay.setTime(mFirstDay.getTime());
    for (int i = 0; i < mDaysPerWeek; i++) {
        if ((date.get(Calendar.YEAR) == currDay.get(Calendar.YEAR))
            && (date.get(Calendar.MONTH) == currDay.get(Calendar.MONTH))
            && (date.get(Calendar.DAY_OF_MONTH) == currDay.get(Calendar.DAY_OF_MONTH))) {
            // We found the matching date. Follow the logic in the draw pass that divides
            // the available horizontal space equally between all the entries in this week.
            // Note that if we're showing week number, the start entry will be that number.
            int cellSize = mWidth / mNumCells;
            if (isLayoutRtl()) {
                outBounds.left = cellSize *
                        (mShowWeekNumber ? (mNumCells - i - 2) : (mNumCells - i - 1));
            } else {
                outBounds.left = cellSize * (mShowWeekNumber ? i + 1 : i);
            }
            outBounds.top = 0;
            outBounds.right = outBounds.left + cellSize;
            outBounds.bottom = getHeight();
            return true;
        }
        // Add one day
        currDay.add(Calendar.DAY_OF_MONTH, 1);
    }
    return false;
}
 
Example 16
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void Test4040996() {
    try {
        String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
        SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
        pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
        pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
        Calendar calendar = new GregorianCalendar(pdt);

        calendar.set(Calendar.MONTH,3);
        calendar.set(Calendar.DAY_OF_MONTH,18);
        calendar.set(Calendar.SECOND, 30);

        logln("MONTH: " + calendar.get(Calendar.MONTH));
        logln("DAY_OF_MONTH: " + 
                           calendar.get(Calendar.DAY_OF_MONTH));
        logln("MINUTE: " + calendar.get(Calendar.MINUTE));
        logln("SECOND: " + calendar.get(Calendar.SECOND));

        calendar.add(Calendar.SECOND,6);
        //This will print out todays date for MONTH and DAY_OF_MONTH
        //instead of the date it was set to.
        //This happens when adding MILLISECOND or MINUTE also
        logln("MONTH: " + calendar.get(Calendar.MONTH));
        logln("DAY_OF_MONTH: " + 
                           calendar.get(Calendar.DAY_OF_MONTH));
        logln("MINUTE: " + calendar.get(Calendar.MINUTE));
        logln("SECOND: " + calendar.get(Calendar.SECOND));
        if (calendar.get(Calendar.MONTH) != 3 ||
            calendar.get(Calendar.DAY_OF_MONTH) != 18 ||
            calendar.get(Calendar.SECOND) != 36)
            errln("Fail: Calendar.add misbehaves");
    } catch (Exception e) {
        warnln("Could not load data. "+ e.getMessage());
    }
}
 
Example 17
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Set behavior of DST_OFFSET field. ICU4J Jitterbug 9.
 */
@Test
public void TestJ9() {
    int HOURS = 60*60*1000;
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("PST"),
                                         Locale.US);

    final int END_FIELDS = 0x1234;

    int[] DATA = {
        // With no explicit ZONE/DST expect 12:00 am
        Calendar.MONTH, Calendar.JUNE,
        END_FIELDS,
        0, 0, // expected hour, min

        // Normal ZONE/DST for June 1 Pacific is 8:00/1:00
        Calendar.MONTH, Calendar.JUNE,
        Calendar.ZONE_OFFSET, -8*HOURS,
        Calendar.DST_OFFSET, HOURS,
        END_FIELDS,
        0, 0, // expected hour, min

        // With ZONE/DST of 8:00/0:30 expect time of 12:30 am
        Calendar.MONTH, Calendar.JUNE,
        Calendar.ZONE_OFFSET, -8*HOURS,
        Calendar.DST_OFFSET, HOURS/2,
        END_FIELDS,
        0, 30, // expected hour, min

        // With ZONE/DST of 8:00/UNSET expect time of 1:00 am
        Calendar.MONTH, Calendar.JUNE,
        Calendar.ZONE_OFFSET, -8*HOURS,
        END_FIELDS,
        1, 0, // expected hour, min

        // With ZONE/DST of UNSET/0:30 expect 4:30 pm (day before)
        Calendar.MONTH, Calendar.JUNE,
        Calendar.DST_OFFSET, HOURS/2,
        END_FIELDS,
        16, 30, // expected hour, min
    };

    for (int i=0; i<DATA.length; ) {
        int start = i;
        cal.clear();

        // Set fields
        while (DATA[i] != END_FIELDS) {
            cal.set(DATA[i++], DATA[i++]);
        }
        ++i; // skip over END_FIELDS

        // Get hour/minute
        int h = cal.get(Calendar.HOUR_OF_DAY);
        int m = cal.get(Calendar.MINUTE);

        // Check
        if (h != DATA[i] || m != DATA[i+1]) {
            errln("Fail: expected " + DATA[i] + ":" + DATA[i+1] +
                  ", got " + h + ":" + m + " after:");
            while (DATA[start] != END_FIELDS) {
                logln("set(" + FIELD_NAME[DATA[start++]] +
                      ", " + DATA[start++] + ");");
            }
        }

        i += 2; // skip over expected hour, min
    }
}
 
Example 18
Source File: DangiTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Make sure IS_LEAP_MONTH participates in field resolution.
 */
@Test
public void TestResolution() {
    Calendar cal = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
    DateFormat fmt = DateFormat.getDateInstance(cal, DateFormat.DEFAULT);

    // May 22 4334 = y4334 m4 d30 doy119
    // May 23 4334 = y4334 m4* d1 doy120

    final int THE_YEAR = 4334;
    final int END = -1;

    int[] DATA = {
        // Format:
        // (field, value)+, END, exp.month, exp.isLeapMonth, exp.DOM
        // Note: exp.month is ONE-BASED

        // If we set DAY_OF_YEAR only, that should be used
        Calendar.DAY_OF_YEAR, 1,
        END,
        1,0,1, // Expect 1-1
        
        // If we set MONTH only, that should be used
        Calendar.IS_LEAP_MONTH, 1,
        Calendar.DAY_OF_MONTH, 1,
        Calendar.MONTH, 3,
        END,
        4,1,1, // Expect 4*-1
        
        // If we set the DOY last, that should take precedence
        Calendar.MONTH, 1, // Should ignore
        Calendar.IS_LEAP_MONTH, 1, // Should ignore
        Calendar.DAY_OF_MONTH, 1, // Should ignore
        Calendar.DAY_OF_YEAR, 121,
        END,
        4,1,2, // Expect 4*-2
        
        // If we set IS_LEAP_MONTH last, that should take precedence
        Calendar.MONTH, 3,
        Calendar.DAY_OF_MONTH, 1,
        Calendar.DAY_OF_YEAR, 5, // Should ignore
        Calendar.IS_LEAP_MONTH, 1,
        END,
        4,1,1, // Expect 4*-1
    };

    StringBuilder buf = new StringBuilder();
    for (int i=0; i<DATA.length; ) {
        cal.clear();
        cal.set(Calendar.EXTENDED_YEAR, THE_YEAR);
        buf.setLength(0);
        buf.append("EXTENDED_YEAR=" + THE_YEAR);
        while (DATA[i] != END) {
            cal.set(DATA[i++], DATA[i++]);
            buf.append(" " + fieldName(DATA[i-2]) + "=" + DATA[i-1]);
        }
        ++i; // Skip over END mark
        int expMonth = DATA[i++]-1;
        int expIsLeapMonth = DATA[i++];
        int expDOM = DATA[i++];
        int month = cal.get(Calendar.MONTH);
        int isLeapMonth = cal.get(Calendar.IS_LEAP_MONTH);
        int dom = cal.get(Calendar.DAY_OF_MONTH);
        if (expMonth == month && expIsLeapMonth == isLeapMonth &&
            dom == expDOM) {
            logln("OK: " + buf + " => " + fmt.format(cal.getTime()));
        } else {
            String s = fmt.format(cal.getTime());
            cal.clear();
            cal.set(Calendar.EXTENDED_YEAR, THE_YEAR);
            cal.set(Calendar.MONTH, expMonth);
            cal.set(Calendar.IS_LEAP_MONTH, expIsLeapMonth);
            cal.set(Calendar.DAY_OF_MONTH, expDOM);
            errln("Fail: " + buf + " => " + s +
                  "=" + (month+1) + "," + isLeapMonth + "," + dom +
                  ", expected " + fmt.format(cal.getTime()) +
                  "=" + (expMonth+1) + "," + expIsLeapMonth + "," + expDOM);
        }
    }
}
 
Example 19
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
private boolean sameDay(int day, Calendar today) {
    return mYear == today.get(Calendar.YEAR) && mMonth == today.get(Calendar.MONTH)
            && day == today.get(Calendar.DAY_OF_MONTH);
}
 
Example 20
Source File: IBMCalendarTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@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);
        // No matter what locale is used, if calendar type is "iso8601",
        // 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] + "]");
            }
        }
    }
}