vzone.h 14 KB

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