1 // © 2018 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 4 #ifndef ERARULES_H_ 5 #define ERARULES_H_ 6 7 #include "unicode/utypes.h" 8 9 #if !UCONFIG_NO_FORMATTING 10 11 #include "unicode/localpointer.h" 12 #include "unicode/uobject.h" 13 #include "cmemory.h" 14 15 U_NAMESPACE_BEGIN 16 17 // Export an explicit template instantiation of LocalMemory used as a data member of EraRules. 18 // When building DLLs for Windows this is required even though no direct access leaks out of the i18n library. 19 // See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples. 20 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 21 #if defined(_MSC_VER) 22 // Ignore warning 4661 as LocalPointerBase does not use operator== or operator!= 23 #pragma warning(suppress: 4661) 24 #endif 25 template class U_I18N_API LocalPointerBase<int32_t>; 26 template class U_I18N_API LocalMemory<int32_t>; 27 #endif 28 29 class U_I18N_API EraRules : public UMemory { 30 public: 31 ~EraRules(); 32 33 static EraRules* createInstance(const char *calType, UBool includeTentativeEra, UErrorCode& status); 34 35 /** 36 * Gets number of effective eras 37 * @return number of effective eras 38 */ getNumberOfEras()39 inline int32_t getNumberOfEras() const { 40 return numEras; 41 } 42 43 /** 44 * Gets start date of an era 45 * @param eraIdx Era index 46 * @param fields Receives date fields. The result includes values of year, month, 47 * day of month in this order. When an era has no start date, the result 48 * will be January 1st in year whose value is minimum integer. 49 * @param status Receives status. 50 */ 51 void getStartDate(int32_t eraIdx, int32_t (&fields)[3], UErrorCode& status) const; 52 53 /** 54 * Gets start year of an era 55 * @param eraIdx Era index 56 * @param status Receives status. 57 * @return The first year of an era. When a era has no start date, minimum int32 58 * value is returned. 59 */ 60 int32_t getStartYear(int32_t eraIdx, UErrorCode& status) const; 61 62 /** 63 * Returns era index for the specified year/month/day. 64 * @param year Year 65 * @param month Month (1-base) 66 * @param day Day of month 67 * @param status Receives status 68 * @return era index (or 0, when the specified date is before the first era) 69 */ 70 int32_t getEraIndex(int32_t year, int32_t month, int32_t day, UErrorCode& status) const; 71 72 /** 73 * Gets the current era index. This is calculated only once for an instance of 74 * EraRules. 75 * 76 * @return era index of current era (or 0, when current date is before the first era) 77 */ getCurrentEraIndex()78 inline int32_t getCurrentEraIndex() const { 79 return currentEra; 80 } 81 82 private: 83 EraRules(LocalMemory<int32_t>& eraStartDates, int32_t numEra); 84 85 void initCurrentEra(); 86 87 LocalMemory<int32_t> startDates; 88 int32_t numEras; 89 int32_t currentEra; 90 }; 91 92 U_NAMESPACE_END 93 #endif /* #if !UCONFIG_NO_FORMATTING */ 94 #endif /* ERARULES_H_ */ 95