intl/icu/source/i18n/coptccal.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.

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

mercurial