bug-2002735-ICU-23277-coptic-single-era.diff (3460B)
1 diff --git a/intl/icu/source/i18n/coptccal.cpp b/intl/icu/source/i18n/coptccal.cpp 2 --- a/intl/icu/source/i18n/coptccal.cpp 3 +++ b/intl/icu/source/i18n/coptccal.cpp 4 @@ -61,46 +61,43 @@ int32_t 5 CopticCalendar::handleGetExtendedYear(UErrorCode& status) 6 { 7 if (U_FAILURE(status)) { 8 return 0; 9 } 10 if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { 11 return internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1 12 } 13 - // The year defaults to the epoch start, the era to CE 14 - int32_t era = internalGet(UCAL_ERA, CE); 15 - if (era == BCE) { 16 - return 1 - internalGet(UCAL_YEAR, 1); // Convert to extended year 17 - } 18 - if (era == CE){ 19 - return internalGet(UCAL_YEAR, 1); // Default to year 1 20 - } 21 - status = U_ILLEGAL_ARGUMENT_ERROR; 22 - return 0; 23 + // The year defaults to the epoch start 24 + return internalGet(UCAL_YEAR, 1); // Default to year 1 25 } 26 27 IMPL_SYSTEM_DEFAULT_CENTURY(CopticCalendar, "@calendar=coptic") 28 29 int32_t 30 CopticCalendar::getJDEpochOffset() const 31 { 32 return COPTIC_JD_EPOCH_OFFSET; 33 } 34 35 int32_t CopticCalendar::extendedYearToEra(int32_t extendedYear) const { 36 - return extendedYear <= 0 ? BCE : CE; 37 + return CE; 38 } 39 40 int32_t CopticCalendar::extendedYearToYear(int32_t extendedYear) const { 41 - return extendedYear <= 0 ? 1 - extendedYear : extendedYear; 42 + return extendedYear; 43 } 44 45 -bool CopticCalendar::isEra0CountingBackward() const { 46 - return true; 47 +int32_t 48 +CopticCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const 49 +{ 50 + if (field == UCAL_ERA) { 51 + return 1; // Only one era, era is always 1 52 + } 53 + return CECalendar::handleGetLimit(field, limitType); 54 } 55 56 int32_t 57 CopticCalendar::getRelatedYearDifference() const { 58 constexpr int32_t kCopticCalendarRelatedYearDifference = 284; 59 return kCopticCalendarRelatedYearDifference; 60 } 61 62 diff --git a/intl/icu/source/i18n/coptccal.h b/intl/icu/source/i18n/coptccal.h 63 --- a/intl/icu/source/i18n/coptccal.h 64 +++ b/intl/icu/source/i18n/coptccal.h 65 @@ -165,16 +165,22 @@ protected: 66 int32_t getRelatedYearDifference() const override; 67 68 /** 69 * Return the extended year defined by the current fields. 70 * @internal 71 */ 72 virtual int32_t handleGetExtendedYear(UErrorCode& status) override; 73 74 + /** 75 + * Calculate the limit for a specified type of limit and field 76 + * @internal 77 + */ 78 + virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override; 79 + 80 DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY 81 82 /** 83 * Return the date offset from Julian 84 * @internal 85 */ 86 int32_t getJDEpochOffset() const override; 87 88 @@ -184,21 +190,16 @@ protected: 89 */ 90 int32_t extendedYearToEra(int32_t extendedYear) const override; 91 92 /** 93 * Compute the year from extended year. 94 * @internal 95 */ 96 int32_t extendedYearToYear(int32_t extendedYear) const override; 97 - 98 - /** 99 - * @internal 100 - */ 101 - bool isEra0CountingBackward() const override; 102 public: 103 /** 104 * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual 105 * override. This method is to implement a simple version of RTTI, since not all C++ 106 * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call 107 * this method. 108 * 109 * @return The class ID for this object. All objects of a given class have the