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

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

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

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

michael@0:      * .   Base* polymorphic_pointer = createPolymorphicObject();
michael@0:      * .   if (polymorphic_pointer->getDynamicClassID() ==
michael@0:      * .       erived::getStaticClassID()) ...
michael@0:      * 
michael@0: * @return The class ID for all objects of this class. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: /** michael@0: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This michael@0: * method is to implement a simple version of RTTI, since not all C++ michael@0: * compilers support genuine RTTI. Polymorphic operator==() and clone() michael@0: * methods call this method. michael@0: * michael@0: * @return The class ID for this object. All objects of a michael@0: * given class have the same class ID. Objects of michael@0: * other classes have different class IDs. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const; michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // VTZONE_H michael@0: //eof