intl/icu/source/i18n/unicode/rbtz.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/unicode/rbtz.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,362 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +* Copyright (C) 2007-2013, International Business Machines Corporation and    *
     1.7 +* others. All Rights Reserved.                                                *
     1.8 +*******************************************************************************
     1.9 +*/
    1.10 +#ifndef RBTZ_H
    1.11 +#define RBTZ_H
    1.12 +
    1.13 +#include "unicode/utypes.h"
    1.14 +
    1.15 +/**
    1.16 + * \file 
    1.17 + * \brief C++ API: Rule based customizable time zone
    1.18 + */
    1.19 +
    1.20 +#if !UCONFIG_NO_FORMATTING
    1.21 +
    1.22 +#include "unicode/basictz.h"
    1.23 +#include "unicode/unistr.h"
    1.24 +
    1.25 +U_NAMESPACE_BEGIN
    1.26 +
    1.27 +// forward declaration
    1.28 +class UVector;
    1.29 +struct Transition;
    1.30 +
    1.31 +/**
    1.32 + * a BasicTimeZone subclass implemented in terms of InitialTimeZoneRule and TimeZoneRule instances
    1.33 + * @see BasicTimeZone
    1.34 + * @see InitialTimeZoneRule
    1.35 + * @see TimeZoneRule
    1.36 + */
    1.37 +class U_I18N_API RuleBasedTimeZone : public BasicTimeZone {
    1.38 +public:
    1.39 +    /**
    1.40 +     * Constructs a <code>RuleBasedTimeZone</code> object with the ID and the
    1.41 +     * <code>InitialTimeZoneRule</code>.  The input <code>InitialTimeZoneRule</code>
    1.42 +     * is adopted by this <code>RuleBasedTimeZone</code>, thus the caller must not
    1.43 +     * delete it.
    1.44 +     * @param id                The time zone ID.
    1.45 +     * @param initialRule       The initial time zone rule.
    1.46 +     * @stable ICU 3.8
    1.47 +     */
    1.48 +    RuleBasedTimeZone(const UnicodeString& id, InitialTimeZoneRule* initialRule);
    1.49 +
    1.50 +    /**
    1.51 +     * Copy constructor.
    1.52 +     * @param source    The RuleBasedTimeZone object to be copied.
    1.53 +     * @stable ICU 3.8
    1.54 +     */
    1.55 +    RuleBasedTimeZone(const RuleBasedTimeZone& source);
    1.56 +
    1.57 +    /**
    1.58 +     * Destructor.
    1.59 +     * @stable ICU 3.8
    1.60 +     */
    1.61 +    virtual ~RuleBasedTimeZone();
    1.62 +
    1.63 +    /**
    1.64 +     * Assignment operator.
    1.65 +     * @param right The object to be copied.
    1.66 +     * @stable ICU 3.8
    1.67 +     */
    1.68 +    RuleBasedTimeZone& operator=(const RuleBasedTimeZone& right);
    1.69 +
    1.70 +    /**
    1.71 +     * Return true if the given <code>TimeZone</code> objects are
    1.72 +     * semantically equal. Objects of different subclasses are considered unequal.
    1.73 +     * @param that  The object to be compared with.
    1.74 +     * @return  true if the given <code>TimeZone</code> objects are
    1.75 +      *semantically equal.
    1.76 +     * @stable ICU 3.8
    1.77 +     */
    1.78 +    virtual UBool operator==(const TimeZone& that) const;
    1.79 +
    1.80 +    /**
    1.81 +     * Return true if the given <code>TimeZone</code> objects are
    1.82 +     * semantically unequal. Objects of different subclasses are considered unequal.
    1.83 +     * @param that  The object to be compared with.
    1.84 +     * @return  true if the given <code>TimeZone</code> objects are
    1.85 +     * semantically unequal.
    1.86 +     * @stable ICU 3.8
    1.87 +     */
    1.88 +    virtual UBool operator!=(const TimeZone& that) const;
    1.89 +
    1.90 +    /**
    1.91 +     * Adds the <code>TimeZoneRule</code> which represents time transitions.
    1.92 +     * The <code>TimeZoneRule</code> must have start times, that is, the result
    1.93 +     * of isTransitionRule() must be true. Otherwise, U_ILLEGAL_ARGUMENT_ERROR
    1.94 +     * is set to the error code.
    1.95 +     * The input <code>TimeZoneRule</code> is adopted by this
    1.96 +     * <code>RuleBasedTimeZone</code> on successful completion of this method,
    1.97 +     * thus, the caller must not delete it when no error is returned.
    1.98 +     * After all rules are added, the caller must call complete() method to
    1.99 +     * make this <code>RuleBasedTimeZone</code> ready to handle common time
   1.100 +     * zone functions.
   1.101 +     * @param rule The <code>TimeZoneRule</code>.
   1.102 +     * @param status Output param to filled in with a success or an error.
   1.103 +     * @stable ICU 3.8
   1.104 +     */
   1.105 +    void addTransitionRule(TimeZoneRule* rule, UErrorCode& status);
   1.106 +
   1.107 +    /**
   1.108 +     * Makes the <code>TimeZoneRule</code> ready to handle actual timezone
   1.109 +     * calcuation APIs.  This method collects time zone rules specified
   1.110 +     * by the caller via the constructor and addTransitionRule() and
   1.111 +     * builds internal structure for making the object ready to support
   1.112 +     * time zone APIs such as getOffset(), getNextTransition() and others.
   1.113 +     * @param status Output param to filled in with a success or an error.
   1.114 +     * @stable ICU 3.8
   1.115 +     */
   1.116 +    void complete(UErrorCode& status);
   1.117 +
   1.118 +    /**
   1.119 +     * Clones TimeZone objects polymorphically. Clients are responsible for deleting
   1.120 +     * the TimeZone object cloned.
   1.121 +     *
   1.122 +     * @return   A new copy of this TimeZone object.
   1.123 +     * @stable ICU 3.8
   1.124 +     */
   1.125 +    virtual TimeZone* clone(void) const;
   1.126 +
   1.127 +    /**
   1.128 +     * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
   1.129 +     * to GMT to get local time in this time zone, taking daylight savings time into
   1.130 +     * account) as of a particular reference date.  The reference date is used to determine
   1.131 +     * whether daylight savings time is in effect and needs to be figured into the offset
   1.132 +     * that is returned (in other words, what is the adjusted GMT offset in this time zone
   1.133 +     * at this particular date and time?).  For the time zones produced by createTimeZone(),
   1.134 +     * the reference data is specified according to the Gregorian calendar, and the date
   1.135 +     * and time fields are local standard time.
   1.136 +     *
   1.137 +     * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
   1.138 +     * which returns both the raw and the DST offset for a given time. This method
   1.139 +     * is retained only for backward compatibility.
   1.140 +     *
   1.141 +     * @param era        The reference date's era
   1.142 +     * @param year       The reference date's year
   1.143 +     * @param month      The reference date's month (0-based; 0 is January)
   1.144 +     * @param day        The reference date's day-in-month (1-based)
   1.145 +     * @param dayOfWeek  The reference date's day-of-week (1-based; 1 is Sunday)
   1.146 +     * @param millis     The reference date's milliseconds in day, local standard time
   1.147 +     * @param status     Output param to filled in with a success or an error.
   1.148 +     * @return           The offset in milliseconds to add to GMT to get local time.
   1.149 +     * @stable ICU 3.8
   1.150 +     */
   1.151 +    virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
   1.152 +                              uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
   1.153 +
   1.154 +    /**
   1.155 +     * Gets the time zone offset, for current date, modified in case of
   1.156 +     * daylight savings. This is the offset to add *to* UTC to get local time.
   1.157 +     *
   1.158 +     * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
   1.159 +     * which returns both the raw and the DST offset for a given time. This method
   1.160 +     * is retained only for backward compatibility.
   1.161 +     *
   1.162 +     * @param era        The reference date's era
   1.163 +     * @param year       The reference date's year
   1.164 +     * @param month      The reference date's month (0-based; 0 is January)
   1.165 +     * @param day        The reference date's day-in-month (1-based)
   1.166 +     * @param dayOfWeek  The reference date's day-of-week (1-based; 1 is Sunday)
   1.167 +     * @param millis     The reference date's milliseconds in day, local standard time
   1.168 +     * @param monthLength The length of the given month in days.
   1.169 +     * @param status     Output param to filled in with a success or an error.
   1.170 +     * @return           The offset in milliseconds to add to GMT to get local time.
   1.171 +     * @stable ICU 3.8
   1.172 +     */
   1.173 +    virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
   1.174 +                           uint8_t dayOfWeek, int32_t millis,
   1.175 +                           int32_t monthLength, UErrorCode& status) const;
   1.176 +
   1.177 +    /**
   1.178 +     * Returns the time zone raw and GMT offset for the given moment
   1.179 +     * in time.  Upon return, local-millis = GMT-millis + rawOffset +
   1.180 +     * dstOffset.  All computations are performed in the proleptic
   1.181 +     * Gregorian calendar.  The default implementation in the TimeZone
   1.182 +     * class delegates to the 8-argument getOffset().
   1.183 +     *
   1.184 +     * @param date moment in time for which to return offsets, in
   1.185 +     * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
   1.186 +     * time or local wall time, depending on `local'.
   1.187 +     * @param local if true, `date' is local wall time; otherwise it
   1.188 +     * is in GMT time.
   1.189 +     * @param rawOffset output parameter to receive the raw offset, that
   1.190 +     * is, the offset not including DST adjustments
   1.191 +     * @param dstOffset output parameter to receive the DST offset,
   1.192 +     * that is, the offset to be added to `rawOffset' to obtain the
   1.193 +     * total offset between local and GMT time. If DST is not in
   1.194 +     * effect, this value is zero; otherwise it is a positive value,
   1.195 +     * typically one hour.
   1.196 +     * @param ec input-output error code
   1.197 +     * @stable ICU 3.8
   1.198 +     */
   1.199 +    virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
   1.200 +                           int32_t& dstOffset, UErrorCode& ec) const;
   1.201 +
   1.202 +    /**
   1.203 +     * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
   1.204 +     * to GMT to get local time, before taking daylight savings time into account).
   1.205 +     *
   1.206 +     * @param offsetMillis  The new raw GMT offset for this time zone.
   1.207 +     * @stable ICU 3.8
   1.208 +     */
   1.209 +    virtual void setRawOffset(int32_t offsetMillis);
   1.210 +
   1.211 +    /**
   1.212 +     * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
   1.213 +     * to GMT to get local time, before taking daylight savings time into account).
   1.214 +     *
   1.215 +     * @return   The TimeZone's raw GMT offset.
   1.216 +     * @stable ICU 3.8
   1.217 +     */
   1.218 +    virtual int32_t getRawOffset(void) const;
   1.219 +
   1.220 +    /**
   1.221 +     * Queries if this time zone uses daylight savings time.
   1.222 +     * @return true if this time zone uses daylight savings time,
   1.223 +     * false, otherwise.
   1.224 +     * @stable ICU 3.8
   1.225 +     */
   1.226 +    virtual UBool useDaylightTime(void) const;
   1.227 +
   1.228 +    /**
   1.229 +     * Queries if the given date is in daylight savings time in
   1.230 +     * this time zone.
   1.231 +     * This method is wasteful since it creates a new GregorianCalendar and
   1.232 +     * deletes it each time it is called. This is a deprecated method
   1.233 +     * and provided only for Java compatibility.
   1.234 +     *
   1.235 +     * @param date the given UDate.
   1.236 +     * @param status Output param filled in with success/error code.
   1.237 +     * @return true if the given date is in daylight savings time,
   1.238 +     * false, otherwise.
   1.239 +     * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
   1.240 +     */
   1.241 +    virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
   1.242 +
   1.243 +    /**
   1.244 +     * Returns true if this zone has the same rule and offset as another zone.
   1.245 +     * That is, if this zone differs only in ID, if at all.
   1.246 +     * @param other the <code>TimeZone</code> object to be compared with
   1.247 +     * @return true if the given zone is the same as this one,
   1.248 +     * with the possible exception of the ID
   1.249 +     * @stable ICU 3.8
   1.250 +     */
   1.251 +    virtual UBool hasSameRules(const TimeZone& other) const;
   1.252 +
   1.253 +    /**
   1.254 +     * Gets the first time zone transition after the base time.
   1.255 +     * @param base      The base time.
   1.256 +     * @param inclusive Whether the base time is inclusive or not.
   1.257 +     * @param result    Receives the first transition after the base time.
   1.258 +     * @return  TRUE if the transition is found.
   1.259 +     * @stable ICU 3.8
   1.260 +     */
   1.261 +    virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
   1.262 +
   1.263 +    /**
   1.264 +     * Gets the most recent time zone transition before the base time.
   1.265 +     * @param base      The base time.
   1.266 +     * @param inclusive Whether the base time is inclusive or not.
   1.267 +     * @param result    Receives the most recent transition before the base time.
   1.268 +     * @return  TRUE if the transition is found.
   1.269 +     * @stable ICU 3.8
   1.270 +     */
   1.271 +    virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
   1.272 +
   1.273 +    /**
   1.274 +     * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
   1.275 +     * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
   1.276 +     * <code>InitialTimeZoneRule</code>.  The return value range is 0 or any positive value.
   1.277 +     * @param status    Receives error status code.
   1.278 +     * @return The number of <code>TimeZoneRule</code>s representing time transitions.
   1.279 +     * @stable ICU 3.8
   1.280 +     */
   1.281 +    virtual int32_t countTransitionRules(UErrorCode& status) const;
   1.282 +
   1.283 +    /**
   1.284 +     * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
   1.285 +     * which represent time transitions for this time zone.  On successful return,
   1.286 +     * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
   1.287 +     * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
   1.288 +     * instances up to the size specified by trscount.  The results are referencing the
   1.289 +     * rule instance held by this time zone instance.  Therefore, after this time zone
   1.290 +     * is destructed, they are no longer available.
   1.291 +     * @param initial       Receives the initial timezone rule
   1.292 +     * @param trsrules      Receives the timezone transition rules
   1.293 +     * @param trscount      On input, specify the size of the array 'transitions' receiving
   1.294 +     *                      the timezone transition rules.  On output, actual number of
   1.295 +     *                      rules filled in the array will be set.
   1.296 +     * @param status        Receives error status code.
   1.297 +     * @stable ICU 3.8
   1.298 +     */
   1.299 +    virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
   1.300 +        const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
   1.301 +
   1.302 +    /**
   1.303 +     * Get time zone offsets from local wall time.
   1.304 +     * @internal
   1.305 +     */
   1.306 +    virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
   1.307 +        int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
   1.308 +
   1.309 +private:
   1.310 +    void deleteRules(void);
   1.311 +    void deleteTransitions(void);
   1.312 +    UVector* copyRules(UVector* source);
   1.313 +    TimeZoneRule* findRuleInFinal(UDate date, UBool local,
   1.314 +        int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
   1.315 +    UBool findNext(UDate base, UBool inclusive, UDate& time, TimeZoneRule*& from, TimeZoneRule*& to) const;
   1.316 +    UBool findPrev(UDate base, UBool inclusive, UDate& time, TimeZoneRule*& from, TimeZoneRule*& to) const;
   1.317 +    int32_t getLocalDelta(int32_t rawBefore, int32_t dstBefore, int32_t rawAfter, int32_t dstAfter,
   1.318 +        int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
   1.319 +    UDate getTransitionTime(Transition* transition, UBool local,
   1.320 +        int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt) const;
   1.321 +    void getOffsetInternal(UDate date, UBool local, int32_t NonExistingTimeOpt, int32_t DuplicatedTimeOpt,
   1.322 +        int32_t& rawOffset, int32_t& dstOffset, UErrorCode& ec) const;
   1.323 +    void completeConst(UErrorCode &status) const;
   1.324 +
   1.325 +    InitialTimeZoneRule *fInitialRule;
   1.326 +    UVector             *fHistoricRules;
   1.327 +    UVector             *fFinalRules;
   1.328 +    UVector             *fHistoricTransitions;
   1.329 +    UBool               fUpToDate;
   1.330 +
   1.331 +public:
   1.332 +    /**
   1.333 +     * Return the class ID for this class. This is useful only for comparing to
   1.334 +     * a return value from getDynamicClassID(). For example:
   1.335 +     * <pre>
   1.336 +     * .   Base* polymorphic_pointer = createPolymorphicObject();
   1.337 +     * .   if (polymorphic_pointer->getDynamicClassID() ==
   1.338 +     * .       erived::getStaticClassID()) ...
   1.339 +     * </pre>
   1.340 +     * @return          The class ID for all objects of this class.
   1.341 +     * @stable ICU 3.8
   1.342 +     */
   1.343 +    static UClassID U_EXPORT2 getStaticClassID(void);
   1.344 +
   1.345 +    /**
   1.346 +     * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
   1.347 +     * method is to implement a simple version of RTTI, since not all C++
   1.348 +     * compilers support genuine RTTI. Polymorphic operator==() and clone()
   1.349 +     * methods call this method.
   1.350 +     *
   1.351 +     * @return          The class ID for this object. All objects of a
   1.352 +     *                  given class have the same class ID.  Objects of
   1.353 +     *                  other classes have different class IDs.
   1.354 +     * @stable ICU 3.8
   1.355 +     */
   1.356 +    virtual UClassID getDynamicClassID(void) const;
   1.357 +};
   1.358 +
   1.359 +U_NAMESPACE_END
   1.360 +
   1.361 +#endif /* #if !UCONFIG_NO_FORMATTING */
   1.362 +
   1.363 +#endif // RBTZ_H
   1.364 +
   1.365 +//eof

mercurial