intl/icu/source/i18n/coptccal.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 * Copyright (C) 2003 - 2013, International Business Machines Corporation and
michael@0 4 * others. All Rights Reserved.
michael@0 5 *******************************************************************************
michael@0 6 */
michael@0 7
michael@0 8 #include "unicode/utypes.h"
michael@0 9
michael@0 10 #if !UCONFIG_NO_FORMATTING
michael@0 11
michael@0 12 #include "umutex.h"
michael@0 13 #include "coptccal.h"
michael@0 14 #include "cecal.h"
michael@0 15 #include <float.h>
michael@0 16
michael@0 17 U_NAMESPACE_BEGIN
michael@0 18
michael@0 19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CopticCalendar)
michael@0 20
michael@0 21 static const int32_t COPTIC_JD_EPOCH_OFFSET = 1824665;
michael@0 22
michael@0 23 //-------------------------------------------------------------------------
michael@0 24 // Constructors...
michael@0 25 //-------------------------------------------------------------------------
michael@0 26
michael@0 27 CopticCalendar::CopticCalendar(const Locale& aLocale, UErrorCode& success)
michael@0 28 : CECalendar(aLocale, success)
michael@0 29 {
michael@0 30 }
michael@0 31
michael@0 32 CopticCalendar::CopticCalendar (const CopticCalendar& other)
michael@0 33 : CECalendar(other)
michael@0 34 {
michael@0 35 }
michael@0 36
michael@0 37 CopticCalendar::~CopticCalendar()
michael@0 38 {
michael@0 39 }
michael@0 40
michael@0 41 Calendar*
michael@0 42 CopticCalendar::clone() const
michael@0 43 {
michael@0 44 return new CopticCalendar(*this);
michael@0 45 }
michael@0 46
michael@0 47 const char*
michael@0 48 CopticCalendar::getType() const
michael@0 49 {
michael@0 50 return "coptic";
michael@0 51 }
michael@0 52
michael@0 53 //-------------------------------------------------------------------------
michael@0 54 // Calendar framework
michael@0 55 //-------------------------------------------------------------------------
michael@0 56
michael@0 57 int32_t
michael@0 58 CopticCalendar::handleGetExtendedYear()
michael@0 59 {
michael@0 60 int32_t eyear;
michael@0 61 if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
michael@0 62 eyear = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
michael@0 63 } else {
michael@0 64 // The year defaults to the epoch start, the era to CE
michael@0 65 int32_t era = internalGet(UCAL_ERA, CE);
michael@0 66 if (era == BCE) {
michael@0 67 eyear = 1 - internalGet(UCAL_YEAR, 1); // Convert to extended year
michael@0 68 } else {
michael@0 69 eyear = internalGet(UCAL_YEAR, 1); // Default to year 1
michael@0 70 }
michael@0 71 }
michael@0 72 return eyear;
michael@0 73 }
michael@0 74
michael@0 75 void
michael@0 76 CopticCalendar::handleComputeFields(int32_t julianDay, UErrorCode &/*status*/)
michael@0 77 {
michael@0 78 int32_t eyear, month, day, era, year;
michael@0 79 jdToCE(julianDay, getJDEpochOffset(), eyear, month, day);
michael@0 80
michael@0 81 if (eyear <= 0) {
michael@0 82 era = BCE;
michael@0 83 year = 1 - eyear;
michael@0 84 } else {
michael@0 85 era = CE;
michael@0 86 year = eyear;
michael@0 87 }
michael@0 88
michael@0 89 internalSet(UCAL_EXTENDED_YEAR, eyear);
michael@0 90 internalSet(UCAL_ERA, era);
michael@0 91 internalSet(UCAL_YEAR, year);
michael@0 92 internalSet(UCAL_MONTH, month);
michael@0 93 internalSet(UCAL_DATE, day);
michael@0 94 internalSet(UCAL_DAY_OF_YEAR, (30 * month) + day);
michael@0 95 }
michael@0 96
michael@0 97 /**
michael@0 98 * The system maintains a static default century start date and Year. They are
michael@0 99 * initialized the first time they are used. Once the system default century date
michael@0 100 * and year are set, they do not change.
michael@0 101 */
michael@0 102 static UDate gSystemDefaultCenturyStart = DBL_MIN;
michael@0 103 static int32_t gSystemDefaultCenturyStartYear = -1;
michael@0 104 static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
michael@0 105
michael@0 106
michael@0 107 static void U_CALLCONV initializeSystemDefaultCentury() {
michael@0 108 UErrorCode status = U_ZERO_ERROR;
michael@0 109 CopticCalendar calendar(Locale("@calendar=coptic"), status);
michael@0 110 if (U_SUCCESS(status)) {
michael@0 111 calendar.setTime(Calendar::getNow(), status);
michael@0 112 calendar.add(UCAL_YEAR, -80, status);
michael@0 113 gSystemDefaultCenturyStart = calendar.getTime(status);
michael@0 114 gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
michael@0 115 }
michael@0 116 // We have no recourse upon failure unless we want to propagate the failure
michael@0 117 // out.
michael@0 118 }
michael@0 119
michael@0 120 UDate
michael@0 121 CopticCalendar::defaultCenturyStart() const
michael@0 122 {
michael@0 123 // lazy-evaluate systemDefaultCenturyStart
michael@0 124 umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
michael@0 125 return gSystemDefaultCenturyStart;
michael@0 126 }
michael@0 127
michael@0 128 int32_t
michael@0 129 CopticCalendar::defaultCenturyStartYear() const
michael@0 130 {
michael@0 131 // lazy-evaluate systemDefaultCenturyStart
michael@0 132 umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
michael@0 133 return gSystemDefaultCenturyStartYear;
michael@0 134 }
michael@0 135
michael@0 136
michael@0 137 int32_t
michael@0 138 CopticCalendar::getJDEpochOffset() const
michael@0 139 {
michael@0 140 return COPTIC_JD_EPOCH_OFFSET;
michael@0 141 }
michael@0 142
michael@0 143
michael@0 144 #if 0
michael@0 145 // We do not want to introduce this API in ICU4C.
michael@0 146 // It was accidentally introduced in ICU4J as a public API.
michael@0 147
michael@0 148 //-------------------------------------------------------------------------
michael@0 149 // Calendar system Conversion methods...
michael@0 150 //-------------------------------------------------------------------------
michael@0 151
michael@0 152 int32_t
michael@0 153 CopticCalendar::copticToJD(int32_t year, int32_t month, int32_t day)
michael@0 154 {
michael@0 155 return CECalendar::ceToJD(year, month, day, COPTIC_JD_EPOCH_OFFSET);
michael@0 156 }
michael@0 157 #endif
michael@0 158
michael@0 159 U_NAMESPACE_END
michael@0 160
michael@0 161 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 162 //eof

mercurial