michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2009-2011, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: RFC2445 VTIMEZONE support michael@0: * michael@0: *
This is a C wrapper around the C++ VTimeZone class.
michael@0: */ michael@0: michael@0: #ifndef __VZONE_H michael@0: #define __VZONE_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "ztrans.h" michael@0: michael@0: #ifndef UCNV_H michael@0: struct VZone; michael@0: /** michael@0: * A UnicodeSet. Use the vzone_* API to manipulate. Create with michael@0: * vzone_open*, and destroy with vzone_close. michael@0: */ michael@0: typedef struct VZone VZone; michael@0: #endif michael@0: michael@0: /********************************************************************* michael@0: * VZone API michael@0: *********************************************************************/ michael@0: michael@0: /** michael@0: * Creates a vzone from the given time zone ID. michael@0: * @param ID The time zone ID, such as America/New_York michael@0: * @param idLength, length of the ID parameter michael@0: * @return A vzone object initialized by the time zone ID, michael@0: * or NULL when the ID is unknown. michael@0: */ michael@0: U_CAPI VZone* U_EXPORT2 michael@0: vzone_openID(const UChar* ID, int32_t idLength); michael@0: michael@0: /** michael@0: * Create a vzone instance by RFC2445 VTIMEZONE data michael@0: * @param vtzdata The string including VTIMEZONE data block michael@0: * @param vtzdataLength, length of the vtzdata michael@0: * @param status Output param to filled in with a success or an error. michael@0: * @return A vzone initialized by the VTIMEZONE data or michael@0: * NULL if failed to load the rule from the VTIMEZONE data. michael@0: */ michael@0: U_CAPI VZone* U_EXPORT2 michael@0: vzone_openData(const UChar* vtzdata, int32_t vtzdataLength, UErrorCode& status); michael@0: michael@0: /** michael@0: * Disposes of the storage used by a VZone object. This function should michael@0: * be called exactly once for objects returned by vzone_open*. michael@0: * @param set the object to dispose of michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: vzone_close(VZone* zone); michael@0: michael@0: /** michael@0: * Returns a copy of this object. michael@0: * @param zone the original vzone michael@0: * @return the newly allocated copy of the vzone michael@0: */ michael@0: U_CAPI VZone* U_EXPORT2 michael@0: vzone_clone(const VZone *zone); michael@0: michael@0: /** michael@0: * Returns true if zone1 is identical to zone2 michael@0: * and vis versa. michael@0: * @param zone1 to be checked for containment michael@0: * @param zone2 to be checked for containment michael@0: * @return true if the test condition is met michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: vzone_equals(const VZone* zone1, const VZone* zone2); michael@0: michael@0: /** michael@0: * Gets the RFC2445 TZURL property value. When a vzone instance was michael@0: * created from VTIMEZONE data, the initial value is set by the TZURL michael@0: * property value in the data. Otherwise, the initial value is not set. michael@0: * @param zone, the vzone to use michael@0: * @param url Receives the RFC2445 TZURL property value. michael@0: * @param urlLength, length of the url michael@0: * @return TRUE if TZURL attribute is available and value is set. michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: vzone_getTZURL(VZone* zone, UChar* & url, int32_t & urlLength); michael@0: michael@0: /** michael@0: * Sets the RFC2445 TZURL property value. michael@0: * @param zone, the vzone to use michael@0: * @param url The TZURL property value. michael@0: * @param urlLength, length of the url michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: vzone_setTZURL(VZone* zone, UChar* url, int32_t urlLength); michael@0: michael@0: /** michael@0: * Gets the RFC2445 LAST-MODIFIED property value. When a vzone instance michael@0: * was created from VTIMEZONE data, the initial value is set by the michael@0: * LAST-MODIFIED property value in the data. Otherwise, the initial value michael@0: * is not set. michael@0: * @param zone, the vzone to use michael@0: * @param lastModified Receives the last modified date. michael@0: * @return TRUE if lastModified attribute is available and value is set. michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: vzone_getLastModified(VZone* zone, UDate& lastModified); michael@0: michael@0: /** michael@0: * Sets the RFC2445 LAST-MODIFIED property value. michael@0: * @param zone, the vzone to use michael@0: * @param lastModified The LAST-MODIFIED date. michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: vzone_setLastModified(VZone* zone, UDate lastModified); michael@0: michael@0: /** michael@0: * Writes RFC2445 VTIMEZONE data for this time zone michael@0: * @param zone, the vzone to use michael@0: * @param result Output param to filled in with the VTIMEZONE data. michael@0: * @param resultLength, length of the result output michael@0: * @param status Output param to filled in with a success or an error. michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: vzone_write(VZone* zone, UChar* & result, int32_t & resultLength, UErrorCode& status); 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 zone, the vzone to use michael@0: * @param start The start date. michael@0: * @param result Output param to filled in with the VTIMEZONE data. michael@0: * @param resultLength, length of the result output michael@0: * @param status Output param to filled in with a success or an error. michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: vzone_writeFromStart(VZone* zone, UDate start, UChar* & result, int32_t & resultLength, UErrorCode& status); 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 zone, the vzone to use 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: */ michael@0: U_CAPI void U_EXPORT2 michael@0: vzone_writeSimple(VZone* zone, UDate time, UChar* & result, int32_t & resultLength, UErrorCode& status); 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 zone, the vzone to use 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: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: vzone_getOffset(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day, michael@0: uint8_t dayOfWeek, int32_t millis, UErrorCode& status); 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 zone, the vzone to use
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: */
michael@0: U_CAPI int32_t U_EXPORT2
michael@0: vzone_getOffset2(VZone* zone, 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);
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 zone, the vzone to use
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: */
michael@0: U_CAPI void U_EXPORT2
michael@0: vzone_getOffset3(VZone* zone, UDate date, UBool local, int32_t& rawOffset,
michael@0: int32_t& dstOffset, UErrorCode& ec);
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 zone, the vzone to use
michael@0: * @param offsetMillis The new raw GMT offset for this time zone.
michael@0: */
michael@0: U_CAPI void U_EXPORT2
michael@0: vzone_setRawOffset(VZone* zone, 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: * @param zone, the vzone to use
michael@0: * @return The TimeZone's raw GMT offset.
michael@0: */
michael@0: U_CAPI int32_t U_EXPORT2
michael@0: vzone_getRawOffset(VZone* zone);
michael@0:
michael@0: /**
michael@0: * Queries if this time zone uses daylight savings time.
michael@0: * @param zone, the vzone to use
michael@0: * @return true if this time zone uses daylight savings time,
michael@0: * false, otherwise.
michael@0: */
michael@0: U_CAPI UBool U_EXPORT2
michael@0: vzone_useDaylightTime(VZone* zone);
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 zone, the vzone to use
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: */
michael@0: U_INTERNAL UBool U_EXPORT2
michael@0: vzone_inDaylightTime(VZone* zone, UDate date, UErrorCode& status);
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 zone, the vzone to use
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: */
michael@0: U_CAPI UBool U_EXPORT2
michael@0: vzone_hasSameRules(VZone* zone, const VZone* other);
michael@0:
michael@0: /**
michael@0: * Gets the first time zone transition after the base time.
michael@0: * @param zone, the vzone to use
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: */
michael@0: U_CAPI UBool U_EXPORT2
michael@0: vzone_getNextTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result);
michael@0:
michael@0: /**
michael@0: * Gets the most recent time zone transition before the base time.
michael@0: * @param zone, the vzone to use
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: */
michael@0: U_CAPI UBool U_EXPORT2
michael@0: vzone_getPreviousTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result);
michael@0:
michael@0: /**
michael@0: * Returns the number of TimeZoneRule
s which represents time transitions,
michael@0: * for this time zone, that is, all TimeZoneRule
s for this time zone except
michael@0: * InitialTimeZoneRule
. The return value range is 0 or any positive value.
michael@0: * @param zone, the vzone to use
michael@0: * @param status Receives error status code.
michael@0: * @return The number of TimeZoneRule
s representing time transitions.
michael@0: */
michael@0: U_CAPI int32_t U_EXPORT2
michael@0: vzone_countTransitionRules(VZone* zone, UErrorCode& status);
michael@0:
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: * @param zone, the vzone to use michael@0: * @return The class ID for all objects of this class. michael@0: */ michael@0: U_CAPI UClassID U_EXPORT2 michael@0: vzone_getStaticClassID(VZone* zone); 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: * @param zone, the vzone to use 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: */ michael@0: U_CAPI UClassID U_EXPORT2 michael@0: vzone_getDynamicClassID(VZone* zone); michael@0: michael@0: #endif // __VZONE_H michael@0: michael@0: #endif