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