(value);
// Search forward to the target month's new moon
- newMoon = newMoonNear(setting.zoneAstroCalc, newMoon, true);
+ newMoon = newMoonNear(setting.zoneAstroCalc, newMoon, true, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
// Find the target dayOfMonth
int32_t jd = newMoon + kEpochStartAsJulianDay - 1 + dayOfMonth;
diff --git a/icu4c/source/i18n/hebrwcal.cpp b/icu4c/source/i18n/hebrwcal.cpp
index d74ab2d3e7d..f5f9c13fede 100644
--- a/icu4c/source/i18n/hebrwcal.cpp
+++ b/icu4c/source/i18n/hebrwcal.cpp
@@ -304,6 +304,12 @@ void HebrewCalendar::add(EDateFields field, int32_t amount, UErrorCode& status)
add((UCalendarDateFields)field, amount, status);
}
+namespace {
+
+int32_t monthsInYear(int32_t year);
+
+} // namespace
+
/**
* Rolls (up/down) a specified amount time on the given field. For
* example, to roll the current date up by three days, you can call
@@ -396,6 +402,8 @@ static const int32_t MONTH_PARTS = MONTH_DAYS*DAY_PARTS + MONTH_FRACT;
// Bet (Monday), Hey (5 hours from sunset), Resh-Daled (204).
static const int32_t BAHARAD = 11*HOUR_PARTS + 204;
+namespace {
+
/**
* Finds the day # of the first day in the given Hebrew year.
* To do this, we want to calculate the time of the Tishri 1 new moon
@@ -416,7 +424,7 @@ static const int32_t BAHARAD = 11*HOUR_PARTS + 204;
* http://www.faqs.org/faqs/calendars/faq/
*
*/
-int32_t HebrewCalendar::startOfYear(int32_t year, UErrorCode &status)
+int32_t startOfYear(int32_t year, UErrorCode &status)
{
ucln_i18n_registerCleanup(UCLN_I18N_HEBREW_CALENDAR, calendar_hebrew_cleanup);
int64_t day = CalendarCache::get(&gCache, year, status);
@@ -440,13 +448,13 @@ int32_t HebrewCalendar::startOfYear(int32_t year, UErrorCode &status)
day += 1;
wd = (day % 7);
}
- if (wd == 1 && frac > 15*HOUR_PARTS+204 && !isLeapYear(year) ) {
+ if (wd == 1 && frac > 15*HOUR_PARTS+204 && !HebrewCalendar::isLeapYear(year) ) {
// If the new moon falls after 3:11:20am (15h204p from the previous noon)
// on a Tuesday and it is not a leap year, postpone by 2 days.
// This prevents 356-day years.
day += 2;
}
- else if (wd == 0 && frac > 21*HOUR_PARTS+589 && isLeapYear(year-1) ) {
+ else if (wd == 0 && frac > 21*HOUR_PARTS+589 && HebrewCalendar::isLeapYear(year-1) ) {
// If the new moon falls after 9:32:43 1/3am (21h589p from yesterday noon)
// on a Monday and *last* year was a leap year, postpone by 1 day.
// Prevents 382-day years.
@@ -463,16 +471,11 @@ int32_t HebrewCalendar::startOfYear(int32_t year, UErrorCode &status)
return day;
}
-/**
-* Find the day of the week for a given day
-*
-* @param day The # of days since the start of the Hebrew calendar,
-* 1-based (i.e. 1/1/1 AM is day 1).
-*/
-int32_t HebrewCalendar::absoluteDayToDayOfWeek(int32_t day)
-{
- // We know that 1/1/1 AM is a Monday, which makes the math easy...
- return (day % 7) + 1;
+int32_t daysInYear(int32_t eyear, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ return startOfYear(eyear+1, status) - startOfYear(eyear, status);
}
/**
@@ -481,9 +484,15 @@ int32_t HebrewCalendar::absoluteDayToDayOfWeek(int32_t day)
* 1 "Normal" year with 354 or 384 days
* 2 "Complete" year with 355 or 385 days
*/
-int32_t HebrewCalendar::yearType(int32_t year) const
+int32_t yearType(int32_t year, UErrorCode& status)
{
- int32_t yearLength = handleGetYearLength(year);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ int32_t yearLength = daysInYear(year, status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
if (yearLength > 380) {
yearLength -= 30; // Subtract length of leap month.
@@ -505,6 +514,8 @@ int32_t HebrewCalendar::yearType(int32_t year) const
return type;
}
+} // namespace
+ //
/**
* Determine whether a given Hebrew year is a leap year
*
@@ -517,10 +528,14 @@ UBool HebrewCalendar::isLeapYear(int32_t year) {
return x >= ((x < 0) ? -7 : 12);
}
-int32_t HebrewCalendar::monthsInYear(int32_t year) {
- return isLeapYear(year) ? 13 : 12;
+namespace{
+
+int32_t monthsInYear(int32_t year) {
+ return HebrewCalendar::isLeapYear(year) ? 13 : 12;
}
+} // namespace
+
//-------------------------------------------------------------------------
// Calendar framework
//-------------------------------------------------------------------------
@@ -557,8 +572,14 @@ int32_t HebrewCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month
switch (month) {
case HESHVAN:
case KISLEV:
- // These two month lengths can vary
- return MONTH_LENGTH[month][yearType(extendedYear)];
+ {
+ // These two month lengths can vary
+ int32_t type = yearType(extendedYear, status);
+ if(U_FAILURE(status)) {
+ return 0;
+ }
+ return MONTH_LENGTH[month][type];
+ }
default:
// The rest are a fixed length
@@ -572,7 +593,11 @@ int32_t HebrewCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month
*/
int32_t HebrewCalendar::handleGetYearLength(int32_t eyear) const {
UErrorCode status = U_ZERO_ERROR;
- return startOfYear(eyear+1, status) - startOfYear(eyear, status);
+ int32_t len = daysInYear(eyear, status);
+ if (U_FAILURE(status)) {
+ return 12;
+ }
+ return len;
}
void HebrewCalendar::validateField(UCalendarDateFields field, UErrorCode &status) {
@@ -635,12 +660,16 @@ void HebrewCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status)
}
// Now figure out which month we're in, and the date within that month
- int32_t type = yearType(year);
+ int32_t type = yearType(year, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
UBool isLeap = isLeapYear(year);
int32_t month = 0;
int32_t momax = UPRV_LENGTHOF(MONTH_START);
- while (month < momax && dayOfYear > ( isLeap ? LEAP_MONTH_START[month][type] : MONTH_START[month][type] ) ) {
+ while (month < momax &&
+ dayOfYear > ( isLeap ? LEAP_MONTH_START[month][type] : MONTH_START[month][type] ) ) {
month++;
}
if (month >= momax || month<=0) {
@@ -663,25 +692,25 @@ void HebrewCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status)
// Check out of bound year
int32_t min_year = handleGetLimit(UCAL_EXTENDED_YEAR, UCAL_LIMIT_MINIMUM);
if (year < min_year) {
- if (!isLenient()) {
- status = U_ILLEGAL_ARGUMENT_ERROR;
- return;
- }
- year = min_year;
+ if (!isLenient()) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ year = min_year;
}
int32_t max_year = handleGetLimit(UCAL_EXTENDED_YEAR, UCAL_LIMIT_MAXIMUM);
if (max_year < year) {
- if (!isLenient()) {
- status = U_ILLEGAL_ARGUMENT_ERROR;
- return;
- }
- year = max_year;
+ if (!isLenient()) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+ year = max_year;
}
internalSet(UCAL_YEAR, year);
internalSet(UCAL_EXTENDED_YEAR, year);
int32_t ordinal_month = month;
if (!isLeap && ordinal_month > ADAR_1) {
- ordinal_month--;
+ ordinal_month--;
}
internalSet(UCAL_ORDINAL_MONTH, ordinal_month);
internalSet(UCAL_MONTH, month);
@@ -754,10 +783,14 @@ int64_t HebrewCalendar::handleComputeMonthStart(
}
if (month != 0) {
+ int32_t type = yearType(eyear, status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
if (isLeapYear(eyear)) {
- day += LEAP_MONTH_START[month][yearType(eyear)];
+ day += LEAP_MONTH_START[month][type];
} else {
- day += MONTH_START[month][yearType(eyear)];
+ day += MONTH_START[month][type];
}
}
diff --git a/icu4c/source/i18n/hebrwcal.h b/icu4c/source/i18n/hebrwcal.h
index 342fdb0efa7..5fb10993d30 100644
--- a/icu4c/source/i18n/hebrwcal.h
+++ b/icu4c/source/i18n/hebrwcal.h
@@ -329,6 +329,7 @@ public:
* @stable ICU 2.0
*/
virtual int32_t handleGetYearLength(int32_t eyear) const override;
+
/**
* Subclasses may override this method to compute several fields
* specific to each calendar system. These are:
@@ -427,44 +428,6 @@ public:
protected:
virtual int32_t internalGetMonth(UErrorCode& status) const override;
-
- private: // Calendar-specific implementation
- /**
- * Finds the day # of the first day in the given Hebrew year.
- * To do this, we want to calculate the time of the Tishri 1 new moon
- * in that year.
- *
- * The algorithm here is similar to ones described in a number of
- * references, including:
- *
- * @param year extended year
- * @return day number (JD)
- * @internal
- */
- static int32_t startOfYear(int32_t year, UErrorCode& status);
-
- static int32_t absoluteDayToDayOfWeek(int32_t day) ;
-
- /**
- * @internal
- */
- int32_t yearType(int32_t year) const;
-
- /**
- * @internal
- */
- static int32_t monthsInYear(int32_t year) ;
};
U_NAMESPACE_END
diff --git a/icu4c/source/i18n/islamcal.cpp b/icu4c/source/i18n/islamcal.cpp
index d299358a5f1..7a9ac5c0852 100644
--- a/icu4c/source/i18n/islamcal.cpp
+++ b/icu4c/source/i18n/islamcal.cpp
@@ -303,7 +303,7 @@ inline bool civilLeapYear(int32_t year) {
return (14 + 11 * year) % 30 < 11;
}
-int32_t trueMonthStart(int32_t month);
+int32_t trueMonthStart(int32_t month, UErrorCode& status);
} // namespace
@@ -311,8 +311,8 @@ int32_t trueMonthStart(int32_t month);
* Return the day # on which the given year starts. Days are counted
* from the Hijri epoch, origin 0.
*/
-int64_t IslamicCalendar::yearStart(int32_t year) const{
- return trueMonthStart(12*(year-1));
+int64_t IslamicCalendar::yearStart(int32_t year, UErrorCode& status) const {
+ return trueMonthStart(12*(year-1), status);
}
/**
@@ -334,7 +334,7 @@ int64_t IslamicCalendar::monthStart(int32_t year, int32_t month, UErrorCode& sta
return 0;
}
- return trueMonthStart(month);
+ return trueMonthStart(month, status);
}
namespace {
@@ -357,9 +357,11 @@ double moonAge(UDate time);
*
* @return The day number on which the given month starts.
*/
-int32_t trueMonthStart(int32_t month) {
+int32_t trueMonthStart(int32_t month, UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return 0;
+ }
ucln_i18n_registerCleanup(UCLN_I18N_ISLAMIC_CALENDAR, calendar_islamic_cleanup);
- UErrorCode status = U_ZERO_ERROR;
int64_t start = CalendarCache::get(&gMonthCache, month, status);
if (U_SUCCESS(status) && start==0) {
@@ -417,18 +419,40 @@ double moonAge(UDate time) {
* @draft ICU 2.4
*/
int32_t IslamicCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month,
- UErrorCode& /* status */) const {
+ UErrorCode& status) const {
month = 12*(extendedYear-1) + month;
- return trueMonthStart(month+1) - trueMonthStart(month) ;
+ int32_t len = trueMonthStart(month+1, status) - trueMonthStart(month, status) ;
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ return len;
}
+namespace {
+
+int32_t yearLength(int32_t extendedYear, UErrorCode& status) {
+ int32_t month = 12*(extendedYear-1);
+ int32_t length = trueMonthStart(month + 12, status) - trueMonthStart(month, status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ return length;
+}
+
+} // namepsace
/**
* Return the number of days in the given Islamic year
* @draft ICU 2.4
*/
int32_t IslamicCalendar::handleGetYearLength(int32_t extendedYear) const {
- int32_t month = 12*(extendedYear-1);
- return (trueMonthStart(month + 12) - trueMonthStart(month));
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t length = yearLength(extendedYear, status);
+ if (U_FAILURE(status)) {
+ // fallback to normal Islamic calendar length 355 day a year if we
+ // encounter error and cannot propagate.
+ return 355;
+ }
+ return length;
}
//-------------------------------------------------------------------------
@@ -500,7 +524,9 @@ int32_t IslamicCalendar::handleGetExtendedYear(UErrorCode& /* status */) {
* @draft ICU 2.4
*/
void IslamicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) {
- if (U_FAILURE(status)) return;
+ if (U_FAILURE(status)) {
+ return;
+ }
int32_t days = julianDay - getEpoc();
// Guess at the number of elapsed full months since the epoch
@@ -516,10 +542,16 @@ void IslamicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status)
// Find out the last time that the new moon was actually visible at this longitude
// This returns midnight the night that the moon was visible at sunset.
- while ((startDate = trueMonthStart(month)) > days) {
+ while ((startDate = trueMonthStart(month, status)) > days) {
+ if (U_FAILURE(status)) {
+ return;
+ }
// If it was after the date in question, back up a month and try again
month--;
}
+ if (U_FAILURE(status)) {
+ return;
+ }
int32_t year = month >= 0 ? ((month / 12) + 1) : ((month + 1 ) / 12);
month = ((month % 12) + 12 ) % 12;
@@ -636,7 +668,7 @@ IslamicCivilCalendar* IslamicCivilCalendar::clone() const {
* Return the day # on which the given year starts. Days are counted
* from the Hijri epoch, origin 0.
*/
-int64_t IslamicCivilCalendar::yearStart(int32_t year) const{
+int64_t IslamicCivilCalendar::yearStart(int32_t year, UErrorCode& /* status */) const {
return 354LL * (year-1LL) + ClockMath::floorDivideInt64(3 + 11LL * year, 30LL);
}
@@ -696,14 +728,19 @@ int32_t IslamicCivilCalendar::handleGetYearLength(int32_t extendedYear) const {
* @draft ICU 2.4
*/
void IslamicCivilCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) {
- if (U_FAILURE(status)) return;
+ if (U_FAILURE(status)) {
+ return;
+ }
int32_t days = julianDay - getEpoc();
// Use the civil calendar approximation, which is just arithmetic
int64_t year =
ClockMath::floorDivideInt64(30LL * days + 10646LL, 10631LL);
int32_t month = static_cast(
- uprv_ceil((days - 29 - yearStart(year)) / 29.5 ));
+ uprv_ceil((days - 29 - yearStart(year, status)) / 29.5 ));
+ if (U_FAILURE(status)) {
+ return;
+ }
month = month<11?month:11;
int64_t dayOfMonth = (days - monthStart(year, month, status)) + 1;
@@ -781,9 +818,9 @@ IslamicUmalquraCalendar* IslamicUmalquraCalendar::clone() const {
* Return the day # on which the given year starts. Days are counted
* from the Hijri epoch, origin 0.
*/
-int64_t IslamicUmalquraCalendar::yearStart(int32_t year) const {
+int64_t IslamicUmalquraCalendar::yearStart(int32_t year, UErrorCode& status) const {
if (year < UMALQURA_YEAR_START || year > UMALQURA_YEAR_END) {
- return IslamicCivilCalendar::yearStart(year);
+ return IslamicCivilCalendar::yearStart(year, status);
}
year -= UMALQURA_YEAR_START;
// rounded least-squares fit of the dates previously calculated from UMALQURA_MONTHLENGTH iteration
@@ -801,10 +838,10 @@ int64_t IslamicUmalquraCalendar::yearStart(int32_t year) const {
* @param month The hijri month, 0-based (assumed to be in range 0..11)
*/
int64_t IslamicUmalquraCalendar::monthStart(int32_t year, int32_t month, UErrorCode& status) const {
+ int64_t ms = yearStart(year, status);
if (U_FAILURE(status)) {
return 0;
}
- int64_t ms = yearStart(year);
for(int i=0; i< month; i++){
ms+= handleGetMonthLength(year, i, status);
if (U_FAILURE(status)) {
@@ -834,20 +871,32 @@ int32_t IslamicUmalquraCalendar::handleGetMonthLength(int32_t extendedYear, int3
return length;
}
+int32_t IslamicUmalquraCalendar::yearLength(int32_t extendedYear, UErrorCode& status) const {
+ if (extendedYearUMALQURA_YEAR_END) {
+ return IslamicCivilCalendar::handleGetYearLength(extendedYear);
+ }
+ int length = 0;
+ for(int i=0; i<12; i++) {
+ length += handleGetMonthLength(extendedYear, i, status);
+ if (U_FAILURE(status)) {
+ return 0;
+ }
+ }
+ return length;
+}
+
/**
* Return the number of days in the given Islamic year
* @draft ICU 2.4
*/
int32_t IslamicUmalquraCalendar::handleGetYearLength(int32_t extendedYear) const {
- if (extendedYearUMALQURA_YEAR_END) {
- return IslamicCivilCalendar::handleGetYearLength(extendedYear);
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t length = yearLength(extendedYear, status);
+ if (U_FAILURE(status)) {
+ // fallback to normal Islamic calendar length 355 day a year if we
+ // encounter error and cannot propagate.
+ return 355;
}
- int length = 0;
- UErrorCode internalStatus = U_ZERO_ERROR;
- for(int i=0; i<12; i++) {
- length += handleGetMonthLength(extendedYear, i, internalStatus);
- }
- U_ASSERT(U_SUCCESS(internalStatus));
return length;
}
@@ -868,12 +917,17 @@ int32_t IslamicUmalquraCalendar::handleGetYearLength(int32_t extendedYear) const
* @draft ICU 2.4
*/
void IslamicUmalquraCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) {
- if (U_FAILURE(status)) return;
+ if (U_FAILURE(status)) {
+ return;
+ }
int64_t year;
int32_t month;
int32_t days = julianDay - getEpoc();
- static int64_t kUmalquraStart = yearStart(UMALQURA_YEAR_START);
+ static int64_t kUmalquraStart = yearStart(UMALQURA_YEAR_START, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
if (days < kUmalquraStart) {
IslamicCivilCalendar::handleComputeFields(julianDay, status);
return;
@@ -886,13 +940,16 @@ void IslamicUmalquraCalendar::handleComputeFields(int32_t julianDay, UErrorCode
int32_t d = 1;
// need a slight correction to some
while (d > 0) {
- d = days - yearStart(++year) + 1;
- int32_t yearLength = handleGetYearLength(year);
- if (d == yearLength) {
+ d = days - yearStart(++year, status) + 1;
+ int32_t length = yearLength(year, status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ if (d == length) {
month = 11;
break;
}
- if (d < yearLength){
+ if (d < length){
int32_t monthLen = handleGetMonthLength(year, month, status);
for (month = 0;
d > monthLen;
diff --git a/icu4c/source/i18n/islamcal.h b/icu4c/source/i18n/islamcal.h
index 1fb9ecd506c..e42e681328b 100644
--- a/icu4c/source/i18n/islamcal.h
+++ b/icu4c/source/i18n/islamcal.h
@@ -201,7 +201,7 @@ class U_I18N_API IslamicCalendar : public Calendar {
* Return the day # on which the given year starts. Days are counted
* from the Hijri epoch, origin 0.
*/
- virtual int64_t yearStart(int32_t year) const;
+ virtual int64_t yearStart(int32_t year, UErrorCode& status) const;
/**
* Return the day # on which the given month starts. Days are counted
@@ -413,7 +413,7 @@ class U_I18N_API IslamicCivilCalendar : public IslamicCalendar {
* from the Hijri epoch, origin 0.
* @internal
*/
- virtual int64_t yearStart(int32_t year) const override;
+ virtual int64_t yearStart(int32_t year, UErrorCode& status) const override;
/**
* Return the day # on which the given month starts. Days are counted
@@ -596,7 +596,7 @@ class U_I18N_API IslamicUmalquraCalendar : public IslamicCivilCalendar {
* from the Hijri epoch, origin 0.
* @internal
*/
- virtual int64_t yearStart(int32_t year) const override;
+ virtual int64_t yearStart(int32_t year, UErrorCode& status) const override;
/**
* Return the day # on which the given month starts. Days are counted
@@ -640,6 +640,9 @@ class U_I18N_API IslamicUmalquraCalendar : public IslamicCivilCalendar {
* @internal
*/
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override;
+
+ private:
+ virtual int32_t yearLength(int32_t extendedYear, UErrorCode& status) const;
};
diff --git a/icu4c/source/i18n/japancal.cpp b/icu4c/source/i18n/japancal.cpp
index c4873a5803c..c0dd9fad0dc 100644
--- a/icu4c/source/i18n/japancal.cpp
+++ b/icu4c/source/i18n/japancal.cpp
@@ -171,15 +171,19 @@ int32_t JapaneseCalendar::getDefaultMonthInYear(int32_t eyear, UErrorCode& statu
return month;
}
-int32_t JapaneseCalendar::getDefaultDayInMonth(int32_t eyear, int32_t month)
+int32_t JapaneseCalendar::getDefaultDayInMonth(int32_t eyear, int32_t month, UErrorCode& status)
{
+ if (U_FAILURE(status)) {
+ return 0;
+ }
int32_t era = internalGetEra();
int32_t day = 1;
int32_t eraStart[3] = { 0,0,0 };
- UErrorCode status = U_ZERO_ERROR;
gJapaneseEraRules->getStartDate(era, eraStart, status);
- U_ASSERT(U_SUCCESS(status));
+ if (U_FAILURE(status)) {
+ return 0;
+ }
if (eyear == eraStart[0] && (month == eraStart[1] - 1)) {
return eraStart[2];
}
diff --git a/icu4c/source/i18n/japancal.h b/icu4c/source/i18n/japancal.h
index bd2a2ca0755..627b12750b9 100644
--- a/icu4c/source/i18n/japancal.h
+++ b/icu4c/source/i18n/japancal.h
@@ -195,6 +195,7 @@ protected:
* taking year and era into account. Will return the first month of the given era, if
* the current year is an ascension year.
* @param eyear the extended year
+ * @param status Indicates the status.
* @internal
*/
virtual int32_t getDefaultMonthInYear(int32_t eyear, UErrorCode& status) override;
@@ -205,9 +206,10 @@ protected:
* era, if the current month is an ascension year and month.
* @param eyear the extended year
* @param mon the month in the year
+ * @param status Indicates the status.
* @internal
*/
- virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month) override;
+ virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month, UErrorCode& status) override;
virtual bool isEra0CountingBackward() const override { return false; }
};
diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp
index 2822e686fd9..cd7a08abfc2 100644
--- a/icu4c/source/i18n/smpdtfmt.cpp
+++ b/icu4c/source/i18n/smpdtfmt.cpp
@@ -1576,10 +1576,9 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
case UDAT_MONTH_FIELD:
case UDAT_STANDALONE_MONTH_FIELD:
if (uprv_strcmp(cal.getType(),"hebrew") == 0) {
- HebrewCalendar *hc = (HebrewCalendar*)&cal;
- if (hc->isLeapYear(hc->get(UCAL_YEAR,status)) && value == 6 && count >= 3 )
+ if (HebrewCalendar::isLeapYear(cal.get(UCAL_YEAR,status)) && value == 6 && count >= 3 )
value = 13; // Show alternate form for Adar II in leap years in Hebrew calendar.
- if (!hc->isLeapYear(hc->get(UCAL_YEAR,status)) && value >= 6 && count < 3 )
+ if (!HebrewCalendar::isLeapYear(cal.get(UCAL_YEAR,status)) && value >= 6 && count < 3 )
value--; // Adjust the month number down 1 in Hebrew non-leap years, i.e. Adar is 6, not 7.
}
{
diff --git a/icu4c/source/i18n/unicode/calendar.h b/icu4c/source/i18n/unicode/calendar.h
index fbe501c9d1c..a21df22ff05 100644
--- a/icu4c/source/i18n/unicode/calendar.h
+++ b/icu4c/source/i18n/unicode/calendar.h
@@ -2045,9 +2045,11 @@ protected:
* taking currently-set year and era into account. Defaults to 1 for Gregorian.
* @param eyear the extended year
* @param month the month in the year
+ * @param status Output param set to failure code on function return
+ * when this function fails.
* @internal
*/
- virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month);
+ virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month, UErrorCode& status);
//-------------------------------------------------------------------------
// Protected utility methods for use by subclasses. These are very handy
diff --git a/icu4c/source/test/intltest/caltest.cpp b/icu4c/source/test/intltest/caltest.cpp
index a104d0b8156..79e7e974b51 100644
--- a/icu4c/source/test/intltest/caltest.cpp
+++ b/icu4c/source/test/intltest/caltest.cpp
@@ -5651,7 +5651,7 @@ void CalendarTest::Test22633ChineseOverflow() {
U_ASSERT(U_SUCCESS(status));
cal->set(UCAL_EXTENDED_YEAR, -1594662558);
cal->get(UCAL_YEAR, status);
- assertTrue("Should return success", U_SUCCESS(status));
+ assertTrue("Should return failure", U_FAILURE(status));
cal->setTime(17000065021099877464213620139773683829419175940649608600213244013003611130029599692535053209683880603725167923910423116397083334648012657787978113960494455603744210944.000000, status);
cal->add(UCAL_YEAR, 1935762034, status);