intl/icu/source/i18n/cecal.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 - 2009, 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 "cecal.h"
michael@0 13 #include "gregoimp.h" //Math
michael@0 14
michael@0 15 U_NAMESPACE_BEGIN
michael@0 16
michael@0 17 static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
michael@0 18 // Minimum Greatest Least Maximum
michael@0 19 // Minimum Maximum
michael@0 20 { 0, 0, 1, 1}, // ERA
michael@0 21 { 1, 1, 5000000, 5000000}, // YEAR
michael@0 22 { 0, 0, 12, 12}, // MONTH
michael@0 23 { 1, 1, 52, 53}, // WEEK_OF_YEAR
michael@0 24 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
michael@0 25 { 1, 1, 5, 30}, // DAY_OF_MONTH
michael@0 26 { 1, 1, 365, 366}, // DAY_OF_YEAR
michael@0 27 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
michael@0 28 { -1, -1, 1, 5}, // DAY_OF_WEEK_IN_MONTH
michael@0 29 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
michael@0 30 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
michael@0 31 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
michael@0 32 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
michael@0 33 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
michael@0 34 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
michael@0 35 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
michael@0 36 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
michael@0 37 { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
michael@0 38 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
michael@0 39 { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
michael@0 40 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
michael@0 41 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
michael@0 42 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
michael@0 43 };
michael@0 44
michael@0 45 //-------------------------------------------------------------------------
michael@0 46 // Constructors...
michael@0 47 //-------------------------------------------------------------------------
michael@0 48
michael@0 49 CECalendar::CECalendar(const Locale& aLocale, UErrorCode& success)
michael@0 50 : Calendar(TimeZone::createDefault(), aLocale, success)
michael@0 51 {
michael@0 52 setTimeInMillis(getNow(), success);
michael@0 53 }
michael@0 54
michael@0 55 CECalendar::CECalendar (const CECalendar& other)
michael@0 56 : Calendar(other)
michael@0 57 {
michael@0 58 }
michael@0 59
michael@0 60 CECalendar::~CECalendar()
michael@0 61 {
michael@0 62 }
michael@0 63
michael@0 64 CECalendar&
michael@0 65 CECalendar::operator=(const CECalendar& right)
michael@0 66 {
michael@0 67 Calendar::operator=(right);
michael@0 68 return *this;
michael@0 69 }
michael@0 70
michael@0 71 //-------------------------------------------------------------------------
michael@0 72 // Calendar framework
michael@0 73 //-------------------------------------------------------------------------
michael@0 74
michael@0 75 int32_t
michael@0 76 CECalendar::handleComputeMonthStart(int32_t eyear,int32_t emonth, UBool /*useMonth*/) const
michael@0 77 {
michael@0 78 return ceToJD(eyear, emonth, 0, getJDEpochOffset());
michael@0 79 }
michael@0 80
michael@0 81 int32_t
michael@0 82 CECalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
michael@0 83 {
michael@0 84 return LIMITS[field][limitType];
michael@0 85 }
michael@0 86
michael@0 87 UBool
michael@0 88 CECalendar::inDaylightTime(UErrorCode& status) const
michael@0 89 {
michael@0 90 if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) {
michael@0 91 return FALSE;
michael@0 92 }
michael@0 93
michael@0 94 // Force an update of the state of the Calendar.
michael@0 95 ((CECalendar*)this)->complete(status); // cast away const
michael@0 96
michael@0 97 return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : FALSE);
michael@0 98 }
michael@0 99
michael@0 100 UBool
michael@0 101 CECalendar::haveDefaultCentury() const
michael@0 102 {
michael@0 103 return TRUE;
michael@0 104 }
michael@0 105
michael@0 106 //-------------------------------------------------------------------------
michael@0 107 // Calendar system Conversion methods...
michael@0 108 //-------------------------------------------------------------------------
michael@0 109 int32_t
michael@0 110 CECalendar::ceToJD(int32_t year, int32_t month, int32_t date, int32_t jdEpochOffset)
michael@0 111 {
michael@0 112 // handle month > 12, < 0 (e.g. from add/set)
michael@0 113 if ( month >= 0 ) {
michael@0 114 year += month/13;
michael@0 115 month %= 13;
michael@0 116 } else {
michael@0 117 ++month;
michael@0 118 year += month/13 - 1;
michael@0 119 month = month%13 + 12;
michael@0 120 }
michael@0 121 return (int32_t) (
michael@0 122 jdEpochOffset // difference from Julian epoch to 1,1,1
michael@0 123 + 365 * year // number of days from years
michael@0 124 + ClockMath::floorDivide(year, 4) // extra day of leap year
michael@0 125 + 30 * month // number of days from months (months are 0-based)
michael@0 126 + date - 1 // number of days for present month (1 based)
michael@0 127 );
michael@0 128 }
michael@0 129
michael@0 130 void
michael@0 131 CECalendar::jdToCE(int32_t julianDay, int32_t jdEpochOffset, int32_t& year, int32_t& month, int32_t& day)
michael@0 132 {
michael@0 133 int32_t c4; // number of 4 year cycle (1461 days)
michael@0 134 int32_t r4; // remainder of 4 year cycle, always positive
michael@0 135
michael@0 136 c4 = ClockMath::floorDivide(julianDay - jdEpochOffset, 1461, r4);
michael@0 137
michael@0 138 year = 4 * c4 + (r4/365 - r4/1460); // 4 * <number of 4year cycle> + <years within the last cycle>
michael@0 139
michael@0 140 int32_t doy = (r4 == 1460) ? 365 : (r4 % 365); // days in present year
michael@0 141
michael@0 142 month = doy / 30; // 30 -> Coptic/Ethiopic month length up to 12th month
michael@0 143 day = (doy % 30) + 1; // 1-based days in a month
michael@0 144 }
michael@0 145
michael@0 146 U_NAMESPACE_END
michael@0 147
michael@0 148 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 149 //eof

mercurial