intl/icu/source/i18n/unicode/rbtz.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) 2007-2013, International Business Machines Corporation and *
michael@0 4 * others. All Rights Reserved. *
michael@0 5 *******************************************************************************
michael@0 6 */
michael@0 7 #ifndef RBTZ_H
michael@0 8 #define RBTZ_H
michael@0 9
michael@0 10 #include "unicode/utypes.h"
michael@0 11
michael@0 12 /**
michael@0 13 * \file
michael@0 14 * \brief C++ API: Rule based customizable time zone
michael@0 15 */
michael@0 16
michael@0 17 #if !UCONFIG_NO_FORMATTING
michael@0 18
michael@0 19 #include "unicode/basictz.h"
michael@0 20 #include "unicode/unistr.h"
michael@0 21
michael@0 22 U_NAMESPACE_BEGIN
michael@0 23
michael@0 24 // forward declaration
michael@0 25 class UVector;
michael@0 26 struct Transition;
michael@0 27
michael@0 28 /**
michael@0 29 * a BasicTimeZone subclass implemented in terms of InitialTimeZoneRule and TimeZoneRule instances
michael@0 30 * @see BasicTimeZone
michael@0 31 * @see InitialTimeZoneRule
michael@0 32 * @see TimeZoneRule
michael@0 33 */
michael@0 34 class U_I18N_API RuleBasedTimeZone : public BasicTimeZone {
michael@0 35 public:
michael@0 36 /**
michael@0 37 * Constructs a <code>RuleBasedTimeZone</code> object with the ID and the
michael@0 38 * <code>InitialTimeZoneRule</code>. The input <code>InitialTimeZoneRule</code>
michael@0 39 * is adopted by this <code>RuleBasedTimeZone</code>, thus the caller must not
michael@0 40 * delete it.
michael@0 41 * @param id The time zone ID.
michael@0 42 * @param initialRule The initial time zone rule.
michael@0 43 * @stable ICU 3.8
michael@0 44 */
michael@0 45 RuleBasedTimeZone(const UnicodeString& id, InitialTimeZoneRule* initialRule);
michael@0 46
michael@0 47 /**
michael@0 48 * Copy constructor.
michael@0 49 * @param source The RuleBasedTimeZone object to be copied.
michael@0 50 * @stable ICU 3.8
michael@0 51 */
michael@0 52 RuleBasedTimeZone(const RuleBasedTimeZone& source);
michael@0 53
michael@0 54 /**
michael@0 55 * Destructor.
michael@0 56 * @stable ICU 3.8
michael@0 57 */
michael@0 58 virtual ~RuleBasedTimeZone();
michael@0 59
michael@0 60 /**
michael@0 61 * Assignment operator.
michael@0 62 * @param right The object to be copied.
michael@0 63 * @stable ICU 3.8
michael@0 64 */
michael@0 65 RuleBasedTimeZone& operator=(const RuleBasedTimeZone& right);
michael@0 66
michael@0 67 /**
michael@0 68 * Return true if the given <code>TimeZone</code> objects are
michael@0 69 * semantically equal. Objects of different subclasses are considered unequal.
michael@0 70 * @param that The object to be compared with.
michael@0 71 * @return true if the given <code>TimeZone</code> objects are
michael@0 72 *semantically equal.
michael@0 73 * @stable ICU 3.8
michael@0 74 */
michael@0 75 virtual UBool operator==(const TimeZone& that) const;
michael@0 76
michael@0 77 /**
michael@0 78 * Return true if the given <code>TimeZone</code> objects are
michael@0 79 * semantically unequal. Objects of different subclasses are considered unequal.
michael@0 80 * @param that The object to be compared with.
michael@0 81 * @return true if the given <code>TimeZone</code> objects are
michael@0 82 * semantically unequal.
michael@0 83 * @stable ICU 3.8
michael@0 84 */
michael@0 85 virtual UBool operator!=(const TimeZone& that) const;
michael@0 86
michael@0 87 /**
michael@0 88 * Adds the <code>TimeZoneRule</code> which represents time transitions.
michael@0 89 * The <code>TimeZoneRule</code> must have start times, that is, the result
michael@0 90 * of isTransitionRule() must be true. Otherwise, U_ILLEGAL_ARGUMENT_ERROR
michael@0 91 * is set to the error code.
michael@0 92 * The input <code>TimeZoneRule</code> is adopted by this
michael@0 93 * <code>RuleBasedTimeZone</code> on successful completion of this method,
michael@0 94 * thus, the caller must not delete it when no error is returned.
michael@0 95 * After all rules are added, the caller must call complete() method to
michael@0 96 * make this <code>RuleBasedTimeZone</code> ready to handle common time
michael@0 97 * zone functions.
michael@0 98 * @param rule The <code>TimeZoneRule</code>.
michael@0 99 * @param status Output param to filled in with a success or an error.
michael@0 100 * @stable ICU 3.8
michael@0 101 */
michael@0 102 void addTransitionRule(TimeZoneRule* rule, UErrorCode& status);
michael@0 103
michael@0 104 /**
michael@0 105 * Makes the <code>TimeZoneRule</code> ready to handle actual timezone
michael@0 106 * calcuation APIs. This method collects time zone rules specified
michael@0 107 * by the caller via the constructor and addTransitionRule() and
michael@0 108 * builds internal structure for making the object ready to support
michael@0 109 * time zone APIs such as getOffset(), getNextTransition() and others.
michael@0 110 * @param status Output param to filled in with a success or an error.
michael@0 111 * @stable ICU 3.8
michael@0 112 */
michael@0 113 void complete(UErrorCode& status);
michael@0 114
michael@0 115 /**
michael@0 116 * Clones TimeZone objects polymorphically. Clients are responsible for deleting
michael@0 117 * the TimeZone object cloned.
michael@0 118 *
michael@0 119 * @return A new copy of this TimeZone object.
michael@0 120 * @stable ICU 3.8
michael@0 121 */
michael@0 122 virtual TimeZone* clone(void) const;
michael@0 123
michael@0 124 /**
michael@0 125 * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
michael@0 126 * to GMT to get local time in this time zone, taking daylight savings time into
michael@0 127 * account) as of a particular reference date. The reference date is used to determine
michael@0 128 * whether daylight savings time is in effect and needs to be figured into the offset
michael@0 129 * that is returned (in other words, what is the adjusted GMT offset in this time zone
michael@0 130 * at this particular date and time?). For the time zones produced by createTimeZone(),
michael@0 131 * the reference data is specified according to the Gregorian calendar, and the date
michael@0 132 * and time fields are local standard time.
michael@0 133 *
michael@0 134 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
michael@0 135 * which returns both the raw and the DST offset for a given time. This method
michael@0 136 * is retained only for backward compatibility.
michael@0 137 *
michael@0 138 * @param era The reference date's era
michael@0 139 * @param year The reference date's year
michael@0 140 * @param month The reference date's month (0-based; 0 is January)
michael@0 141 * @param day The reference date's day-in-month (1-based)
michael@0 142 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
michael@0 143 * @param millis The reference date's milliseconds in day, local standard time
michael@0 144 * @param status Output param to filled in with a success or an error.
michael@0 145 * @return The offset in milliseconds to add to GMT to get local time.
michael@0 146 * @stable ICU 3.8
michael@0 147 */
michael@0 148 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
michael@0 149 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
michael@0 150
michael@0 151 /**
michael@0 152 * Gets the time zone offset, for current date, modified in case of
michael@0 153 * daylight savings. This is the offset to add *to* UTC to get local time.
michael@0 154 *
michael@0 155 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
michael@0 156 * which returns both the raw and the DST offset for a given time. This method
michael@0 157 * is retained only for backward compatibility.
michael@0 158 *
michael@0 159 * @param era The reference date's era
michael@0 160 * @param year The reference date's year
michael@0 161 * @param month The reference date's month (0-based; 0 is January)
michael@0 162 * @param day The reference date's day-in-month (1-based)
michael@0 163 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
michael@0 164 * @param millis The reference date's milliseconds in day, local standard time
michael@0 165 * @param monthLength The length of the given month in days.
michael@0 166 * @param status Output param to filled in with a success or an error.
michael@0 167 * @return The offset in milliseconds to add to GMT to get local time.
michael@0 168 * @stable ICU 3.8
michael@0 169 */
michael@0 170 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
michael@0 171 uint8_t dayOfWeek, int32_t millis,
michael@0 172 int32_t monthLength, UErrorCode& status) const;
michael@0 173
michael@0 174 /**
michael@0 175 * Returns the time zone raw and GMT offset for the given moment
michael@0 176 * in time. Upon return, local-millis = GMT-millis + rawOffset +
michael@0 177 * dstOffset. All computations are performed in the proleptic
michael@0 178 * Gregorian calendar. The default implementation in the TimeZone
michael@0 179 * class delegates to the 8-argument getOffset().
michael@0 180 *
michael@0 181 * @param date moment in time for which to return offsets, in
michael@0 182 * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
michael@0 183 * time or local wall time, depending on `local'.
michael@0 184 * @param local if true, `date' is local wall time; otherwise it
michael@0 185 * is in GMT time.
michael@0 186 * @param rawOffset output parameter to receive the raw offset, that
michael@0 187 * is, the offset not including DST adjustments
michael@0 188 * @param dstOffset output parameter to receive the DST offset,
michael@0 189 * that is, the offset to be added to `rawOffset' to obtain the
michael@0 190 * total offset between local and GMT time. If DST is not in
michael@0 191 * effect, this value is zero; otherwise it is a positive value,
michael@0 192 * typically one hour.
michael@0 193 * @param ec input-output error code
michael@0 194 * @stable ICU 3.8
michael@0 195 */
michael@0 196 virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
michael@0 197 int32_t& dstOffset, UErrorCode& ec) const;
michael@0 198
michael@0 199 /**
michael@0 200 * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
michael@0 201 * to GMT to get local time, before taking daylight savings time into account).
michael@0 202 *
michael@0 203 * @param offsetMillis The new raw GMT offset for this time zone.
michael@0 204 * @stable ICU 3.8
michael@0 205 */
michael@0 206 virtual void setRawOffset(int32_t offsetMillis);
michael@0 207
michael@0 208 /**
michael@0 209 * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
michael@0 210 * to GMT to get local time, before taking daylight savings time into account).
michael@0 211 *
michael@0 212 * @return The TimeZone's raw GMT offset.
michael@0 213 * @stable ICU 3.8
michael@0 214 */
michael@0 215 virtual int32_t getRawOffset(void) const;
michael@0 216
michael@0 217 /**
michael@0 218 * Queries if this time zone uses daylight savings time.
michael@0 219 * @return true if this time zone uses daylight savings time,
michael@0 220 * false, otherwise.
michael@0 221 * @stable ICU 3.8
michael@0 222 */
michael@0 223 virtual UBool useDaylightTime(void) const;
michael@0 224
michael@0 225 /**
michael@0 226 * Queries if the given date is in daylight savings time in
michael@0 227 * this time zone.
michael@0 228 * This method is wasteful since it creates a new GregorianCalendar and
michael@0 229 * deletes it each time it is called. This is a deprecated method
michael@0 230 * and provided only for Java compatibility.
michael@0 231 *
michael@0 232 * @param date the given UDate.
michael@0 233 * @param status Output param filled in with success/error code.
michael@0 234 * @return true if the given date is in daylight savings time,
michael@0 235 * false, otherwise.
michael@0 236 * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
michael@0 237 */
michael@0 238 virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
michael@0 239
michael@0 240 /**
michael@0 241 * Returns true if this zone has the same rule and offset as another zone.
michael@0 242 * That is, if this zone differs only in ID, if at all.
michael@0 243 * @param other the <code>TimeZone</code> object to be compared with
michael@0 244 * @return true if the given zone is the same as this one,
michael@0 245 * with the possible exception of the ID
michael@0 246 * @stable ICU 3.8
michael@0 247 */
michael@0 248 virtual UBool hasSameRules(const TimeZone& other) const;
michael@0 249
michael@0 250 /**
michael@0 251 * Gets the first time zone transition after the base time.
michael@0 252 * @param base The base time.
michael@0 253 * @param inclusive Whether the base time is inclusive or not.
michael@0 254 * @param result Receives the first transition after the base time.
michael@0 255 * @return TRUE if the transition is found.
michael@0 256 * @stable ICU 3.8
michael@0 257 */
michael@0 258 virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
michael@0 259
michael@0 260 /**
michael@0 261 * Gets the most recent time zone transition before the base time.
michael@0 262 * @param base The base time.
michael@0 263 * @param inclusive Whether the base time is inclusive or not.
michael@0 264 * @param result Receives the most recent transition before the base time.
michael@0 265 * @return TRUE if the transition is found.
michael@0 266 * @stable ICU 3.8
michael@0 267 */
michael@0 268 virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
michael@0 269
michael@0 270 /**
michael@0 271 * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
michael@0 272 * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
michael@0 273 * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
michael@0 274 * @param status Receives error status code.
michael@0 275 * @return The number of <code>TimeZoneRule</code>s representing time transitions.
michael@0 276 * @stable ICU 3.8
michael@0 277 */
michael@0 278 virtual int32_t countTransitionRules(UErrorCode& status) const;
michael@0 279
michael@0 280 /**
michael@0 281 * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
michael@0 282 * which represent time transitions for this time zone. On successful return,
michael@0 283 * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
michael@0 284 * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
michael@0 285 * instances up to the size specified by trscount. The results are referencing the
michael@0 286 * rule instance held by this time zone instance. Therefore, after this time zone
michael@0 287 * is destructed, they are no longer available.
michael@0 288 * @param initial Receives the initial timezone rule
michael@0 289 * @param trsrules Receives the timezone transition rules
michael@0 290 * @param trscount On input, specify the size of the array 'transitions' receiving
michael@0 291 * the timezone transition rules. On output, actual number of
michael@0 292 * rules filled in the array will be set.
michael@0 293 * @param status Receives error status code.
michael@0 294 * @stable ICU 3.8
michael@0 295 */
michael@0 296 virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
michael@0 297 const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
michael@0 298
michael@0 299 /**
michael@0 300 * Get time zone offsets from local wall time.
michael@0 301 * @internal
michael@0 302 */
michael@0 303 virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
michael@0 304 int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
michael@0 305
michael@0 306 private:
michael@0 307 void deleteRules(void);
michael@0 308 void deleteTransitions(void);
michael@0 309 UVector* copyRules(UVector* source);
michael@0 310 TimeZoneRule* findRuleInFinal(UDate date, UBool local,
michael@0 311 int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
michael@0 312 UBool findNext(UDate base, UBool inclusive, UDate& time, TimeZoneRule*& from, TimeZoneRule*& to) const;
michael@0 313 UBool findPrev(UDate base, UBool inclusive, UDate& time, TimeZoneRule*& from, TimeZoneRule*& to) const;
michael@0 314 int32_t getLocalDelta(int32_t rawBefore, int32_t dstBefore, int32_t rawAfter, int32_t dstAfter,
michael@0 315 int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
michael@0 316 UDate getTransitionTime(Transition* transition, UBool local,
michael@0 317 int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
michael@0 318 void getOffsetInternal(UDate date, UBool local, int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt,
michael@0 319 int32_t& rawOffset, int32_t& dstOffset, UErrorCode& ec) const;
michael@0 320 void completeConst(UErrorCode &status) const;
michael@0 321
michael@0 322 InitialTimeZoneRule *fInitialRule;
michael@0 323 UVector *fHistoricRules;
michael@0 324 UVector *fFinalRules;
michael@0 325 UVector *fHistoricTransitions;
michael@0 326 UBool fUpToDate;
michael@0 327
michael@0 328 public:
michael@0 329 /**
michael@0 330 * Return the class ID for this class. This is useful only for comparing to
michael@0 331 * a return value from getDynamicClassID(). For example:
michael@0 332 * <pre>
michael@0 333 * . Base* polymorphic_pointer = createPolymorphicObject();
michael@0 334 * . if (polymorphic_pointer->getDynamicClassID() ==
michael@0 335 * . erived::getStaticClassID()) ...
michael@0 336 * </pre>
michael@0 337 * @return The class ID for all objects of this class.
michael@0 338 * @stable ICU 3.8
michael@0 339 */
michael@0 340 static UClassID U_EXPORT2 getStaticClassID(void);
michael@0 341
michael@0 342 /**
michael@0 343 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
michael@0 344 * method is to implement a simple version of RTTI, since not all C++
michael@0 345 * compilers support genuine RTTI. Polymorphic operator==() and clone()
michael@0 346 * methods call this method.
michael@0 347 *
michael@0 348 * @return The class ID for this object. All objects of a
michael@0 349 * given class have the same class ID. Objects of
michael@0 350 * other classes have different class IDs.
michael@0 351 * @stable ICU 3.8
michael@0 352 */
michael@0 353 virtual UClassID getDynamicClassID(void) const;
michael@0 354 };
michael@0 355
michael@0 356 U_NAMESPACE_END
michael@0 357
michael@0 358 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 359
michael@0 360 #endif // RBTZ_H
michael@0 361
michael@0 362 //eof

mercurial