Java Code Examples for android.icu.util.Calendar#YEAR
The following examples show how to use
android.icu.util.Calendar#YEAR .
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: DateIntervalFormat.java From j2objc with Apache License 2.0 | 5 votes |
/** * @deprecated This API is ICU internal only. * @hide original deprecated declaration * @hide draft / provisional / internal are hidden on Android */ @Deprecated public String getPatterns(Calendar fromCalendar, Calendar toCalendar, Output<String> part2) { // First, find the largest different calendar field. int field; if ( fromCalendar.get(Calendar.ERA) != toCalendar.get(Calendar.ERA) ) { field = Calendar.ERA; } else if ( fromCalendar.get(Calendar.YEAR) != toCalendar.get(Calendar.YEAR) ) { field = Calendar.YEAR; } else if ( fromCalendar.get(Calendar.MONTH) != toCalendar.get(Calendar.MONTH) ) { field = Calendar.MONTH; } else if ( fromCalendar.get(Calendar.DATE) != toCalendar.get(Calendar.DATE) ) { field = Calendar.DATE; } else if ( fromCalendar.get(Calendar.AM_PM) != toCalendar.get(Calendar.AM_PM) ) { field = Calendar.AM_PM; } else if ( fromCalendar.get(Calendar.HOUR) != toCalendar.get(Calendar.HOUR) ) { field = Calendar.HOUR; } else if ( fromCalendar.get(Calendar.MINUTE) != toCalendar.get(Calendar.MINUTE) ) { field = Calendar.MINUTE; } else if ( fromCalendar.get(Calendar.SECOND) != toCalendar.get(Calendar.SECOND) ) { field = Calendar.SECOND; } else { return null; } PatternInfo intervalPattern = fIntervalPatterns.get( DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]); part2.value = intervalPattern.getSecondPart(); return intervalPattern.getFirstPart(); }
Example 2
Source File: JapaneseTest.java From j2objc with Apache License 2.0 | 4 votes |
@Test public void Test5345calendar() { logln("** testIncompleteCalendar()"); // Test calendar with incomplete information JapaneseCalendar c = new JapaneseCalendar(TimeZone.getDefault()); logln("test clear"); c.clear(); // Showa 45 = Gregorian 1970 int expected0[] = { Calendar.ERA, 234, Calendar.YEAR, 45 }; checkExpected(c, expected0); logln("test setting era"); c.clear(); c.set(Calendar.ERA, JapaneseCalendar.MEIJI); int expectedA[] = { Calendar.ERA, JapaneseCalendar.MEIJI }; checkExpected(c, expectedA); logln("test setting era and year and month and date"); c.clear(); c.set(Calendar.ERA, JapaneseCalendar.MEIJI); c.set(Calendar.YEAR, 1); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DATE, 1); int expectedC[] = { Calendar.ERA, JapaneseCalendar.MEIJI -1}; checkExpected(c, expectedC); logln("test setting year and month and date THEN era"); c.clear(); c.set(Calendar.YEAR, 1); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DATE, 1); c.set(Calendar.ERA, JapaneseCalendar.MEIJI); checkExpected(c, expectedC); logln("test setting era and year"); c.clear(); c.set(Calendar.YEAR, 1); c.set(Calendar.ERA, JapaneseCalendar.MEIJI); int expectedB[] = { Calendar.ERA, JapaneseCalendar.MEIJI, Calendar.YEAR, 1 }; checkExpected(c, expectedB); }
Example 3
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * Calendar.getActualMaximum(YEAR) works wrong. */ @Test public void Test4167060() { int field = Calendar.YEAR; DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy G", Locale.US); GregorianCalendar calendars[] = { new GregorianCalendar(100, Calendar.NOVEMBER, 1), new GregorianCalendar(-99 /* 100BC */, Calendar.JANUARY, 1), new GregorianCalendar(1996, Calendar.FEBRUARY, 29), }; String[] id = { "Hybrid", "Gregorian", "Julian" }; for (int k=0; k<3; ++k) { logln("--- " + id[k] + " ---"); for (int j=0; j<calendars.length; ++j) { GregorianCalendar calendar = calendars[j]; if (k == 1) { calendar.setGregorianChange(new Date(Long.MIN_VALUE)); } else if (k == 2) { calendar.setGregorianChange(new Date(Long.MAX_VALUE)); } format.setCalendar((Calendar)calendar.clone()); Date dateBefore = calendar.getTime(); int maxYear = calendar.getActualMaximum(field); logln("maxYear: " + maxYear + " for " + format.format(calendar.getTime())); logln("date before: " + format.format(dateBefore)); int years[] = {2000, maxYear-1, maxYear, maxYear+1}; for (int i = 0; i < years.length; i++) { boolean valid = years[i] <= maxYear; calendar.set(field, years[i]); Date dateAfter = calendar.getTime(); int newYear = calendar.get(field); calendar.setTime(dateBefore); // restore calendar for next // use logln(" Year " + years[i] + (valid? " ok " : " bad") + " => " + format.format(dateAfter)); if (valid && newYear != years[i]) { errln(" FAIL: " + newYear + " should be valid; date, month and time shouldn't change"); } else if (!valid && newYear == years[i]) { // We no longer require strict year maxima. That is, the // calendar // algorithm may work for values > the stated maximum. //errln(" FAIL: " + newYear + " should be invalid"); logln(" Note: " + newYear + " > maximum, but still valid"); } } } } }