intl/icu/source/i18n/persncal.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 ******************************************************************************
michael@0 3 * Copyright (C) 2003-2013, International Business Machines Corporation
michael@0 4 * and others. All Rights Reserved.
michael@0 5 ******************************************************************************
michael@0 6 *
michael@0 7 * File PERSNCAL.H
michael@0 8 *
michael@0 9 * Modification History:
michael@0 10 *
michael@0 11 * Date Name Description
michael@0 12 * 9/23/2003 mehran posted to icu-design
michael@0 13 *****************************************************************************
michael@0 14 */
michael@0 15
michael@0 16 #ifndef PERSNCAL_H
michael@0 17 #define PERSNCAL_H
michael@0 18
michael@0 19 #include "unicode/utypes.h"
michael@0 20
michael@0 21 #if !UCONFIG_NO_FORMATTING
michael@0 22
michael@0 23 #include "unicode/calendar.h"
michael@0 24
michael@0 25 U_NAMESPACE_BEGIN
michael@0 26
michael@0 27 /**
michael@0 28 * <code>PersianCalendar</code> is a subclass of <code>Calendar</code>
michael@0 29 * that implements the Persian calendar. It is used as the official
michael@0 30 * calendar in Iran. This calendar is also known as the "Hijri Shamsi"
michael@0 31 * calendar, since it starts at the time of Mohammed's emigration (or
michael@0 32 * "hijra") to Medinah on Thursday, July 15, 622 AD (Julian) and is a
michael@0 33 * solar calendar system (or "shamsi").
michael@0 34 * <p>
michael@0 35 * The Persian calendar is strictly solar, and thus a Persian year has twelve
michael@0 36 * solar months. A Persian year is about 365 days long, except in leap years
michael@0 37 * which is 366 days long.
michael@0 38 * <p>
michael@0 39 * The six first months of Persian Calendar are 31 days long. The next five
michael@0 40 * months are 30 days long. The last month is 29 days long in normal years,
michael@0 41 * and 30 days long in leap years.
michael@0 42 *
michael@0 43 * @see GregorianCalendar
michael@0 44 *
michael@0 45 * @author Mehran Mehr
michael@0 46 * @internal
michael@0 47 */
michael@0 48 class PersianCalendar : public Calendar {
michael@0 49 public:
michael@0 50 //-------------------------------------------------------------------------
michael@0 51 // Constants...
michael@0 52 //-------------------------------------------------------------------------
michael@0 53 /**
michael@0 54 * Constants for the months
michael@0 55 * @internal
michael@0 56 */
michael@0 57 enum EMonths {
michael@0 58 /**
michael@0 59 * Constant for Farvardin, the 1st month of the Persian year.
michael@0 60 * @internal
michael@0 61 */
michael@0 62 FARVARDIN = 0,
michael@0 63
michael@0 64 /**
michael@0 65 * Constant for Ordibehesht, the 2nd month of the Persian year.
michael@0 66 * @internal
michael@0 67 */
michael@0 68 ORDIBEHESHT = 1,
michael@0 69
michael@0 70 /**
michael@0 71 * Constant for Khordad, the 3rd month of the Persian year.
michael@0 72 * @internal
michael@0 73 */
michael@0 74 KHORDAD = 2,
michael@0 75
michael@0 76 /**
michael@0 77 * Constant for Tir, the 4th month of the Persian year.
michael@0 78 * @internal
michael@0 79 */
michael@0 80 TIR = 3,
michael@0 81
michael@0 82 /**
michael@0 83 * Constant for Mordad, the 5th month of the Persian year.
michael@0 84 * @internal
michael@0 85 */
michael@0 86 MORDAD = 4,
michael@0 87
michael@0 88 /**
michael@0 89 * Constant for Shahrivar, the 6th month of the Persian year.
michael@0 90 * @internal
michael@0 91 */
michael@0 92 SHAHRIVAR = 5,
michael@0 93
michael@0 94 /**
michael@0 95 * Constant for Mehr, the 7th month of the Persian year.
michael@0 96 * @internal
michael@0 97 */
michael@0 98 MEHR = 6,
michael@0 99
michael@0 100 /**
michael@0 101 * Constant for Aban, the 8th month of the Persian year.
michael@0 102 * @internal
michael@0 103 */
michael@0 104 ABAN = 7,
michael@0 105
michael@0 106 /**
michael@0 107 * Constant for Azar, the 9th month of the Persian year.
michael@0 108 * @internal
michael@0 109 */
michael@0 110 AZAR = 8,
michael@0 111
michael@0 112 /**
michael@0 113 * Constant for Dei, the 10th month of the Persian year.
michael@0 114 * @internal
michael@0 115 */
michael@0 116 DEI = 9,
michael@0 117
michael@0 118 /**
michael@0 119 * Constant for Bahman, the 11th month of the Persian year.
michael@0 120 * @internal
michael@0 121 */
michael@0 122 BAHMAN = 10,
michael@0 123
michael@0 124 /**
michael@0 125 * Constant for Esfand, the 12th month of the Persian year.
michael@0 126 * @internal
michael@0 127 */
michael@0 128 ESFAND = 11,
michael@0 129
michael@0 130 PERSIAN_MONTH_MAX
michael@0 131 };
michael@0 132
michael@0 133
michael@0 134
michael@0 135 //-------------------------------------------------------------------------
michael@0 136 // Constructors...
michael@0 137 //-------------------------------------------------------------------------
michael@0 138
michael@0 139 /**
michael@0 140 * Constructs a PersianCalendar based on the current time in the default time zone
michael@0 141 * with the given locale.
michael@0 142 *
michael@0 143 * @param aLocale The given locale.
michael@0 144 * @param success Indicates the status of PersianCalendar object construction.
michael@0 145 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 146 * @internal
michael@0 147 */
michael@0 148 PersianCalendar(const Locale& aLocale, UErrorCode &success);
michael@0 149
michael@0 150 /**
michael@0 151 * Copy Constructor
michael@0 152 * @internal
michael@0 153 */
michael@0 154 PersianCalendar(const PersianCalendar& other);
michael@0 155
michael@0 156 /**
michael@0 157 * Destructor.
michael@0 158 * @internal
michael@0 159 */
michael@0 160 virtual ~PersianCalendar();
michael@0 161
michael@0 162 // TODO: copy c'tor, etc
michael@0 163
michael@0 164 // clone
michael@0 165 virtual Calendar* clone() const;
michael@0 166
michael@0 167 private:
michael@0 168 /**
michael@0 169 * Determine whether a year is a leap year in the Persian calendar
michael@0 170 */
michael@0 171 static UBool isLeapYear(int32_t year);
michael@0 172
michael@0 173 /**
michael@0 174 * Return the day # on which the given year starts. Days are counted
michael@0 175 * from the Hijri epoch, origin 0.
michael@0 176 */
michael@0 177 int32_t yearStart(int32_t year);
michael@0 178
michael@0 179 /**
michael@0 180 * Return the day # on which the given month starts. Days are counted
michael@0 181 * from the Hijri epoch, origin 0.
michael@0 182 *
michael@0 183 * @param year The hijri shamsi year
michael@0 184 * @param year The hijri shamsi month, 0-based
michael@0 185 */
michael@0 186 int32_t monthStart(int32_t year, int32_t month) const;
michael@0 187
michael@0 188 //----------------------------------------------------------------------
michael@0 189 // Calendar framework
michael@0 190 //----------------------------------------------------------------------
michael@0 191 protected:
michael@0 192 /**
michael@0 193 * @internal
michael@0 194 */
michael@0 195 virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
michael@0 196
michael@0 197 /**
michael@0 198 * Return the length (in days) of the given month.
michael@0 199 *
michael@0 200 * @param year The hijri shamsi year
michael@0 201 * @param year The hijri shamsi month, 0-based
michael@0 202 * @internal
michael@0 203 */
michael@0 204 virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
michael@0 205
michael@0 206 /**
michael@0 207 * Return the number of days in the given Persian year
michael@0 208 * @internal
michael@0 209 */
michael@0 210 virtual int32_t handleGetYearLength(int32_t extendedYear) const;
michael@0 211
michael@0 212 //-------------------------------------------------------------------------
michael@0 213 // Functions for converting from field values to milliseconds....
michael@0 214 //-------------------------------------------------------------------------
michael@0 215
michael@0 216 // Return JD of start of given month/year
michael@0 217 /**
michael@0 218 * @internal
michael@0 219 */
michael@0 220 virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
michael@0 221
michael@0 222 //-------------------------------------------------------------------------
michael@0 223 // Functions for converting from milliseconds to field values
michael@0 224 //-------------------------------------------------------------------------
michael@0 225
michael@0 226 /**
michael@0 227 * @internal
michael@0 228 */
michael@0 229 virtual int32_t handleGetExtendedYear();
michael@0 230
michael@0 231 /**
michael@0 232 * Override Calendar to compute several fields specific to the Persian
michael@0 233 * calendar system. These are:
michael@0 234 *
michael@0 235 * <ul><li>ERA
michael@0 236 * <li>YEAR
michael@0 237 * <li>MONTH
michael@0 238 * <li>DAY_OF_MONTH
michael@0 239 * <li>DAY_OF_YEAR
michael@0 240 * <li>EXTENDED_YEAR</ul>
michael@0 241 *
michael@0 242 * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
michael@0 243 * method is called. The getGregorianXxx() methods return Gregorian
michael@0 244 * calendar equivalents for the given Julian day.
michael@0 245 * @internal
michael@0 246 */
michael@0 247 virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
michael@0 248
michael@0 249 // UObject stuff
michael@0 250 public:
michael@0 251 /**
michael@0 252 * @return The class ID for this object. All objects of a given class have the
michael@0 253 * same class ID. Objects of other classes have different class IDs.
michael@0 254 * @internal
michael@0 255 */
michael@0 256 virtual UClassID getDynamicClassID(void) const;
michael@0 257
michael@0 258 /**
michael@0 259 * Return the class ID for this class. This is useful only for comparing to a return
michael@0 260 * value from getDynamicClassID(). For example:
michael@0 261 *
michael@0 262 * Base* polymorphic_pointer = createPolymorphicObject();
michael@0 263 * if (polymorphic_pointer->getDynamicClassID() ==
michael@0 264 * Derived::getStaticClassID()) ...
michael@0 265 *
michael@0 266 * @return The class ID for all objects of this class.
michael@0 267 * @internal
michael@0 268 */
michael@0 269 U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
michael@0 270
michael@0 271 /**
michael@0 272 * return the calendar type, "persian".
michael@0 273 *
michael@0 274 * @return calendar type
michael@0 275 * @internal
michael@0 276 */
michael@0 277 virtual const char * getType() const;
michael@0 278
michael@0 279 private:
michael@0 280 PersianCalendar(); // default constructor not implemented
michael@0 281
michael@0 282 protected:
michael@0 283
michael@0 284 /**
michael@0 285 * (Overrides Calendar) Return true if the current date for this Calendar is in
michael@0 286 * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
michael@0 287 *
michael@0 288 * @param status Fill-in parameter which receives the status of this operation.
michael@0 289 * @return True if the current date for this Calendar is in Daylight Savings Time,
michael@0 290 * false, otherwise.
michael@0 291 * @internal
michael@0 292 */
michael@0 293 virtual UBool inDaylightTime(UErrorCode& status) const;
michael@0 294
michael@0 295 /**
michael@0 296 * Returns TRUE because the Persian Calendar does have a default century
michael@0 297 * @internal
michael@0 298 */
michael@0 299 virtual UBool haveDefaultCentury() const;
michael@0 300
michael@0 301 /**
michael@0 302 * Returns the date of the start of the default century
michael@0 303 * @return start of century - in milliseconds since epoch, 1970
michael@0 304 * @internal
michael@0 305 */
michael@0 306 virtual UDate defaultCenturyStart() const;
michael@0 307
michael@0 308 /**
michael@0 309 * Returns the year in which the default century begins
michael@0 310 * @internal
michael@0 311 */
michael@0 312 virtual int32_t defaultCenturyStartYear() const;
michael@0 313 };
michael@0 314
michael@0 315 U_NAMESPACE_END
michael@0 316
michael@0 317 #endif
michael@0 318 #endif
michael@0 319
michael@0 320
michael@0 321

mercurial