vzone.h 14 KB

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