ICU-10313 Added Hebrew calendar month value checking for leap year.

X-SVN-Rev: 34540
This commit is contained in:
Yoshito Umaoka 2013-10-10 17:36:54 +00:00
parent 0d678d3115
commit ff0dbde358
2 changed files with 41 additions and 1 deletions

View file

@ -746,6 +746,21 @@ public class HebrewCalendar extends Calendar {
return (int)(startOfYear(eyear+1) - startOfYear(eyear));
}
/**
* {@inheritDoc}
* <p>
* Overrides {@link Calendar#validateField(int)} to provide
* special handling for month validation for Hebrew calendar.
* @internal
*/
protected void validateField(int field) {
if (field == MONTH && !isLeapYear(handleGetExtendedYear()) && internalGet(MONTH) == ADAR_1) {
throw new IllegalArgumentException("MONTH cannot be ADAR_1(5) except leap years");
}
super.validateField(field);
}
//-------------------------------------------------------------------------
// Functions for converting from milliseconds to field values
//-------------------------------------------------------------------------

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2009, International Business Machines Corporation and *
* Copyright (C) 1996-2013, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -496,4 +496,29 @@ public class HebrewTest extends CalendarTest {
}
}
}
// Test case for Ticket#10313. HebrewCalendar requires
// special handling for validating month value, because
// month Adar I is only available in leap years.
public void TestMonthValidation() {
HebrewCalendar cal = new HebrewCalendar();
cal.setLenient(false);
// 5776 is a leap year and has month Adar I
cal.set(5776, ADAR_1, 1);
try {
/* Date d = */ cal.getTime();
} catch (IllegalArgumentException e) {
errln("Fail: 5776 Adar I 1 is a valid date.");
}
// 5777 is NOT a lear year and does not have month Adar I
cal.set(5777, ADAR_1, 1);
try {
/* Date d = */ cal.getTime();
errln("Fail: IllegalArgumentException should be thrown for input date 5777 Adar I 1.");
} catch (IllegalArgumentException e) {
logln("Info: IllegalArgumentException, because 5777 Adar I 1 is not a valid date.");
}
}
}