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