jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * Copyright (C) 2007-2008, International Business Machines Corporation and * jpayne@69: * others. All Rights Reserved. * jpayne@69: ******************************************************************************* jpayne@69: */ jpayne@69: #ifndef TZRULE_H jpayne@69: #define TZRULE_H jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Time zone rule classes jpayne@69: */ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/uobject.h" jpayne@69: #include "unicode/unistr.h" jpayne@69: #include "unicode/dtrule.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * TimeZoneRule is a class representing a rule for time zone. jpayne@69: * TimeZoneRule has a set of time zone attributes, such as zone name, jpayne@69: * raw offset (UTC offset for standard time) and daylight saving time offset. jpayne@69: * jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: class U_I18N_API TimeZoneRule : public UObject { jpayne@69: public: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual ~TimeZoneRule(); jpayne@69: jpayne@69: /** jpayne@69: * Clone this TimeZoneRule object polymorphically. The caller owns the result and jpayne@69: * should delete it when done. jpayne@69: * @return A copy of the object. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual TimeZoneRule* clone() const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZoneRule objects are semantically equal. Objects jpayne@69: * of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZoneRule objects are semantically equal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator==(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZoneRule objects are semantically unequal. Objects jpayne@69: * of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZoneRule objects are semantically unequal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator!=(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Fills in "name" with the name of this time zone. jpayne@69: * @param name Receives the name of this time zone. jpayne@69: * @return A reference to "name" jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UnicodeString& getName(UnicodeString& name) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the standard time offset. jpayne@69: * @return The standard time offset from UTC in milliseconds. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: int32_t getRawOffset(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the amount of daylight saving delta time from the standard time. jpayne@69: * @return The amount of daylight saving offset used by this rule jpayne@69: * in milliseconds. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: int32_t getDSTSavings(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns if this rule represents the same rule and offsets as another. jpayne@69: * When two TimeZoneRule objects differ only its names, this method jpayne@69: * returns true. jpayne@69: * @param other The TimeZoneRule object to be compared with. jpayne@69: * @return true if the other TimeZoneRule is the same as this one. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool isEquivalentTo(const TimeZoneRule& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the very first time when this rule takes effect. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the very first time when this rule takes effect. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Gets the final time when this rule takes effect. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the final time when this rule takes effect. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Gets the first time when this rule takes effect after the specified time. jpayne@69: * @param base The first start time after this base time will be returned. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives The first time when this rule takes effect after jpayne@69: * the specified base time. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, jpayne@69: UBool inclusive, UDate& result) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Gets the most recent time when this rule takes effect before the specified time. jpayne@69: * @param base The most recent time before this base time will be returned. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives The most recent time when this rule takes effect before jpayne@69: * the specified base time. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, jpayne@69: UBool inclusive, UDate& result) const = 0; jpayne@69: jpayne@69: protected: jpayne@69: jpayne@69: /** jpayne@69: * Constructs a TimeZoneRule with the name, the GMT offset of its jpayne@69: * standard time and the amount of daylight saving offset adjustment. jpayne@69: * @param name The time zone name. jpayne@69: * @param rawOffset The UTC offset of its standard time in milliseconds. jpayne@69: * @param dstSavings The amount of daylight saving offset adjustment in milliseconds. jpayne@69: * If this ia a rule for standard time, the value of this argument is 0. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: TimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @param source The TimeZoneRule object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: TimeZoneRule(const TimeZoneRule& source); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * @param right The object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: TimeZoneRule& operator=(const TimeZoneRule& right); jpayne@69: jpayne@69: private: jpayne@69: UnicodeString fName; // time name jpayne@69: int32_t fRawOffset; // UTC offset of the standard time in milliseconds jpayne@69: int32_t fDSTSavings; // DST saving amount in milliseconds jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * InitialTimeZoneRule represents a time zone rule jpayne@69: * representing a time zone effective from the beginning and jpayne@69: * has no actual start times. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: class U_I18N_API InitialTimeZoneRule : public TimeZoneRule { jpayne@69: public: jpayne@69: /** jpayne@69: * Constructs an InitialTimeZoneRule with the name, the GMT offset of its jpayne@69: * standard time and the amount of daylight saving offset adjustment. jpayne@69: * @param name The time zone name. jpayne@69: * @param rawOffset The UTC offset of its standard time in milliseconds. jpayne@69: * @param dstSavings The amount of daylight saving offset adjustment in milliseconds. jpayne@69: * If this ia a rule for standard time, the value of this argument is 0. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: InitialTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @param source The InitialTimeZoneRule object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: InitialTimeZoneRule(const InitialTimeZoneRule& source); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual ~InitialTimeZoneRule(); jpayne@69: jpayne@69: /** jpayne@69: * Clone this InitialTimeZoneRule object polymorphically. The caller owns the result and jpayne@69: * should delete it when done. jpayne@69: * @return A copy of the object. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual InitialTimeZoneRule* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * @param right The object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: InitialTimeZoneRule& operator=(const InitialTimeZoneRule& right); jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZoneRule objects are semantically equal. Objects jpayne@69: * of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZoneRule objects are semantically equal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator==(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZoneRule objects are semantically unequal. Objects jpayne@69: * of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZoneRule objects are semantically unequal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator!=(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the time when this rule takes effect in the given year. jpayne@69: * @param year The Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the start time in the year. jpayne@69: * @return true if this rule takes effect in the year and the result is set to jpayne@69: * "result". jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns if this rule represents the same rule and offsets as another. jpayne@69: * When two TimeZoneRule objects differ only its names, this method jpayne@69: * returns true. jpayne@69: * @param that The TimeZoneRule object to be compared with. jpayne@69: * @return true if the other TimeZoneRule is equivalent to this one. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool isEquivalentTo(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the very first time when this rule takes effect. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the very first time when this rule takes effect. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the final time when this rule takes effect. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the final time when this rule takes effect. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the first time when this rule takes effect after the specified time. jpayne@69: * @param base The first start time after this base time will be returned. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives The first time when this rule takes effect after jpayne@69: * the specified base time. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, jpayne@69: UBool inclusive, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the most recent time when this rule takes effect before the specified time. jpayne@69: * @param base The most recent time before this base time will be returned. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives The most recent time when this rule takes effect before jpayne@69: * the specified base time. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, jpayne@69: UBool inclusive, UDate& result) const; jpayne@69: jpayne@69: public: jpayne@69: /** jpayne@69: * Return the class ID for this class. This is useful only for comparing to jpayne@69: * a return value from getDynamicClassID(). For example: jpayne@69: *
jpayne@69:      * .   Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69:      * .   if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69:      * .       erived::getStaticClassID()) ...
jpayne@69:      * 
jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This jpayne@69: * method is to implement a simple version of RTTI, since not all C++ jpayne@69: * compilers support genuine RTTI. Polymorphic operator==() and clone() jpayne@69: * methods call this method. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a jpayne@69: * given class have the same class ID. Objects of jpayne@69: * other classes have different class IDs. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const; jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * AnnualTimeZoneRule is a class used for representing a time zone jpayne@69: * rule which takes effect annually. The calenday system used for the rule is jpayne@69: * is based on Gregorian calendar jpayne@69: * jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: class U_I18N_API AnnualTimeZoneRule : public TimeZoneRule { jpayne@69: public: jpayne@69: /** jpayne@69: * The constant representing the maximum year used for designating jpayne@69: * a rule is permanent. jpayne@69: */ jpayne@69: static const int32_t MAX_YEAR; jpayne@69: jpayne@69: /** jpayne@69: * Constructs a AnnualTimeZoneRule with the name, the GMT offset of its jpayne@69: * standard time, the amount of daylight saving offset adjustment, the annual start jpayne@69: * time rule and the start/until years. The input DateTimeRule is copied by this jpayne@69: * constructor, so the caller remains responsible for deleting the object. jpayne@69: * @param name The time zone name. jpayne@69: * @param rawOffset The GMT offset of its standard time in milliseconds. jpayne@69: * @param dstSavings The amount of daylight saving offset adjustment in jpayne@69: * milliseconds. If this ia a rule for standard time, jpayne@69: * the value of this argument is 0. jpayne@69: * @param dateTimeRule The start date/time rule repeated annually. jpayne@69: * @param startYear The first year when this rule takes effect. jpayne@69: * @param endYear The last year when this rule takes effect. If this jpayne@69: * rule is effective forever in future, specify MAX_YEAR. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings, jpayne@69: const DateTimeRule& dateTimeRule, int32_t startYear, int32_t endYear); jpayne@69: jpayne@69: /** jpayne@69: * Constructs a AnnualTimeZoneRule with the name, the GMT offset of its jpayne@69: * standard time, the amount of daylight saving offset adjustment, the annual start jpayne@69: * time rule and the start/until years. The input DateTimeRule object is adopted jpayne@69: * by this object, therefore, the caller must not delete the object. jpayne@69: * @param name The time zone name. jpayne@69: * @param rawOffset The GMT offset of its standard time in milliseconds. jpayne@69: * @param dstSavings The amount of daylight saving offset adjustment in jpayne@69: * milliseconds. If this ia a rule for standard time, jpayne@69: * the value of this argument is 0. jpayne@69: * @param dateTimeRule The start date/time rule repeated annually. jpayne@69: * @param startYear The first year when this rule takes effect. jpayne@69: * @param endYear The last year when this rule takes effect. If this jpayne@69: * rule is effective forever in future, specify MAX_YEAR. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings, jpayne@69: DateTimeRule* dateTimeRule, int32_t startYear, int32_t endYear); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @param source The AnnualTimeZoneRule object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: AnnualTimeZoneRule(const AnnualTimeZoneRule& source); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual ~AnnualTimeZoneRule(); jpayne@69: jpayne@69: /** jpayne@69: * Clone this AnnualTimeZoneRule object polymorphically. The caller owns the result and jpayne@69: * should delete it when done. jpayne@69: * @return A copy of the object. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual AnnualTimeZoneRule* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * @param right The object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: AnnualTimeZoneRule& operator=(const AnnualTimeZoneRule& right); jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZoneRule objects are semantically equal. Objects jpayne@69: * of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZoneRule objects are semantically equal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator==(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZoneRule objects are semantically unequal. Objects jpayne@69: * of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZoneRule objects are semantically unequal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator!=(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the start date/time rule used by this rule. jpayne@69: * @return The AnnualDateTimeRule which represents the start date/time jpayne@69: * rule used by this time zone rule. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: const DateTimeRule* getRule(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the first year when this rule takes effect. jpayne@69: * @return The start year of this rule. The year is in Gregorian calendar jpayne@69: * with 0 == 1 BCE, -1 == 2 BCE, etc. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: int32_t getStartYear(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the end year when this rule takes effect. jpayne@69: * @return The end year of this rule (inclusive). The year is in Gregorian calendar jpayne@69: * with 0 == 1 BCE, -1 == 2 BCE, etc. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: int32_t getEndYear(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the time when this rule takes effect in the given year. jpayne@69: * @param year The Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the start time in the year. jpayne@69: * @return true if this rule takes effect in the year and the result is set to jpayne@69: * "result". jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns if this rule represents the same rule and offsets as another. jpayne@69: * When two TimeZoneRule objects differ only its names, this method jpayne@69: * returns true. jpayne@69: * @param that The TimeZoneRule object to be compared with. jpayne@69: * @return true if the other TimeZoneRule is equivalent to this one. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool isEquivalentTo(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the very first time when this rule takes effect. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the very first time when this rule takes effect. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the final time when this rule takes effect. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the final time when this rule takes effect. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the first time when this rule takes effect after the specified time. jpayne@69: * @param base The first start time after this base time will be returned. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives The first time when this rule takes effect after jpayne@69: * the specified base time. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, jpayne@69: UBool inclusive, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the most recent time when this rule takes effect before the specified time. jpayne@69: * @param base The most recent time before this base time will be returned. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives The most recent time when this rule takes effect before jpayne@69: * the specified base time. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, jpayne@69: UBool inclusive, UDate& result) const; jpayne@69: jpayne@69: jpayne@69: private: jpayne@69: DateTimeRule* fDateTimeRule; jpayne@69: int32_t fStartYear; jpayne@69: int32_t fEndYear; jpayne@69: jpayne@69: public: jpayne@69: /** jpayne@69: * Return the class ID for this class. This is useful only for comparing to jpayne@69: * a return value from getDynamicClassID(). For example: jpayne@69: *
jpayne@69:      * .   Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69:      * .   if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69:      * .       erived::getStaticClassID()) ...
jpayne@69:      * 
jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This jpayne@69: * method is to implement a simple version of RTTI, since not all C++ jpayne@69: * compilers support genuine RTTI. Polymorphic operator==() and clone() jpayne@69: * methods call this method. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a jpayne@69: * given class have the same class ID. Objects of jpayne@69: * other classes have different class IDs. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const; jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * TimeArrayTimeZoneRule represents a time zone rule whose start times are jpayne@69: * defined by an array of milliseconds since the standard base time. jpayne@69: * jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: class U_I18N_API TimeArrayTimeZoneRule : public TimeZoneRule { jpayne@69: public: jpayne@69: /** jpayne@69: * Constructs a TimeArrayTimeZoneRule with the name, the GMT offset of its jpayne@69: * standard time, the amount of daylight saving offset adjustment and jpayne@69: * the array of times when this rule takes effect. jpayne@69: * @param name The time zone name. jpayne@69: * @param rawOffset The UTC offset of its standard time in milliseconds. jpayne@69: * @param dstSavings The amount of daylight saving offset adjustment in jpayne@69: * milliseconds. If this ia a rule for standard time, jpayne@69: * the value of this argument is 0. jpayne@69: * @param startTimes The array start times in milliseconds since the base time jpayne@69: * (January 1, 1970, 00:00:00). jpayne@69: * @param numStartTimes The number of elements in the parameter "startTimes" jpayne@69: * @param timeRuleType The time type of the start times, which is one of jpayne@69: * DataTimeRule::WALL_TIME, STANDARD_TIME jpayne@69: * and UTC_TIME. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: TimeArrayTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings, jpayne@69: const UDate* startTimes, int32_t numStartTimes, DateTimeRule::TimeRuleType timeRuleType); jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @param source The TimeArrayTimeZoneRule object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: TimeArrayTimeZoneRule(const TimeArrayTimeZoneRule& source); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual ~TimeArrayTimeZoneRule(); jpayne@69: jpayne@69: /** jpayne@69: * Clone this TimeArrayTimeZoneRule object polymorphically. The caller owns the result and jpayne@69: * should delete it when done. jpayne@69: * @return A copy of the object. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual TimeArrayTimeZoneRule* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * @param right The object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: TimeArrayTimeZoneRule& operator=(const TimeArrayTimeZoneRule& right); jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZoneRule objects are semantically equal. Objects jpayne@69: * of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZoneRule objects are semantically equal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator==(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZoneRule objects are semantically unequal. Objects jpayne@69: * of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZoneRule objects are semantically unequal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator!=(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the time type of the start times used by this rule. The return value jpayne@69: * is either DateTimeRule::WALL_TIME or STANDARD_TIME jpayne@69: * or UTC_TIME. jpayne@69: * jpayne@69: * @return The time type used of the start times used by this rule. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: DateTimeRule::TimeRuleType getTimeType(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets a start time at the index stored in this rule. jpayne@69: * @param index The index of start times jpayne@69: * @param result Receives the start time at the index jpayne@69: * @return true if the index is within the valid range and jpayne@69: * and the result is set. When false, the output jpayne@69: * parameger "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UBool getStartTimeAt(int32_t index, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the number of start times stored in this rule jpayne@69: * @return The number of start times. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: int32_t countStartTimes(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns if this rule represents the same rule and offsets as another. jpayne@69: * When two TimeZoneRule objects differ only its names, this method jpayne@69: * returns true. jpayne@69: * @param that The TimeZoneRule object to be compared with. jpayne@69: * @return true if the other TimeZoneRule is equivalent to this one. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool isEquivalentTo(const TimeZoneRule& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the very first time when this rule takes effect. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the very first time when this rule takes effect. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the final time when this rule takes effect. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param result Receives the final time when this rule takes effect. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the first time when this rule takes effect after the specified time. jpayne@69: * @param base The first start time after this base time will be returned. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives The first time when this rule takes effect after jpayne@69: * the specified base time. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, jpayne@69: UBool inclusive, UDate& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the most recent time when this rule takes effect before the specified time. jpayne@69: * @param base The most recent time before this base time will be returned. jpayne@69: * @param prevRawOffset The standard time offset from UTC before this rule jpayne@69: * takes effect in milliseconds. jpayne@69: * @param prevDSTSavings The amount of daylight saving offset from the jpayne@69: * standard time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives The most recent time when this rule takes effect before jpayne@69: * the specified base time. jpayne@69: * @return true if the start time is available. When false is returned, output parameter jpayne@69: * "result" is unchanged. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, jpayne@69: UBool inclusive, UDate& result) const; jpayne@69: jpayne@69: jpayne@69: private: jpayne@69: enum { TIMEARRAY_STACK_BUFFER_SIZE = 32 }; jpayne@69: UBool initStartTimes(const UDate source[], int32_t size, UErrorCode& ec); jpayne@69: UDate getUTC(UDate time, int32_t raw, int32_t dst) const; jpayne@69: jpayne@69: DateTimeRule::TimeRuleType fTimeRuleType; jpayne@69: int32_t fNumStartTimes; jpayne@69: UDate* fStartTimes; jpayne@69: UDate fLocalStartTimes[TIMEARRAY_STACK_BUFFER_SIZE]; jpayne@69: jpayne@69: public: jpayne@69: /** jpayne@69: * Return the class ID for this class. This is useful only for comparing to jpayne@69: * a return value from getDynamicClassID(). For example: jpayne@69: *
jpayne@69:      * .   Base* polymorphic_pointer = createPolymorphicObject();
jpayne@69:      * .   if (polymorphic_pointer->getDynamicClassID() ==
jpayne@69:      * .       erived::getStaticClassID()) ...
jpayne@69:      * 
jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: /** jpayne@69: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This jpayne@69: * method is to implement a simple version of RTTI, since not all C++ jpayne@69: * compilers support genuine RTTI. Polymorphic operator==() and clone() jpayne@69: * methods call this method. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a jpayne@69: * given class have the same class ID. Objects of jpayne@69: * other classes have different class IDs. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const; jpayne@69: }; jpayne@69: jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // TZRULE_H jpayne@69: jpayne@69: //eof