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