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