Coverage Report

Created: 2026-06-07 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/icu/icu4c/source/i18n/buddhcal.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
* File BUDDHCAL.CPP
10
*
11
* Modification History:
12
*  05/13/2003    srl     copied from gregocal.cpp
13
*
14
*/
15
16
#include "unicode/utypes.h"
17
18
#if !UCONFIG_NO_FORMATTING
19
20
#include "buddhcal.h"
21
#include "gregoimp.h"
22
#include "unicode/gregocal.h"
23
#include "umutex.h"
24
#include <float.h>
25
26
U_NAMESPACE_BEGIN
27
28
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(BuddhistCalendar)
29
30
//static const int32_t kMaxEra = 0; // only 1 era
31
32
static const int32_t kBuddhistEraStart = -543;  // 544 BC (Gregorian)
33
34
static const int32_t kGregorianEpoch = 1970;    // used as the default value of EXTENDED_YEAR
35
36
BuddhistCalendar::BuddhistCalendar(const Locale& aLocale, UErrorCode& success)
37
238
:   GregorianCalendar(aLocale, success)
38
238
{
39
238
}
40
41
BuddhistCalendar::~BuddhistCalendar()
42
61.2k
{
43
61.2k
}
44
45
BuddhistCalendar::BuddhistCalendar(const BuddhistCalendar& source)
46
61.0k
: GregorianCalendar(source)
47
61.0k
{
48
61.0k
}
49
50
BuddhistCalendar* BuddhistCalendar::clone() const
51
61.0k
{
52
61.0k
    return new BuddhistCalendar(*this);
53
61.0k
}
54
55
const char *BuddhistCalendar::getType() const
56
535
{
57
535
    return "buddhist";
58
535
}
59
60
int32_t BuddhistCalendar::handleGetExtendedYear(UErrorCode& status)
61
61.0k
{
62
61.0k
    if (U_FAILURE(status)) {
63
0
        return 0;
64
0
    }
65
    // EXTENDED_YEAR in BuddhistCalendar is a Gregorian year.
66
    // The default value of EXTENDED_YEAR is 1970 (Buddhist 2513)
67
61.0k
    if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
68
60.3k
        return internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
69
60.3k
    }
70
    // extended year is a gregorian year, where 1 = 1AD,  0 = 1BC, -1 = 2BC, etc
71
703
    int32_t year = internalGet(UCAL_YEAR, kGregorianEpoch - kBuddhistEraStart);
72
703
    if (uprv_add32_overflow(year, kBuddhistEraStart, &year)) {
73
18
        status = U_ILLEGAL_ARGUMENT_ERROR;
74
18
        return 0;
75
18
    }
76
685
    return year;
77
703
}
78
79
void BuddhistCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status)
80
122k
{
81
122k
    GregorianCalendar::handleComputeFields(julianDay, status);
82
122k
    int32_t y = internalGet(UCAL_EXTENDED_YEAR) - kBuddhistEraStart;
83
122k
    internalSet(UCAL_ERA, 0);
84
122k
    internalSet(UCAL_YEAR, y);
85
122k
}
86
87
int32_t BuddhistCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
88
120k
{
89
120k
    if(field == UCAL_ERA) {
90
558
        return BE;
91
558
    }
92
120k
    return GregorianCalendar::handleGetLimit(field,limitType);
93
120k
}
94
95
IMPL_SYSTEM_DEFAULT_CENTURY(BuddhistCalendar, "@calendar=buddhist")
96
97
U_NAMESPACE_END
98
99
#endif