Coverage Report

Created: 2025-06-13 06:34

/src/icu/icu4c/source/i18n/ethpccal.cpp
Line
Count
Source (jump to first uncovered line)
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
0
:   CECalendar(aLocale, success)
36
0
{
37
0
}
38
39
EthiopicCalendar::~EthiopicCalendar()
40
0
{
41
0
}
42
43
EthiopicCalendar*
44
EthiopicCalendar::clone() const
45
0
{
46
0
    return new EthiopicCalendar(*this);
47
0
}
48
49
const char *
50
EthiopicCalendar::getType() const
51
0
{
52
0
    return "ethiopic";
53
0
}
54
55
//-------------------------------------------------------------------------
56
// Calendar framework
57
//-------------------------------------------------------------------------
58
59
int32_t
60
EthiopicCalendar::handleGetExtendedYear(UErrorCode& status)
61
0
{
62
0
    if (U_FAILURE(status)) {
63
0
        return 0;
64
0
    }
65
    // Ethiopic calendar uses EXTENDED_YEAR aligned to
66
    // Amelete Hihret year always.
67
0
    if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
68
0
        return internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
69
0
    }
70
    // The year defaults to the epoch start, the era to AMETE_MIHRET
71
0
    if (internalGet(UCAL_ERA, AMETE_MIHRET) == AMETE_MIHRET) {
72
0
        return internalGet(UCAL_YEAR, 1); // Default to year 1
73
0
    }
74
0
    int32_t year = internalGet(UCAL_YEAR, 1);
75
0
    if (uprv_add32_overflow(year, -AMETE_MIHRET_DELTA, &year)) {
76
0
        status = U_ILLEGAL_ARGUMENT_ERROR;
77
0
        return 0;
78
0
    }
79
0
    return year;
80
0
}
81
82
IMPL_SYSTEM_DEFAULT_CENTURY(EthiopicCalendar, "@calendar=ethiopic")
83
84
int32_t
85
EthiopicCalendar::getJDEpochOffset() const
86
0
{
87
0
    return JD_EPOCH_OFFSET_AMETE_MIHRET;
88
0
}
89
90
0
int32_t EthiopicCalendar::extendedYearToEra(int32_t extendedYear) const {
91
0
    return extendedYear <= 0 ? AMETE_ALEM : AMETE_MIHRET;
92
0
}
93
94
0
int32_t EthiopicCalendar::extendedYearToYear(int32_t extendedYear) const {
95
0
    return extendedYear <= 0 ? extendedYear + AMETE_MIHRET_DELTA : extendedYear;
96
0
}
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
0
:   EthiopicCalendar(aLocale, success)
110
0
{
111
0
}
112
113
EthiopicAmeteAlemCalendar::~EthiopicAmeteAlemCalendar()
114
{
115
}
116
117
EthiopicAmeteAlemCalendar*
118
EthiopicAmeteAlemCalendar::clone() const
119
0
{
120
0
    return new EthiopicAmeteAlemCalendar(*this);
121
0
}
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
0
{
136
0
    if (U_FAILURE(status)) {
137
0
        return 0;
138
0
    }
139
    // Ethiopic calendar uses EXTENDED_YEAR aligned to
140
    // Amelete Hihret year always.
141
0
    if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
142
0
        return internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
143
0
    }
144
    // Default to year 1 of Amelete Mihret
145
0
    int32_t year = internalGet(UCAL_YEAR, 1 + AMETE_MIHRET_DELTA);
146
0
    if (uprv_add32_overflow(year, -AMETE_MIHRET_DELTA, &year)) {
147
0
        status = U_ILLEGAL_ARGUMENT_ERROR;
148
0
        return 0;
149
0
    }
150
0
    return year;
151
0
}
152
153
0
int32_t EthiopicAmeteAlemCalendar::extendedYearToEra(int32_t /* extendedYear */) const {
154
0
    return AMETE_ALEM;
155
0
}
156
157
0
int32_t EthiopicAmeteAlemCalendar::extendedYearToYear(int32_t extendedYear) const {
158
0
    return extendedYear + AMETE_MIHRET_DELTA;
159
0
}
160
161
162
int32_t
163
EthiopicAmeteAlemCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
164
0
{
165
0
    if (field == UCAL_ERA) {
166
0
        return 0; // Only one era in this mode, era is always 0
167
0
    }
168
0
    return EthiopicCalendar::handleGetLimit(field, limitType);
169
0
}
170
171
int32_t
172
EthiopicAmeteAlemCalendar::defaultCenturyStartYear() const
173
0
{
174
0
    return EthiopicCalendar::defaultCenturyStartYear() + AMETE_MIHRET_DELTA;
175
0
}
176
177
178
0
int32_t EthiopicAmeteAlemCalendar::getRelatedYearDifference() const {
179
0
    constexpr int32_t kEthiopicAmeteAlemCalendarRelatedYearDifference = -5492;
180
0
    return kEthiopicAmeteAlemCalendarRelatedYearDifference;
181
0
}
182
U_NAMESPACE_END
183
184
#endif