mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-10313 Added Hebrew month value checking for leap year.
X-SVN-Rev: 34539
This commit is contained in:
parent
b2f9cedfbf
commit
0d678d3115
5 changed files with 61 additions and 12 deletions
|
@ -529,6 +529,13 @@ int32_t HebrewCalendar::handleGetYearLength(int32_t eyear) const {
|
|||
return startOfYear(eyear+1, status) - startOfYear(eyear, status);
|
||||
}
|
||||
|
||||
void HebrewCalendar::validateField(UCalendarDateFields field, UErrorCode &status) {
|
||||
if (field == UCAL_MONTH && !isLeapYear(handleGetExtendedYear()) && internalGet(UCAL_MONTH) == ADAR_1) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
}
|
||||
Calendar::validateField(field, status);
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// Functions for converting from milliseconds to field values
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
@ -362,6 +362,13 @@ public:
|
|||
UBool useMonth) const;
|
||||
|
||||
|
||||
/**
|
||||
* Validate a single field of this calendar.
|
||||
* Overrides Calendar::validateField(int) to provide
|
||||
* special handling for month validation for Hebrew calendar.
|
||||
* @internal
|
||||
*/
|
||||
virtual void validateField(UCalendarDateFields field, UErrorCode &status);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -1713,6 +1713,16 @@ protected:
|
|||
*/
|
||||
virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
|
||||
|
||||
/**
|
||||
* Validate a single field of this calendar. Subclasses should
|
||||
* override this method to validate any calendar-specific fields.
|
||||
* Generic fields can be handled by
|
||||
* <code>Calendar::validateField()</code>.
|
||||
* @see #validateField(int, int, int, int&)
|
||||
* @internal
|
||||
*/
|
||||
virtual void validateField(UCalendarDateFields field, UErrorCode &status);
|
||||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Compute the Julian day from fields. Will determine whether to use
|
||||
|
@ -2292,16 +2302,6 @@ private:
|
|||
*/
|
||||
void validateFields(UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Validate a single field of this calendar. Subclasses should
|
||||
* override this method to validate any calendar-specific fields.
|
||||
* Generic fields can be handled by
|
||||
* <code>Calendar::validateField()</code>.
|
||||
* @see #validateField(int, int, int, int&)
|
||||
* @internal
|
||||
*/
|
||||
virtual void validateField(UCalendarDateFields field, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Validate a single field of this calendar given its minimum and
|
||||
* maximum allowed value. If the field is out of range,
|
||||
|
|
|
@ -298,6 +298,13 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
|
|||
TestIslamicTabularDates();
|
||||
}
|
||||
break;
|
||||
case 33:
|
||||
name = "TestHebrewMonthValidation";
|
||||
if(exec) {
|
||||
logln("TestHebrewMonthValidation---"); logln("");
|
||||
TestHebrewMonthValidation();
|
||||
}
|
||||
break;
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
|
@ -2771,7 +2778,7 @@ void CalendarTest::TestIslamicUmAlQura() {
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
Locale islamicLoc("ar_SA@calendar=islamic-umalqura");
|
||||
Calendar* tstCal = Calendar::createInstance(islamicLoc, status);
|
||||
|
||||
|
||||
IslamicCalendar* iCal = (IslamicCalendar*)tstCal;
|
||||
if(strcmp(iCal->getType(), "islamic-umalqura") != 0) {
|
||||
errln("wrong type of calendar created - %s", iCal->getType());
|
||||
|
@ -2858,7 +2865,7 @@ void CalendarTest::TestIslamicTabularDates() {
|
|||
UErrorCode status = U_ZERO_ERROR;
|
||||
Locale islamicLoc("ar_SA@calendar=islamic-civil");
|
||||
Locale tblaLoc("ar_SA@calendar=islamic-tbla");
|
||||
SimpleDateFormat* formatter = new SimpleDateFormat("yyyy-MM-dd", Locale::getUS(), status);
|
||||
SimpleDateFormat* formatter = new SimpleDateFormat("yyyy-MM-dd", Locale::getUS(), status);
|
||||
UDate date = formatter->parse("1975-05-06", status);
|
||||
|
||||
Calendar* tstCal = Calendar::createInstance(islamicLoc, status);
|
||||
|
@ -2885,6 +2892,32 @@ void CalendarTest::TestIslamicTabularDates() {
|
|||
delete formatter;
|
||||
}
|
||||
|
||||
void CalendarTest::TestHebrewMonthValidation() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<Calendar> cal(Calendar::createInstance(Locale::createFromName("he_IL@calendar=hebrew"), status));
|
||||
if (failure(status, "Calendar::createInstance, locale:he_IL@calendar=hebrew", TRUE)) return;
|
||||
Calendar *pCal = cal.getAlias();
|
||||
|
||||
UDate d;
|
||||
pCal->setLenient(FALSE);
|
||||
|
||||
// 5776 is a leap year and has month Adar I
|
||||
pCal->set(5776, HebrewCalendar::ADAR_1, 1);
|
||||
d = pCal->getTime(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Fail: 5776 Adar I 1 is a valid date.");
|
||||
}
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
// 5777 is NOT a lear year and does not have month Adar I
|
||||
pCal->set(5777, HebrewCalendar::ADAR_1, 1);
|
||||
d = pCal->getTime(status);
|
||||
if (status == U_ILLEGAL_ARGUMENT_ERROR) {
|
||||
logln("Info: U_ILLEGAL_ARGUMENT_ERROR, because 5777 Adar I 1 is not a valid date.");
|
||||
} else {
|
||||
errln("Fail: U_ILLEGAL_ARGUMENT_ERROR should be set for input date 5777 Adar I 1.");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
|
|
|
@ -240,6 +240,8 @@ public: // package
|
|||
|
||||
void TestCloneLocale(void);
|
||||
|
||||
void TestHebrewMonthValidation(void);
|
||||
|
||||
/*
|
||||
* utility methods for TestIslamicUmAlQura
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue