Java Code Examples for android.icu.util.Calendar#IS_LEAP_MONTH
The following examples show how to use
android.icu.util.Calendar#IS_LEAP_MONTH .
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: DangiTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * 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 2
Source File: ChineseTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * Make sure IS_LEAP_MONTH participates in field resolution. */ @Test public void TestResolution() { ChineseCalendar cal = new ChineseCalendar(); DateFormat fmt = DateFormat.getDateInstance(cal, DateFormat.DEFAULT); // May 22 2001 = y4638 m4 d30 doy119 // May 23 2001 = y4638 m4* d1 doy120 final int THE_YEAR = 4638; 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 // I've disabled this test because it doesn't work this way, // not even with a GregorianCalendar! MONTH alone isn't enough // to supersede DAY_OF_YEAR. Some other month-related field is // also required. - Liu 11/28/00 //! // If we set MONTH last, that should take precedence //! ChineseCalendar.IS_LEAP_MONTH, 1, //! Calendar.DAY_OF_MONTH, 1, //! Calendar.DAY_OF_YEAR, 5, // Should ignore //! Calendar.MONTH, 3, //! END, //! 4,1,1, // Expect 4*-1 // 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 }; StringBuffer buf = new StringBuffer(); 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); } } }