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-2013, International Business Machines Corporation and jpayne@69: * others. All Rights Reserved. jpayne@69: ******************************************************************************* jpayne@69: */ jpayne@69: #ifndef VTZONE_H jpayne@69: #define VTZONE_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: RFC2445 VTIMEZONE support jpayne@69: */ jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/basictz.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class VTZWriter; jpayne@69: class VTZReader; jpayne@69: class UVector; jpayne@69: jpayne@69: /** jpayne@69: * VTimeZone is a class implementing RFC2445 VTIMEZONE. You can create a jpayne@69: * VTimeZone instance from a time zone ID supported by TimeZone. jpayne@69: * With the VTimeZone instance created from the ID, you can write out the rule jpayne@69: * in RFC2445 VTIMEZONE format. Also, you can create a VTimeZone instance jpayne@69: * from RFC2445 VTIMEZONE data stream, which allows you to calculate time jpayne@69: * zone offset by the rules defined by the data. Or, you can create a jpayne@69: * VTimeZone from any other ICU BasicTimeZone. jpayne@69: *

jpayne@69: * Note: The consumer of this class reading or writing VTIMEZONE data is responsible to jpayne@69: * decode or encode Non-ASCII text. Methods reading/writing VTIMEZONE data in this class jpayne@69: * do nothing with MIME encoding. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: class U_I18N_API VTimeZone : public BasicTimeZone { jpayne@69: public: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @param source The VTimeZone object to be copied. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: VTimeZone(const VTimeZone& source); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual ~VTimeZone(); 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: VTimeZone& operator=(const VTimeZone& right); jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZone objects are jpayne@69: * semantically equal. Objects of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZone objects are jpayne@69: *semantically equal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator==(const TimeZone& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given TimeZone objects are jpayne@69: * semantically unequal. Objects of different subclasses are considered unequal. jpayne@69: * @param that The object to be compared with. jpayne@69: * @return true if the given TimeZone objects are jpayne@69: * semantically unequal. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool operator!=(const TimeZone& that) const; jpayne@69: jpayne@69: /** jpayne@69: * Create a VTimeZone instance by the time zone ID. jpayne@69: * @param ID The time zone ID, such as America/New_York jpayne@69: * @return A VTimeZone object initialized by the time zone ID, jpayne@69: * or NULL when the ID is unknown. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static VTimeZone* createVTimeZoneByID(const UnicodeString& ID); jpayne@69: jpayne@69: /** jpayne@69: * Create a VTimeZone instance using a basic time zone. jpayne@69: * @param basicTZ The basic time zone instance jpayne@69: * @param status Output param to filled in with a success or an error. jpayne@69: * @return A VTimeZone object initialized by the basic time zone. jpayne@69: * @stable ICU 4.6 jpayne@69: */ jpayne@69: static VTimeZone* createVTimeZoneFromBasicTimeZone(const BasicTimeZone& basicTZ, jpayne@69: UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Create a VTimeZone instance by RFC2445 VTIMEZONE data jpayne@69: * jpayne@69: * @param vtzdata The string including VTIMEZONE data block jpayne@69: * @param status Output param to filled in with a success or an error. jpayne@69: * @return A VTimeZone initialized by the VTIMEZONE data or jpayne@69: * NULL if failed to load the rule from the VTIMEZONE data. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: static VTimeZone* createVTimeZone(const UnicodeString& vtzdata, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Gets the RFC2445 TZURL property value. When a VTimeZone instance was jpayne@69: * created from VTIMEZONE data, the initial value is set by the TZURL property value jpayne@69: * in the data. Otherwise, the initial value is not set. jpayne@69: * @param url Receives the RFC2445 TZURL property value. jpayne@69: * @return TRUE if TZURL attribute is available and value is set. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UBool getTZURL(UnicodeString& url) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the RFC2445 TZURL property value. jpayne@69: * @param url The TZURL property value. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void setTZURL(const UnicodeString& url); jpayne@69: jpayne@69: /** jpayne@69: * Gets the RFC2445 LAST-MODIFIED property value. When a VTimeZone instance jpayne@69: * was created from VTIMEZONE data, the initial value is set by the LAST-MODIFIED property jpayne@69: * value in the data. Otherwise, the initial value is not set. jpayne@69: * @param lastModified Receives the last modified date. jpayne@69: * @return TRUE if lastModified attribute is available and value is set. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: UBool getLastModified(UDate& lastModified) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the RFC2445 LAST-MODIFIED property value. jpayne@69: * @param lastModified The LAST-MODIFIED date. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void setLastModified(UDate lastModified); jpayne@69: jpayne@69: /** jpayne@69: * Writes RFC2445 VTIMEZONE data for this time zone jpayne@69: * @param result Output param to filled in with the VTIMEZONE data. jpayne@69: * @param status Output param to filled in with a success or an error. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void write(UnicodeString& result, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Writes RFC2445 VTIMEZONE data for this time zone applicalbe jpayne@69: * for dates after the specified start time. jpayne@69: * @param start The start date. jpayne@69: * @param result Output param to filled in with the VTIMEZONE data. jpayne@69: * @param status Output param to filled in with a success or an error. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void write(UDate start, UnicodeString& result, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Writes RFC2445 VTIMEZONE data applicalbe for the specified date. jpayne@69: * Some common iCalendar implementations can only handle a single time jpayne@69: * zone property or a pair of standard and daylight time properties using jpayne@69: * BYDAY rule with day of week (such as BYDAY=1SUN). This method produce jpayne@69: * the VTIMEZONE data which can be handled these implementations. The rules jpayne@69: * produced by this method can be used only for calculating time zone offset jpayne@69: * around the specified date. jpayne@69: * @param time The date used for rule extraction. jpayne@69: * @param result Output param to filled in with the VTIMEZONE data. jpayne@69: * @param status Output param to filled in with a success or an error. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: void writeSimple(UDate time, UnicodeString& result, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Clones TimeZone objects polymorphically. Clients are responsible for deleting jpayne@69: * the TimeZone object cloned. jpayne@69: * @return A new copy of this TimeZone object. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual VTimeZone* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add jpayne@69: * to GMT to get local time in this time zone, taking daylight savings time into jpayne@69: * account) as of a particular reference date. The reference date is used to determine jpayne@69: * whether daylight savings time is in effect and needs to be figured into the offset jpayne@69: * that is returned (in other words, what is the adjusted GMT offset in this time zone jpayne@69: * at this particular date and time?). For the time zones produced by createTimeZone(), jpayne@69: * the reference data is specified according to the Gregorian calendar, and the date jpayne@69: * and time fields are local standard time. jpayne@69: * jpayne@69: *

Note: Don't call this method. Instead, call the getOffset(UDate...) overload, jpayne@69: * which returns both the raw and the DST offset for a given time. This method jpayne@69: * is retained only for backward compatibility. jpayne@69: * jpayne@69: * @param era The reference date's era jpayne@69: * @param year The reference date's year jpayne@69: * @param month The reference date's month (0-based; 0 is January) jpayne@69: * @param day The reference date's day-in-month (1-based) jpayne@69: * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) jpayne@69: * @param millis The reference date's milliseconds in day, local standard time jpayne@69: * @param status Output param to filled in with a success or an error. jpayne@69: * @return The offset in milliseconds to add to GMT to get local time. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, jpayne@69: uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the time zone offset, for current date, modified in case of jpayne@69: * daylight savings. This is the offset to add *to* UTC to get local time. jpayne@69: * jpayne@69: *

Note: Don't call this method. Instead, call the getOffset(UDate...) overload, jpayne@69: * which returns both the raw and the DST offset for a given time. This method jpayne@69: * is retained only for backward compatibility. jpayne@69: * jpayne@69: * @param era The reference date's era jpayne@69: * @param year The reference date's year jpayne@69: * @param month The reference date's month (0-based; 0 is January) jpayne@69: * @param day The reference date's day-in-month (1-based) jpayne@69: * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) jpayne@69: * @param millis The reference date's milliseconds in day, local standard time jpayne@69: * @param monthLength The length of the given month in days. jpayne@69: * @param status Output param to filled in with a success or an error. jpayne@69: * @return The offset in milliseconds to add to GMT to get local time. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, jpayne@69: uint8_t dayOfWeek, int32_t millis, jpayne@69: int32_t monthLength, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the time zone raw and GMT offset for the given moment jpayne@69: * in time. Upon return, local-millis = GMT-millis + rawOffset + jpayne@69: * dstOffset. All computations are performed in the proleptic jpayne@69: * Gregorian calendar. The default implementation in the TimeZone jpayne@69: * class delegates to the 8-argument getOffset(). jpayne@69: * jpayne@69: * @param date moment in time for which to return offsets, in jpayne@69: * units of milliseconds from January 1, 1970 0:00 GMT, either GMT jpayne@69: * time or local wall time, depending on `local'. jpayne@69: * @param local if true, `date' is local wall time; otherwise it jpayne@69: * is in GMT time. jpayne@69: * @param rawOffset output parameter to receive the raw offset, that jpayne@69: * is, the offset not including DST adjustments jpayne@69: * @param dstOffset output parameter to receive the DST offset, jpayne@69: * that is, the offset to be added to `rawOffset' to obtain the jpayne@69: * total offset between local and GMT time. If DST is not in jpayne@69: * effect, this value is zero; otherwise it is a positive value, jpayne@69: * typically one hour. jpayne@69: * @param ec input-output error code jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual void getOffset(UDate date, UBool local, int32_t& rawOffset, jpayne@69: int32_t& dstOffset, UErrorCode& ec) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add jpayne@69: * to GMT to get local time, before taking daylight savings time into account). jpayne@69: * jpayne@69: * @param offsetMillis The new raw GMT offset for this time zone. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual void setRawOffset(int32_t offsetMillis); jpayne@69: jpayne@69: /** jpayne@69: * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add jpayne@69: * to GMT to get local time, before taking daylight savings time into account). jpayne@69: * jpayne@69: * @return The TimeZone's raw GMT offset. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual int32_t getRawOffset(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Queries if this time zone uses daylight savings time. jpayne@69: * @return true if this time zone uses daylight savings time, jpayne@69: * false, otherwise. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool useDaylightTime(void) const; jpayne@69: jpayne@69: #ifndef U_FORCE_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Queries if the given date is in daylight savings time in jpayne@69: * this time zone. jpayne@69: * This method is wasteful since it creates a new GregorianCalendar and jpayne@69: * deletes it each time it is called. This is a deprecated method jpayne@69: * and provided only for Java compatibility. jpayne@69: * jpayne@69: * @param date the given UDate. jpayne@69: * @param status Output param filled in with success/error code. jpayne@69: * @return true if the given date is in daylight savings time, jpayne@69: * false, otherwise. jpayne@69: * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead. jpayne@69: */ jpayne@69: virtual UBool inDaylightTime(UDate date, UErrorCode& status) const; jpayne@69: #endif // U_FORCE_HIDE_DEPRECATED_API jpayne@69: jpayne@69: /** jpayne@69: * Returns true if this zone has the same rule and offset as another zone. jpayne@69: * That is, if this zone differs only in ID, if at all. jpayne@69: * @param other the TimeZone object to be compared with jpayne@69: * @return true if the given zone is the same as this one, jpayne@69: * with the possible exception of the ID jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool hasSameRules(const TimeZone& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the first time zone transition after the base time. jpayne@69: * @param base The base time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives the first transition after the base time. jpayne@69: * @return TRUE if the transition is found. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the most recent time zone transition before the base time. jpayne@69: * @param base The base time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives the most recent transition before the base time. jpayne@69: * @return TRUE if the transition is found. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the number of TimeZoneRules which represents time transitions, jpayne@69: * for this time zone, that is, all TimeZoneRules for this time zone except jpayne@69: * InitialTimeZoneRule. The return value range is 0 or any positive value. jpayne@69: * @param status Receives error status code. jpayne@69: * @return The number of TimeZoneRules representing time transitions. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual int32_t countTransitionRules(UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the InitialTimeZoneRule and the set of TimeZoneRule jpayne@69: * which represent time transitions for this time zone. On successful return, jpayne@69: * the argument initial points to non-NULL InitialTimeZoneRule and jpayne@69: * the array trsrules is filled with 0 or multiple TimeZoneRule jpayne@69: * instances up to the size specified by trscount. The results are referencing the jpayne@69: * rule instance held by this time zone instance. Therefore, after this time zone jpayne@69: * is destructed, they are no longer available. jpayne@69: * @param initial Receives the initial timezone rule jpayne@69: * @param trsrules Receives the timezone transition rules jpayne@69: * @param trscount On input, specify the size of the array 'transitions' receiving jpayne@69: * the timezone transition rules. On output, actual number of jpayne@69: * rules filled in the array will be set. jpayne@69: * @param status Receives error status code. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial, jpayne@69: const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const; jpayne@69: jpayne@69: private: jpayne@69: enum { DEFAULT_VTIMEZONE_LINES = 100 }; jpayne@69: jpayne@69: /** jpayne@69: * Default constructor. jpayne@69: */ jpayne@69: VTimeZone(); jpayne@69: static VTimeZone* createVTimeZone(VTZReader* reader); jpayne@69: void write(VTZWriter& writer, UErrorCode& status) const; jpayne@69: void write(UDate start, VTZWriter& writer, UErrorCode& status) const; jpayne@69: void writeSimple(UDate time, VTZWriter& writer, UErrorCode& status) const; jpayne@69: void load(VTZReader& reader, UErrorCode& status); jpayne@69: void parse(UErrorCode& status); jpayne@69: jpayne@69: void writeZone(VTZWriter& w, BasicTimeZone& basictz, UVector* customProps, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: void writeHeaders(VTZWriter& w, UErrorCode& status) const; jpayne@69: void writeFooter(VTZWriter& writer, UErrorCode& status) const; jpayne@69: jpayne@69: void writeZonePropsByTime(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, jpayne@69: int32_t fromOffset, int32_t toOffset, UDate time, UBool withRDATE, jpayne@69: UErrorCode& status) const; jpayne@69: void writeZonePropsByDOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, jpayne@69: int32_t fromOffset, int32_t toOffset, jpayne@69: int32_t month, int32_t dayOfMonth, UDate startTime, UDate untilTime, jpayne@69: UErrorCode& status) const; jpayne@69: void writeZonePropsByDOW(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, jpayne@69: int32_t fromOffset, int32_t toOffset, jpayne@69: int32_t month, int32_t weekInMonth, int32_t dayOfWeek, jpayne@69: UDate startTime, UDate untilTime, UErrorCode& status) const; jpayne@69: void writeZonePropsByDOW_GEQ_DOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, jpayne@69: int32_t fromOffset, int32_t toOffset, jpayne@69: int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, jpayne@69: UDate startTime, UDate untilTime, UErrorCode& status) const; jpayne@69: void writeZonePropsByDOW_GEQ_DOM_sub(VTZWriter& writer, int32_t month, int32_t dayOfMonth, jpayne@69: int32_t dayOfWeek, int32_t numDays, jpayne@69: UDate untilTime, int32_t fromOffset, UErrorCode& status) const; jpayne@69: void writeZonePropsByDOW_LEQ_DOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, jpayne@69: int32_t fromOffset, int32_t toOffset, jpayne@69: int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, jpayne@69: UDate startTime, UDate untilTime, UErrorCode& status) const; jpayne@69: void writeFinalRule(VTZWriter& writer, UBool isDst, const AnnualTimeZoneRule* rule, jpayne@69: int32_t fromRawOffset, int32_t fromDSTSavings, jpayne@69: UDate startTime, UErrorCode& status) const; jpayne@69: jpayne@69: void beginZoneProps(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, jpayne@69: int32_t fromOffset, int32_t toOffset, UDate startTime, UErrorCode& status) const; jpayne@69: void endZoneProps(VTZWriter& writer, UBool isDst, UErrorCode& status) const; jpayne@69: void beginRRULE(VTZWriter& writer, int32_t month, UErrorCode& status) const; jpayne@69: void appendUNTIL(VTZWriter& writer, const UnicodeString& until, UErrorCode& status) const; jpayne@69: jpayne@69: BasicTimeZone *tz; jpayne@69: UVector *vtzlines; jpayne@69: UnicodeString tzurl; jpayne@69: UDate lastmod; jpayne@69: UnicodeString olsonzid; jpayne@69: UnicodeString icutzver; 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: 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 // VTZONE_H jpayne@69: //eof