tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

buddhcal.cpp (2735B)


      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 :   GregorianCalendar(aLocale, success)
     38 {
     39 }
     40 
     41 BuddhistCalendar::~BuddhistCalendar()
     42 {
     43 }
     44 
     45 BuddhistCalendar::BuddhistCalendar(const BuddhistCalendar& source)
     46 : GregorianCalendar(source)
     47 {
     48 }
     49 
     50 BuddhistCalendar* BuddhistCalendar::clone() const
     51 {
     52    return new BuddhistCalendar(*this);
     53 }
     54 
     55 const char *BuddhistCalendar::getType() const
     56 {
     57    return "buddhist";
     58 }
     59 
     60 int32_t BuddhistCalendar::handleGetExtendedYear(UErrorCode& status)
     61 {
     62    if (U_FAILURE(status)) {
     63        return 0;
     64    }
     65    // EXTENDED_YEAR in BuddhistCalendar is a Gregorian year.
     66    // The default value of EXTENDED_YEAR is 1970 (Buddhist 2513)
     67    if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
     68        return internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
     69    }
     70    // extended year is a gregorian year, where 1 = 1AD,  0 = 1BC, -1 = 2BC, etc
     71    int32_t year = internalGet(UCAL_YEAR, kGregorianEpoch - kBuddhistEraStart);
     72    if (uprv_add32_overflow(year, kBuddhistEraStart, &year)) {
     73        status = U_ILLEGAL_ARGUMENT_ERROR;
     74        return 0;
     75    }
     76    return year;
     77 }
     78 
     79 void BuddhistCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status)
     80 {
     81    GregorianCalendar::handleComputeFields(julianDay, status);
     82    int32_t y = internalGet(UCAL_EXTENDED_YEAR) - kBuddhistEraStart;
     83    internalSet(UCAL_ERA, 0);
     84    internalSet(UCAL_YEAR, y);
     85 }
     86 
     87 int32_t BuddhistCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
     88 {
     89    if(field == UCAL_ERA) {
     90        return BE;
     91    }
     92    return GregorianCalendar::handleGetLimit(field,limitType);
     93 }
     94 
     95 IMPL_SYSTEM_DEFAULT_CENTURY(BuddhistCalendar, "@calendar=buddhist")
     96 
     97 U_NAMESPACE_END
     98 
     99 #endif