intl/icu/source/i18n/cecal.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/cecal.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,149 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +* Copyright (C) 2003 - 2009, International Business Machines Corporation and  *
     1.7 +* others. All Rights Reserved.                                                *
     1.8 +*******************************************************************************
     1.9 +*/
    1.10 +
    1.11 +#include "unicode/utypes.h"
    1.12 +
    1.13 +#if !UCONFIG_NO_FORMATTING
    1.14 +
    1.15 +#include "cecal.h"
    1.16 +#include "gregoimp.h"   //Math
    1.17 +
    1.18 +U_NAMESPACE_BEGIN
    1.19 +
    1.20 +static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
    1.21 +    // Minimum  Greatest    Least  Maximum
    1.22 +    //           Minimum  Maximum
    1.23 +    {        0,        0,        1,        1}, // ERA
    1.24 +    {        1,        1,  5000000,  5000000}, // YEAR
    1.25 +    {        0,        0,       12,       12}, // MONTH
    1.26 +    {        1,        1,       52,       53}, // WEEK_OF_YEAR
    1.27 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
    1.28 +    {        1,        1,        5,       30}, // DAY_OF_MONTH
    1.29 +    {        1,        1,      365,      366}, // DAY_OF_YEAR
    1.30 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
    1.31 +    {       -1,       -1,        1,        5}, // DAY_OF_WEEK_IN_MONTH
    1.32 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
    1.33 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
    1.34 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
    1.35 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
    1.36 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
    1.37 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
    1.38 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
    1.39 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
    1.40 +    { -5000000, -5000000,  5000000,  5000000}, // YEAR_WOY
    1.41 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
    1.42 +    { -5000000, -5000000,  5000000,  5000000}, // EXTENDED_YEAR
    1.43 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
    1.44 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
    1.45 +    {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
    1.46 +};
    1.47 +
    1.48 +//-------------------------------------------------------------------------
    1.49 +// Constructors...
    1.50 +//-------------------------------------------------------------------------
    1.51 +
    1.52 +CECalendar::CECalendar(const Locale& aLocale, UErrorCode& success)
    1.53 +:   Calendar(TimeZone::createDefault(), aLocale, success)
    1.54 +{
    1.55 +    setTimeInMillis(getNow(), success);
    1.56 +}
    1.57 +
    1.58 +CECalendar::CECalendar (const CECalendar& other) 
    1.59 +:   Calendar(other)
    1.60 +{
    1.61 +}
    1.62 +
    1.63 +CECalendar::~CECalendar()
    1.64 +{
    1.65 +}
    1.66 +
    1.67 +CECalendar&
    1.68 +CECalendar::operator=(const CECalendar& right)
    1.69 +{
    1.70 +    Calendar::operator=(right);
    1.71 +    return *this;
    1.72 +}
    1.73 +
    1.74 +//-------------------------------------------------------------------------
    1.75 +// Calendar framework
    1.76 +//-------------------------------------------------------------------------
    1.77 +
    1.78 +int32_t
    1.79 +CECalendar::handleComputeMonthStart(int32_t eyear,int32_t emonth, UBool /*useMonth*/) const
    1.80 +{
    1.81 +    return ceToJD(eyear, emonth, 0, getJDEpochOffset());
    1.82 +}
    1.83 +
    1.84 +int32_t
    1.85 +CECalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
    1.86 +{
    1.87 +    return LIMITS[field][limitType];
    1.88 +}
    1.89 +
    1.90 +UBool
    1.91 +CECalendar::inDaylightTime(UErrorCode& status) const
    1.92 +{
    1.93 +    if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) {
    1.94 +        return FALSE;
    1.95 +    }
    1.96 +
    1.97 +    // Force an update of the state of the Calendar.
    1.98 +    ((CECalendar*)this)->complete(status); // cast away const
    1.99 +
   1.100 +    return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
   1.101 +}
   1.102 +
   1.103 +UBool
   1.104 +CECalendar::haveDefaultCentury() const
   1.105 +{
   1.106 +    return TRUE;
   1.107 +}
   1.108 +
   1.109 +//-------------------------------------------------------------------------
   1.110 +// Calendar system Conversion methods...
   1.111 +//-------------------------------------------------------------------------
   1.112 +int32_t
   1.113 +CECalendar::ceToJD(int32_t year, int32_t month, int32_t date, int32_t jdEpochOffset)
   1.114 +{
   1.115 +    // handle month > 12, < 0 (e.g. from add/set)
   1.116 +    if ( month >= 0 ) {
   1.117 +        year += month/13;
   1.118 +        month %= 13;
   1.119 +    } else {
   1.120 +        ++month;
   1.121 +        year += month/13 - 1;
   1.122 +        month = month%13 + 12;
   1.123 +    }
   1.124 +    return (int32_t) (
   1.125 +        jdEpochOffset                   // difference from Julian epoch to 1,1,1
   1.126 +        + 365 * year                    // number of days from years
   1.127 +        + ClockMath::floorDivide(year, 4)    // extra day of leap year
   1.128 +        + 30 * month                    // number of days from months (months are 0-based)
   1.129 +        + date - 1                      // number of days for present month (1 based)
   1.130 +        );
   1.131 +}
   1.132 +
   1.133 +void
   1.134 +CECalendar::jdToCE(int32_t julianDay, int32_t jdEpochOffset, int32_t& year, int32_t& month, int32_t& day)
   1.135 +{
   1.136 +    int32_t c4; // number of 4 year cycle (1461 days)
   1.137 +    int32_t r4; // remainder of 4 year cycle, always positive
   1.138 +
   1.139 +    c4 = ClockMath::floorDivide(julianDay - jdEpochOffset, 1461, r4);
   1.140 +
   1.141 +    year = 4 * c4 + (r4/365 - r4/1460); // 4 * <number of 4year cycle> + <years within the last cycle>
   1.142 +
   1.143 +    int32_t doy = (r4 == 1460) ? 365 : (r4 % 365); // days in present year
   1.144 +
   1.145 +    month = doy / 30;       // 30 -> Coptic/Ethiopic month length up to 12th month
   1.146 +    day = (doy % 30) + 1;   // 1-based days in a month
   1.147 +}
   1.148 +
   1.149 +U_NAMESPACE_END
   1.150 +
   1.151 +#endif /* #if !UCONFIG_NO_FORMATTING */
   1.152 +//eof

mercurial