erarules.h 3.1 KB

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