intl/icu/source/i18n/taiwncal.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 * File TAIWNCAL.CPP
michael@0 8 *
michael@0 9 * Modification History:
michael@0 10 * 05/13/2003 srl copied from gregocal.cpp
michael@0 11 * 06/29/2007 srl copied from buddhcal.cpp
michael@0 12 * 05/12/2008 jce modified to use calendar=roc per CLDR
michael@0 13 *
michael@0 14 */
michael@0 15
michael@0 16 #include "unicode/utypes.h"
michael@0 17
michael@0 18 #if !UCONFIG_NO_FORMATTING
michael@0 19
michael@0 20 #include "taiwncal.h"
michael@0 21 #include "unicode/gregocal.h"
michael@0 22 #include "umutex.h"
michael@0 23 #include <float.h>
michael@0 24
michael@0 25 U_NAMESPACE_BEGIN
michael@0 26
michael@0 27 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TaiwanCalendar)
michael@0 28
michael@0 29 static const int32_t kTaiwanEraStart = 1911; // 1911 (Gregorian)
michael@0 30
michael@0 31 static const int32_t kGregorianEpoch = 1970;
michael@0 32
michael@0 33 TaiwanCalendar::TaiwanCalendar(const Locale& aLocale, UErrorCode& success)
michael@0 34 : GregorianCalendar(aLocale, success)
michael@0 35 {
michael@0 36 setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
michael@0 37 }
michael@0 38
michael@0 39 TaiwanCalendar::~TaiwanCalendar()
michael@0 40 {
michael@0 41 }
michael@0 42
michael@0 43 TaiwanCalendar::TaiwanCalendar(const TaiwanCalendar& source)
michael@0 44 : GregorianCalendar(source)
michael@0 45 {
michael@0 46 }
michael@0 47
michael@0 48 TaiwanCalendar& TaiwanCalendar::operator= ( const TaiwanCalendar& right)
michael@0 49 {
michael@0 50 GregorianCalendar::operator=(right);
michael@0 51 return *this;
michael@0 52 }
michael@0 53
michael@0 54 Calendar* TaiwanCalendar::clone(void) const
michael@0 55 {
michael@0 56 return new TaiwanCalendar(*this);
michael@0 57 }
michael@0 58
michael@0 59 const char *TaiwanCalendar::getType() const
michael@0 60 {
michael@0 61 return "roc";
michael@0 62 }
michael@0 63
michael@0 64 int32_t TaiwanCalendar::handleGetExtendedYear()
michael@0 65 {
michael@0 66 // EXTENDED_YEAR in TaiwanCalendar is a Gregorian year
michael@0 67 // The default value of EXTENDED_YEAR is 1970 (Minguo 59)
michael@0 68 int32_t year = kGregorianEpoch;
michael@0 69
michael@0 70 if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR
michael@0 71 && newerField(UCAL_EXTENDED_YEAR, UCAL_ERA) == UCAL_EXTENDED_YEAR) {
michael@0 72 year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
michael@0 73 } else {
michael@0 74 int32_t era = internalGet(UCAL_ERA, MINGUO);
michael@0 75 if(era == MINGUO) {
michael@0 76 year = internalGet(UCAL_YEAR, 1) + kTaiwanEraStart;
michael@0 77 } else if(era == BEFORE_MINGUO) {
michael@0 78 year = 1 - internalGet(UCAL_YEAR, 1) + kTaiwanEraStart;
michael@0 79 }
michael@0 80 }
michael@0 81 return year;
michael@0 82 }
michael@0 83
michael@0 84 void TaiwanCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status)
michael@0 85 {
michael@0 86 GregorianCalendar::handleComputeFields(julianDay, status);
michael@0 87 int32_t y = internalGet(UCAL_EXTENDED_YEAR) - kTaiwanEraStart;
michael@0 88 if(y>0) {
michael@0 89 internalSet(UCAL_ERA, MINGUO);
michael@0 90 internalSet(UCAL_YEAR, y);
michael@0 91 } else {
michael@0 92 internalSet(UCAL_ERA, BEFORE_MINGUO);
michael@0 93 internalSet(UCAL_YEAR, 1-y);
michael@0 94 }
michael@0 95 }
michael@0 96
michael@0 97 int32_t TaiwanCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
michael@0 98 {
michael@0 99 if(field == UCAL_ERA) {
michael@0 100 if(limitType == UCAL_LIMIT_MINIMUM || limitType == UCAL_LIMIT_GREATEST_MINIMUM) {
michael@0 101 return BEFORE_MINGUO;
michael@0 102 } else {
michael@0 103 return MINGUO;
michael@0 104 }
michael@0 105 } else {
michael@0 106 return GregorianCalendar::handleGetLimit(field,limitType);
michael@0 107 }
michael@0 108 }
michael@0 109
michael@0 110 #if 0
michael@0 111 void TaiwanCalendar::timeToFields(UDate theTime, UBool quick, UErrorCode& status)
michael@0 112 {
michael@0 113 //Calendar::timeToFields(theTime, quick, status);
michael@0 114
michael@0 115 int32_t era = internalGet(UCAL_ERA);
michael@0 116 int32_t year = internalGet(UCAL_YEAR);
michael@0 117
michael@0 118 if(era == GregorianCalendar::BC) {
michael@0 119 year = 1-year;
michael@0 120 era = TaiwanCalendar::MINGUO;
michael@0 121 } else if(era == GregorianCalendar::AD) {
michael@0 122 era = TaiwanCalendar::MINGUO;
michael@0 123 } else {
michael@0 124 status = U_INTERNAL_PROGRAM_ERROR;
michael@0 125 }
michael@0 126
michael@0 127 year = year - kTaiwanEraStart;
michael@0 128
michael@0 129 internalSet(UCAL_ERA, era);
michael@0 130 internalSet(UCAL_YEAR, year);
michael@0 131 }
michael@0 132 #endif
michael@0 133
michael@0 134 /**
michael@0 135 * The system maintains a static default century start date and Year. They are
michael@0 136 * initialized the first time they are used. Once the system default century date
michael@0 137 * and year are set, they do not change.
michael@0 138 */
michael@0 139 static UDate gSystemDefaultCenturyStart = DBL_MIN;
michael@0 140 static int32_t gSystemDefaultCenturyStartYear = -1;
michael@0 141 static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
michael@0 142
michael@0 143 UBool TaiwanCalendar::haveDefaultCentury() const
michael@0 144 {
michael@0 145 return TRUE;
michael@0 146 }
michael@0 147
michael@0 148 static void U_CALLCONV initializeSystemDefaultCentury()
michael@0 149 {
michael@0 150 // initialize systemDefaultCentury and systemDefaultCenturyYear based
michael@0 151 // on the current time. They'll be set to 80 years before
michael@0 152 // the current time.
michael@0 153 UErrorCode status = U_ZERO_ERROR;
michael@0 154 TaiwanCalendar calendar(Locale("@calendar=roc"),status);
michael@0 155 if (U_SUCCESS(status))
michael@0 156 {
michael@0 157 calendar.setTime(Calendar::getNow(), status);
michael@0 158 calendar.add(UCAL_YEAR, -80, status);
michael@0 159
michael@0 160 gSystemDefaultCenturyStart = calendar.getTime(status);
michael@0 161 gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
michael@0 162 }
michael@0 163 // We have no recourse upon failure unless we want to propagate the failure
michael@0 164 // out.
michael@0 165 }
michael@0 166
michael@0 167 UDate TaiwanCalendar::defaultCenturyStart() const {
michael@0 168 // lazy-evaluate systemDefaultCenturyStart
michael@0 169 umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
michael@0 170 return gSystemDefaultCenturyStart;
michael@0 171 }
michael@0 172
michael@0 173 int32_t TaiwanCalendar::defaultCenturyStartYear() const {
michael@0 174 // lazy-evaluate systemDefaultCenturyStartYear
michael@0 175 umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
michael@0 176 return gSystemDefaultCenturyStartYear;
michael@0 177 }
michael@0 178
michael@0 179 U_NAMESPACE_END
michael@0 180
michael@0 181 #endif

mercurial