Coverage Report

Created: 2025-10-24 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/icu/icu4c/source/i18n/ethpccal.cpp
Line
Count
Source
1
// © 2016 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
/*
4
*******************************************************************************
5
* Copyright (C) 2003 - 2013, International Business Machines Corporation and
6
* others. All Rights Reserved.
7
*******************************************************************************
8
*/
9
10
#include "unicode/utypes.h"
11
12
#if !UCONFIG_NO_FORMATTING
13
14
#include "gregoimp.h"
15
#include "umutex.h"
16
#include "ethpccal.h"
17
#include "cecal.h"
18
#include <float.h>
19
20
U_NAMESPACE_BEGIN
21
22
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EthiopicCalendar)
23
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EthiopicAmeteAlemCalendar)
24
25
static const int32_t JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
26
static const int32_t JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856;
27
static const int32_t AMETE_MIHRET_DELTA = 5500; // 5501 - 1 (Amete Alem 5501 = Amete Mihret 1)
28
29
//-------------------------------------------------------------------------
30
// Constructors...
31
//-------------------------------------------------------------------------
32
33
EthiopicCalendar::EthiopicCalendar(const Locale& aLocale,
34
                                   UErrorCode& success)
35
175
:   CECalendar(aLocale, success)
36
175
{
37
175
}
38
39
EthiopicCalendar::~EthiopicCalendar()
40
2.75k
{
41
2.75k
}
42
43
EthiopicCalendar*
44
EthiopicCalendar::clone() const
45
1.55k
{
46
1.55k
    return new EthiopicCalendar(*this);
47
1.55k
}
48
49
const char *
50
EthiopicCalendar::getType() const
51
24
{
52
24
    return "ethiopic";
53
24
}
54
55
//-------------------------------------------------------------------------
56
// Calendar framework
57
//-------------------------------------------------------------------------
58
59
int32_t
60
EthiopicCalendar::handleGetExtendedYear(UErrorCode& status)
61
2.93k
{
62
2.93k
    if (U_FAILURE(status)) {
63
0
        return 0;
64
0
    }
65
    // Ethiopic calendar uses EXTENDED_YEAR aligned to
66
    // Amelete Hihret year always.
67
2.93k
    if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
68
1.05k
        return internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
69
1.05k
    }
70
    // The year defaults to the epoch start, the era to AMETE_MIHRET
71
1.88k
    if (internalGet(UCAL_ERA, AMETE_MIHRET) == AMETE_MIHRET) {
72
1.23k
        return internalGet(UCAL_YEAR, 1); // Default to year 1
73
1.23k
    }
74
648
    int32_t year = internalGet(UCAL_YEAR, 1);
75
648
    if (uprv_add32_overflow(year, -AMETE_MIHRET_DELTA, &year)) {
76
23
        status = U_ILLEGAL_ARGUMENT_ERROR;
77
23
        return 0;
78
23
    }
79
625
    return year;
80
648
}
81
82
IMPL_SYSTEM_DEFAULT_CENTURY(EthiopicCalendar, "@calendar=ethiopic")
83
84
int32_t
85
EthiopicCalendar::getJDEpochOffset() const
86
21.4k
{
87
21.4k
    return JD_EPOCH_OFFSET_AMETE_MIHRET;
88
21.4k
}
89
90
5.24k
int32_t EthiopicCalendar::extendedYearToEra(int32_t extendedYear) const {
91
5.24k
    return extendedYear <= 0 ? AMETE_ALEM : AMETE_MIHRET;
92
5.24k
}
93
94
5.24k
int32_t EthiopicCalendar::extendedYearToYear(int32_t extendedYear) const {
95
5.24k
    return extendedYear <= 0 ? extendedYear + AMETE_MIHRET_DELTA : extendedYear;
96
5.24k
}
97
98
0
int32_t EthiopicCalendar::getRelatedYearDifference() const {
99
0
    constexpr int32_t kEthiopicCalendarRelatedYearDifference = 8;
100
0
    return kEthiopicCalendarRelatedYearDifference;
101
0
}
102
103
//-------------------------------------------------------------------------
104
// Constructors...
105
//-------------------------------------------------------------------------
106
107
EthiopicAmeteAlemCalendar::EthiopicAmeteAlemCalendar(const Locale& aLocale,
108
                                   UErrorCode& success)
109
81
:   EthiopicCalendar(aLocale, success)
110
81
{
111
81
}
112
113
EthiopicAmeteAlemCalendar::~EthiopicAmeteAlemCalendar()
114
{
115
}
116
117
EthiopicAmeteAlemCalendar*
118
EthiopicAmeteAlemCalendar::clone() const
119
1.07k
{
120
1.07k
    return new EthiopicAmeteAlemCalendar(*this);
121
1.07k
}
122
123
//-------------------------------------------------------------------------
124
// Calendar framework
125
//-------------------------------------------------------------------------
126
127
const char *
128
EthiopicAmeteAlemCalendar::getType() const
129
0
{
130
0
    return "ethiopic-amete-alem";
131
0
}
132
133
int32_t
134
EthiopicAmeteAlemCalendar::handleGetExtendedYear(UErrorCode& status)
135
2.08k
{
136
2.08k
    if (U_FAILURE(status)) {
137
0
        return 0;
138
0
    }
139
    // Ethiopic calendar uses EXTENDED_YEAR aligned to
140
    // Amelete Hihret year always.
141
2.08k
    if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
142
1.63k
        return internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
143
1.63k
    }
144
    // Default to year 1
145
450
    return internalGet(UCAL_YEAR, 1);
146
2.08k
}
147
148
int32_t
149
EthiopicAmeteAlemCalendar::getJDEpochOffset() const
150
17.3k
{
151
17.3k
    return JD_EPOCH_OFFSET_AMETE_ALEM;
152
17.3k
}
153
154
4.38k
int32_t EthiopicAmeteAlemCalendar::extendedYearToEra(int32_t /* extendedYear */) const {
155
4.38k
    return AMETE_ALEM;
156
4.38k
}
157
158
4.38k
int32_t EthiopicAmeteAlemCalendar::extendedYearToYear(int32_t extendedYear) const {
159
4.38k
    return extendedYear;
160
4.38k
}
161
162
163
int32_t
164
EthiopicAmeteAlemCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
165
3.69k
{
166
3.69k
    if (field == UCAL_ERA) {
167
704
        return 0; // Only one era in this mode, era is always 0
168
704
    }
169
2.98k
    return EthiopicCalendar::handleGetLimit(field, limitType);
170
3.69k
}
171
172
U_NAMESPACE_END
173
174
#endif