diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java index d19b830a01..965786b90a 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java @@ -34,6 +34,7 @@ import com.ibm.icu.lang.UCharacter; import com.ibm.icu.util.BasicTimeZone; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.GregorianCalendar; +import com.ibm.icu.util.HebrewCalendar; import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.TimeZoneTransition; import com.ibm.icu.util.ULocale; @@ -232,6 +233,7 @@ public class SimpleDateFormat extends DateFormat { // - 1 for version from JDK 1.1.4, which includes a new field static final int currentSerialVersion = 1; + static boolean DelayedHebrewMonthCheck = false; /* * From calendar field to its level. @@ -866,6 +868,15 @@ public class SimpleDateFormat extends DateFormat { } break; case 2: // 'M' - MONTH + if ( cal.getType().equals("hebrew")) { + HebrewCalendar hc = (HebrewCalendar)cal.clone(); + if (hc.isLeapYear(hc.get(Calendar.YEAR)) && value == 6 && count >= 3 ) { + value = 13; // Show alternate form for Adar II in leap years in Hebrew calendar. + } + if (!hc.isLeapYear(hc.get(Calendar.YEAR)) && value >= 6 && count < 3 ) { + value--; // Adjust the month number down 1 in Hebrew non-leap years, i.e. Adar is 6, not 7. + } + } if (count == 5) { safeAppend(formatData.narrowMonths, value, buf); } else if (count == 4) { @@ -2046,6 +2057,7 @@ public class SimpleDateFormat extends DateFormat { int value = 0; int i; ParsePosition pos = new ParsePosition(0); + //int patternCharIndex = DateFormatSymbols.patternChars.indexOf(ch);c int patternCharIndex = -1; if ('A' <= ch && ch <= 'z') { @@ -2132,6 +2144,15 @@ public class SimpleDateFormat extends DateFormat { (value < ambiguousTwoDigitYear ? 100 : 0); } cal.set(Calendar.YEAR, value); + + // Delayed checking for adjustment of Hebrew month numbers in non-leap years. + if (DelayedHebrewMonthCheck) { + HebrewCalendar hc = (HebrewCalendar) cal.clone(); + if (!hc.isLeapYear(value)) { + cal.add(Calendar.MONTH,1); + } + DelayedHebrewMonthCheck = false; + } return pos.getIndex(); case 2: // 'M' - MONTH if (count <= 2) { // i.e., M or MM. @@ -2139,6 +2160,19 @@ public class SimpleDateFormat extends DateFormat { // while pattern uses numeric style: M or MM. // [We computed 'value' above.] cal.set(Calendar.MONTH, value - 1); + // When parsing month numbers from the Hebrew Calendar, we might need to adjust the month depending on whether + // or not it was a leap year. We may or may not yet know what year it is, so might have to delay checking + // until the year is parsed. + if (cal.getType().equals("hebrew") && value >= 6) { + HebrewCalendar hc = (HebrewCalendar) cal.clone(); + if (cal.isSet(Calendar.YEAR)) { + if (!hc.isLeapYear(hc.get(Calendar.YEAR))) { + cal.set(Calendar.MONTH, value); + } + } else { + DelayedHebrewMonthCheck = true; + } + } return pos.getIndex(); } else { // count >= 3 // i.e., MMM or MMMM diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/HebrewCalendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/HebrewCalendar.java index 3ffe8f8ecd..54478099a4 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/HebrewCalendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/HebrewCalendar.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * + * Copyright (C) 1996-2009, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -678,13 +678,13 @@ public class HebrewCalendar extends Calendar { * The rule here is that if (year % 19) == 0, 3, 6, 8, 11, 14, or 17. * The formula below performs the same test, believe it or not. */ - private static final boolean isLeapYear(int year) { + public static final boolean isLeapYear(int year) { //return (year * 12 + 17) % 19 >= 12; int x = (year*12 + 17) % 19; return x >= ((x < 0) ? -7 : 12); } - private static int monthsInYear(int year) { + public static int monthsInYear(int year) { return isLeapYear(year) ? 13 : 12; } diff --git a/icu4j/main/shared/data/icudata.jar b/icu4j/main/shared/data/icudata.jar index cfba8c806a..fee36e8b9b 100755 --- a/icu4j/main/shared/data/icudata.jar +++ b/icu4j/main/shared/data/icudata.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2e0e9765959db0043f13753f536fdd17f5c3575134c62e2fc3605f0468ec9e0d -size 6408404 +oid sha256:db0ac7d8c3202260bd74b75da3b6bb3772cbe71748dd823632af792fcb015bf9 +size 6432271 diff --git a/icu4j/main/shared/data/testdata.jar b/icu4j/main/shared/data/testdata.jar index d47550218a..41fe6073d1 100755 --- a/icu4j/main/shared/data/testdata.jar +++ b/icu4j/main/shared/data/testdata.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:02091ec2784bdaf2c4f03191092760c4729c3724ed78dab3efe23733227b4fe9 -size 717064 +oid sha256:f736990a0ecdadf6da582d57184596b9385a2ee38c0ab369cef7da153e239447 +size 720081