2 *******************************************************************************
3 * Copyright (C) 2003 - 2008, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_FORMATTING
19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CopticCalendar
)
21 static const int32_t COPTIC_JD_EPOCH_OFFSET
= 1824665;
23 //-------------------------------------------------------------------------
25 //-------------------------------------------------------------------------
27 CopticCalendar::CopticCalendar(const Locale
& aLocale
, UErrorCode
& success
)
28 : CECalendar(aLocale
, success
)
32 CopticCalendar::CopticCalendar (const CopticCalendar
& other
)
37 CopticCalendar::~CopticCalendar()
42 CopticCalendar::clone() const
44 return new CopticCalendar(*this);
48 CopticCalendar::getType() const
53 //-------------------------------------------------------------------------
55 //-------------------------------------------------------------------------
58 CopticCalendar::handleGetExtendedYear()
61 if (newerField(UCAL_EXTENDED_YEAR
, UCAL_YEAR
) == UCAL_EXTENDED_YEAR
) {
62 eyear
= internalGet(UCAL_EXTENDED_YEAR
, 1); // Default to year 1
64 // The year defaults to the epoch start, the era to CE
65 int32_t era
= internalGet(UCAL_ERA
, CE
);
67 eyear
= 1 - internalGet(UCAL_YEAR
, 1); // Convert to extended year
69 eyear
= internalGet(UCAL_YEAR
, 1); // Default to year 1
76 CopticCalendar::handleComputeFields(int32_t julianDay
, UErrorCode
&status
)
78 int32_t eyear
, month
, day
, era
, year
;
79 jdToCE(julianDay
, getJDEpochOffset(), eyear
, month
, day
);
89 internalSet(UCAL_EXTENDED_YEAR
, eyear
);
90 internalSet(UCAL_ERA
, era
);
91 internalSet(UCAL_YEAR
, year
);
92 internalSet(UCAL_MONTH
, month
);
93 internalSet(UCAL_DATE
, day
);
94 internalSet(UCAL_DAY_OF_YEAR
, (30 * month
) + day
);
97 const UDate
CopticCalendar::fgSystemDefaultCentury
= DBL_MIN
;
98 const int32_t CopticCalendar::fgSystemDefaultCenturyYear
= -1;
100 UDate
CopticCalendar::fgSystemDefaultCenturyStart
= DBL_MIN
;
101 int32_t CopticCalendar::fgSystemDefaultCenturyStartYear
= -1;
104 CopticCalendar::defaultCenturyStart() const
106 initializeSystemDefaultCentury();
108 // use defaultCenturyStart unless it's the flag value;
109 // then use systemDefaultCenturyStart
110 return fgSystemDefaultCenturyStart
;
114 CopticCalendar::defaultCenturyStartYear() const
116 initializeSystemDefaultCentury();
118 // use defaultCenturyStart unless it's the flag value;
119 // then use systemDefaultCenturyStart
120 return fgSystemDefaultCenturyStartYear
;
124 CopticCalendar::initializeSystemDefaultCentury()
126 // lazy-evaluate systemDefaultCenturyStart
128 UMTX_CHECK(NULL
, (fgSystemDefaultCenturyStart
== fgSystemDefaultCentury
), needsUpdate
);
134 UErrorCode status
= U_ZERO_ERROR
;
136 CopticCalendar
calendar(Locale("@calendar=coptic"), status
);
137 if (U_SUCCESS(status
)) {
138 calendar
.setTime(Calendar::getNow(), status
);
139 calendar
.add(UCAL_YEAR
, -80, status
);
140 UDate newStart
= calendar
.getTime(status
);
141 int32_t newYear
= calendar
.get(UCAL_YEAR
, status
);
144 fgSystemDefaultCenturyStart
= newStart
;
145 fgSystemDefaultCenturyStartYear
= newYear
;
149 // We have no recourse upon failure unless we want to propagate the failure
154 CopticCalendar::getJDEpochOffset() const
156 return COPTIC_JD_EPOCH_OFFSET
;
161 // We do not want to introduce this API in ICU4C.
162 // It was accidentally introduced in ICU4J as a public API.
164 //-------------------------------------------------------------------------
165 // Calendar system Conversion methods...
166 //-------------------------------------------------------------------------
169 CopticCalendar::copticToJD(int32_t year
, int32_t month
, int32_t day
)
171 return CECalendar::ceToJD(year
, month
, day
, COPTIC_JD_EPOCH_OFFSET
);
177 #endif /* #if !UCONFIG_NO_FORMATTING */