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(push) |
24 | #pragma warning(disable: 4661) |
25 | #endif |
26 | template class U_I18N_API LocalPointerBase<int32_t>; |
27 | template class U_I18N_API LocalMemory<int32_t>; |
28 | #if defined(_MSC_VER) |
29 | #pragma warning(pop) |
30 | #endif |
31 | #endif |
32 | |
33 | class U_I18N_API EraRules : public UMemory { |
34 | public: |
35 | ~EraRules(); |
36 | |
37 | static EraRules* createInstance(const char *calType, UBool includeTentativeEra, UErrorCode& status); |
38 | |
39 | /** |
40 | * Gets number of effective eras |
41 | * @return number of effective eras |
42 | */ |
43 | inline int32_t getNumberOfEras() const { |
44 | return numEras; |
45 | } |
46 | |
47 | /** |
48 | * Gets start date of an era |
49 | * @param eraIdx Era index |
50 | * @param fields Receives date fields. The result includes values of year, month, |
51 | * day of month in this order. When an era has no start date, the result |
52 | * will be January 1st in year whose value is minimum integer. |
53 | * @param status Receives status. |
54 | */ |
55 | void getStartDate(int32_t eraIdx, int32_t (&fields)[3], UErrorCode& status) const; |
56 | |
57 | /** |
58 | * Gets start year of an era |
59 | * @param eraIdx Era index |
60 | * @param status Receives status. |
61 | * @return The first year of an era. When a era has no start date, minimum int32 |
62 | * value is returned. |
63 | */ |
64 | int32_t getStartYear(int32_t eraIdx, UErrorCode& status) const; |
65 | |
66 | /** |
67 | * Returns era index for the specified year/month/day. |
68 | * @param year Year |
69 | * @param month Month (1-base) |
70 | * @param day Day of month |
71 | * @param status Receives status |
72 | * @return era index (or 0, when the specified date is before the first era) |
73 | */ |
74 | int32_t getEraIndex(int32_t year, int32_t month, int32_t day, UErrorCode& status) const; |
75 | |
76 | /** |
77 | * Gets the current era index. This is calculated only once for an instance of |
78 | * EraRules. The current era calculation is based on the default time zone at |
79 | * the time of instantiation. |
80 | * |
81 | * @return era index of current era (or 0, when current date is before the first era) |
82 | */ |
83 | inline int32_t getCurrentEraIndex() const { |
84 | return currentEra; |
85 | } |
86 | |
87 | private: |
88 | EraRules(LocalMemory<int32_t>& eraStartDates, int32_t numEra); |
89 | |
90 | void initCurrentEra(); |
91 | |
92 | LocalMemory<int32_t> startDates; |
93 | int32_t numEras; |
94 | int32_t currentEra; |
95 | }; |
96 | |
97 | U_NAMESPACE_END |
98 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
99 | #endif /* ERARULES_H_ */ |
100 | |