2 *******************************************************************************
3 * Copyright (C) 2009-2011, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
10 * \brief C API: RFC2445 VTIMEZONE support
12 * <p>This is a C wrapper around the C++ VTimeZone class.</p>
18 #include "unicode/utypes.h"
20 #if !UCONFIG_NO_FORMATTING
27 * A UnicodeSet. Use the vzone_* API to manipulate. Create with
28 * vzone_open*, and destroy with vzone_close.
30 typedef struct VZone VZone
;
33 /*********************************************************************
35 *********************************************************************/
38 * Creates a vzone from the given time zone ID.
39 * @param ID The time zone ID, such as America/New_York
40 * @param idLength, length of the ID parameter
41 * @return A vzone object initialized by the time zone ID,
42 * or NULL when the ID is unknown.
44 U_CAPI VZone
* U_EXPORT2
45 vzone_openID(const UChar
* ID
, int32_t idLength
);
48 * Create a vzone instance by RFC2445 VTIMEZONE data
49 * @param vtzdata The string including VTIMEZONE data block
50 * @param vtzdataLength, length of the vtzdata
51 * @param status Output param to filled in with a success or an error.
52 * @return A vzone initialized by the VTIMEZONE data or
53 * NULL if failed to load the rule from the VTIMEZONE data.
55 U_CAPI VZone
* U_EXPORT2
56 vzone_openData(const UChar
* vtzdata
, int32_t vtzdataLength
, UErrorCode
& status
);
59 * Disposes of the storage used by a VZone object. This function should
60 * be called exactly once for objects returned by vzone_open*.
61 * @param set the object to dispose of
64 vzone_close(VZone
* zone
);
67 * Returns a copy of this object.
68 * @param zone the original vzone
69 * @return the newly allocated copy of the vzone
71 U_CAPI VZone
* U_EXPORT2
72 vzone_clone(const VZone
*zone
);
75 * Returns true if zone1 is identical to zone2
77 * @param zone1 to be checked for containment
78 * @param zone2 to be checked for containment
79 * @return true if the test condition is met
81 U_CAPI UBool U_EXPORT2
82 vzone_equals(const VZone
* zone1
, const VZone
* zone2
);
85 * Gets the RFC2445 TZURL property value. When a vzone instance was
86 * created from VTIMEZONE data, the initial value is set by the TZURL
87 * property value in the data. Otherwise, the initial value is not set.
88 * @param zone, the vzone to use
89 * @param url Receives the RFC2445 TZURL property value.
90 * @param urlLength, length of the url
91 * @return TRUE if TZURL attribute is available and value is set.
93 U_CAPI UBool U_EXPORT2
94 vzone_getTZURL(VZone
* zone
, UChar
* & url
, int32_t & urlLength
);
97 * Sets the RFC2445 TZURL property value.
98 * @param zone, the vzone to use
99 * @param url The TZURL property value.
100 * @param urlLength, length of the url
102 U_CAPI
void U_EXPORT2
103 vzone_setTZURL(VZone
* zone
, UChar
* url
, int32_t urlLength
);
106 * Gets the RFC2445 LAST-MODIFIED property value. When a vzone instance
107 * was created from VTIMEZONE data, the initial value is set by the
108 * LAST-MODIFIED property value in the data. Otherwise, the initial value
110 * @param zone, the vzone to use
111 * @param lastModified Receives the last modified date.
112 * @return TRUE if lastModified attribute is available and value is set.
114 U_CAPI UBool U_EXPORT2
115 vzone_getLastModified(VZone
* zone
, UDate
& lastModified
);
118 * Sets the RFC2445 LAST-MODIFIED property value.
119 * @param zone, the vzone to use
120 * @param lastModified The LAST-MODIFIED date.
122 U_CAPI
void U_EXPORT2
123 vzone_setLastModified(VZone
* zone
, UDate lastModified
);
126 * Writes RFC2445 VTIMEZONE data for this time zone
127 * @param zone, the vzone to use
128 * @param result Output param to filled in with the VTIMEZONE data.
129 * @param resultLength, length of the result output
130 * @param status Output param to filled in with a success or an error.
132 U_CAPI
void U_EXPORT2
133 vzone_write(VZone
* zone
, UChar
* & result
, int32_t & resultLength
, UErrorCode
& status
);
136 * Writes RFC2445 VTIMEZONE data for this time zone applicalbe
137 * for dates after the specified start time.
138 * @param zone, the vzone to use
139 * @param start The start date.
140 * @param result Output param to filled in with the VTIMEZONE data.
141 * @param resultLength, length of the result output
142 * @param status Output param to filled in with a success or an error.
144 U_CAPI
void U_EXPORT2
145 vzone_writeFromStart(VZone
* zone
, UDate start
, UChar
* & result
, int32_t & resultLength
, UErrorCode
& status
);
148 * Writes RFC2445 VTIMEZONE data applicalbe for the specified date.
149 * Some common iCalendar implementations can only handle a single time
150 * zone property or a pair of standard and daylight time properties using
151 * BYDAY rule with day of week (such as BYDAY=1SUN). This method produce
152 * the VTIMEZONE data which can be handled these implementations. The rules
153 * produced by this method can be used only for calculating time zone offset
154 * around the specified date.
155 * @param zone, the vzone to use
156 * @param time The date used for rule extraction.
157 * @param result Output param to filled in with the VTIMEZONE data.
158 * @param status Output param to filled in with a success or an error.
160 U_CAPI
void U_EXPORT2
161 vzone_writeSimple(VZone
* zone
, UDate time
, UChar
* & result
, int32_t & resultLength
, UErrorCode
& status
);
164 * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
165 * to GMT to get local time in this time zone, taking daylight savings time into
166 * account) as of a particular reference date. The reference date is used to determine
167 * whether daylight savings time is in effect and needs to be figured into the offset
168 * that is returned (in other words, what is the adjusted GMT offset in this time zone
169 * at this particular date and time?). For the time zones produced by createTimeZone(),
170 * the reference data is specified according to the Gregorian calendar, and the date
171 * and time fields are local standard time.
173 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
174 * which returns both the raw and the DST offset for a given time. This method
175 * is retained only for backward compatibility.
177 * @param zone, the vzone to use
178 * @param era The reference date's era
179 * @param year The reference date's year
180 * @param month The reference date's month (0-based; 0 is January)
181 * @param day The reference date's day-in-month (1-based)
182 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
183 * @param millis The reference date's milliseconds in day, local standard time
184 * @param status Output param to filled in with a success or an error.
185 * @return The offset in milliseconds to add to GMT to get local time.
187 U_CAPI
int32_t U_EXPORT2
188 vzone_getOffset(VZone
* zone
, uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
189 uint8_t dayOfWeek
, int32_t millis
, UErrorCode
& status
);
192 * Gets the time zone offset, for current date, modified in case of
193 * daylight savings. This is the offset to add *to* UTC to get local time.
195 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
196 * which returns both the raw and the DST offset for a given time. This method
197 * is retained only for backward compatibility.
199 * @param zone, the vzone to use
200 * @param era The reference date's era
201 * @param year The reference date's year
202 * @param month The reference date's month (0-based; 0 is January)
203 * @param day The reference date's day-in-month (1-based)
204 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
205 * @param millis The reference date's milliseconds in day, local standard time
206 * @param monthLength The length of the given month in days.
207 * @param status Output param to filled in with a success or an error.
208 * @return The offset in milliseconds to add to GMT to get local time.
210 U_CAPI
int32_t U_EXPORT2
211 vzone_getOffset2(VZone
* zone
, uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
212 uint8_t dayOfWeek
, int32_t millis
,
213 int32_t monthLength
, UErrorCode
& status
);
216 * Returns the time zone raw and GMT offset for the given moment
217 * in time. Upon return, local-millis = GMT-millis + rawOffset +
218 * dstOffset. All computations are performed in the proleptic
219 * Gregorian calendar. The default implementation in the TimeZone
220 * class delegates to the 8-argument getOffset().
222 * @param zone, the vzone to use
223 * @param date moment in time for which to return offsets, in
224 * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
225 * time or local wall time, depending on `local'.
226 * @param local if true, `date' is local wall time; otherwise it
228 * @param rawOffset output parameter to receive the raw offset, that
229 * is, the offset not including DST adjustments
230 * @param dstOffset output parameter to receive the DST offset,
231 * that is, the offset to be added to `rawOffset' to obtain the
232 * total offset between local and GMT time. If DST is not in
233 * effect, this value is zero; otherwise it is a positive value,
234 * typically one hour.
235 * @param ec input-output error code
237 U_CAPI
void U_EXPORT2
238 vzone_getOffset3(VZone
* zone
, UDate date
, UBool local
, int32_t& rawOffset
,
239 int32_t& dstOffset
, UErrorCode
& ec
);
242 * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
243 * to GMT to get local time, before taking daylight savings time into account).
245 * @param zone, the vzone to use
246 * @param offsetMillis The new raw GMT offset for this time zone.
248 U_CAPI
void U_EXPORT2
249 vzone_setRawOffset(VZone
* zone
, int32_t offsetMillis
);
252 * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
253 * to GMT to get local time, before taking daylight savings time into account).
255 * @param zone, the vzone to use
256 * @return The TimeZone's raw GMT offset.
258 U_CAPI
int32_t U_EXPORT2
259 vzone_getRawOffset(VZone
* zone
);
262 * Queries if this time zone uses daylight savings time.
263 * @param zone, the vzone to use
264 * @return true if this time zone uses daylight savings time,
267 U_CAPI UBool U_EXPORT2
268 vzone_useDaylightTime(VZone
* zone
);
271 * Queries if the given date is in daylight savings time in
273 * This method is wasteful since it creates a new GregorianCalendar and
274 * deletes it each time it is called. This is a deprecated method
275 * and provided only for Java compatibility.
277 * @param zone, the vzone to use
278 * @param date the given UDate.
279 * @param status Output param filled in with success/error code.
280 * @return true if the given date is in daylight savings time,
283 U_INTERNAL UBool U_EXPORT2
284 vzone_inDaylightTime(VZone
* zone
, UDate date
, UErrorCode
& status
);
287 * Returns true if this zone has the same rule and offset as another zone.
288 * That is, if this zone differs only in ID, if at all.
289 * @param zone, the vzone to use
290 * @param other the <code>TimeZone</code> object to be compared with
291 * @return true if the given zone is the same as this one,
292 * with the possible exception of the ID
294 U_CAPI UBool U_EXPORT2
295 vzone_hasSameRules(VZone
* zone
, const VZone
* other
);
298 * Gets the first time zone transition after the base time.
299 * @param zone, the vzone to use
300 * @param base The base time.
301 * @param inclusive Whether the base time is inclusive or not.
302 * @param result Receives the first transition after the base time.
303 * @return TRUE if the transition is found.
305 U_CAPI UBool U_EXPORT2
306 vzone_getNextTransition(VZone
* zone
, UDate base
, UBool inclusive
, ZTrans
* result
);
309 * Gets the most recent time zone transition before the base time.
310 * @param zone, the vzone to use
311 * @param base The base time.
312 * @param inclusive Whether the base time is inclusive or not.
313 * @param result Receives the most recent transition before the base time.
314 * @return TRUE if the transition is found.
316 U_CAPI UBool U_EXPORT2
317 vzone_getPreviousTransition(VZone
* zone
, UDate base
, UBool inclusive
, ZTrans
* result
);
320 * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
321 * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
322 * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
323 * @param zone, the vzone to use
324 * @param status Receives error status code.
325 * @return The number of <code>TimeZoneRule</code>s representing time transitions.
327 U_CAPI
int32_t U_EXPORT2
328 vzone_countTransitionRules(VZone
* zone
, UErrorCode
& status
);
331 * Return the class ID for this class. This is useful only for comparing to
332 * a return value from getDynamicClassID(). For example:
334 * . Base* polymorphic_pointer = createPolymorphicObject();
335 * . if (polymorphic_pointer->getDynamicClassID() ==
336 * . erived::getStaticClassID()) ...
338 * @param zone, the vzone to use
339 * @return The class ID for all objects of this class.
341 U_CAPI UClassID U_EXPORT2
342 vzone_getStaticClassID(VZone
* zone
);
345 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
346 * method is to implement a simple version of RTTI, since not all C++
347 * compilers support genuine RTTI. Polymorphic operator==() and clone()
348 * methods call this method.
350 * @param zone, the vzone to use
351 * @return The class ID for this object. All objects of a
352 * given class have the same class ID. Objects of
353 * other classes have different class IDs.
355 U_CAPI UClassID U_EXPORT2
356 vzone_getDynamicClassID(VZone
* zone
);