Coverage Report

Created: 2026-06-23 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/icu/icu4c/source/i18n/erarules.h
Line
Count
Source
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
class U_I18N_API_CLASS EraRules : public UMemory {
18
public:
19
    U_I18N_API ~EraRules();
20
21
    U_I18N_API static EraRules* createInstance(const char* calType,
22
                                               UBool includeTentativeEra,
23
                                               UErrorCode& status);
24
25
    /**
26
     * Gets number of effective eras
27
     * @return  number of effective eras (not the same as max era code)
28
     */
29
0
    inline int32_t getNumberOfEras() const {
30
0
        return numEras;
31
0
    }
32
33
    /**
34
     * Gets maximum defined era code for the current calendar
35
     * @return  maximum defined era code
36
     */
37
10.8k
    inline int32_t getMaxEraCode() const {
38
10.8k
        return minEra + startDatesLength - 1;
39
10.8k
    }
40
41
    /**
42
     * Gets start date of an era
43
     * @param eraCode   Era code
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 eraCode, int32_t (&fields)[3], UErrorCode& status) const;
50
51
    /**
52
     * Gets start year of an era
53
     * @param eraCode   Era code
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
    U_I18N_API int32_t getStartYear(int32_t eraCode, UErrorCode& status) const;
59
60
    /**
61
     * Returns era code 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 code (or code of earliest era when date is before that era)
67
     */
68
    U_I18N_API int32_t getEraCode(int32_t year, int32_t month, int32_t day, UErrorCode& status) const;
69
70
    /**
71
     * Gets the current era code. This is calculated only once for an instance of
72
     * EraRules. The current era calculation is based on the default time zone at
73
     * the time of instantiation.
74
     *
75
     * @return era code of current era (or era code of earliest era when current date is before any era)
76
     */
77
1
    inline int32_t getCurrentEraCode() const {
78
1
        return currentEra;
79
1
    }
80
81
private:
82
    EraRules(LocalMemory<int32_t>& startDatesIn, int32_t startDatesLengthIn, int32_t minEraIn, int32_t numErasIn);
83
84
    void initCurrentEra();
85
86
    LocalMemory<int32_t> startDates;
87
    int32_t startDatesLength;
88
    int32_t minEra;  // minimum valid era code, for first entry in startDates
89
    int32_t numEras; // number of valid era codes (not necessarily the same as startDates length
90
    int32_t currentEra;
91
};
92
93
U_NAMESPACE_END
94
#endif /* #if !UCONFIG_NO_FORMATTING */
95
#endif /* ERARULES_H_ */