zrule.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. #ifndef __ZRULE_H
  10. #define __ZRULE_H
  11. /**
  12. * \file
  13. * \brief C API: Time zone rule classes
  14. */
  15. #include "unicode/utypes.h"
  16. #if !UCONFIG_NO_FORMATTING
  17. #include "unicode/uobject.h"
  18. #ifndef UCNV_H
  19. /**
  20. * A TimeZoneRule. Use the zrule_* API to manipulate. Create with
  21. * zrule_open*, and destroy with zrule_close.
  22. */
  23. struct ZRule;
  24. typedef struct ZRule ZRule;
  25. /**
  26. * An InitialTimeZoneRule. Use the izrule_* API to manipulate. Create with
  27. * izrule_open*, and destroy with izrule_close.
  28. */
  29. struct IZRule;
  30. typedef struct IZRule IZRule;
  31. /**
  32. * An AnnualTimeZoneRule. Use the azrule_* API to manipulate. Create with
  33. * azrule_open*, and destroy with azrule_close.
  34. */
  35. struct AZRule;
  36. typedef struct AZRule AZRule;
  37. #endif
  38. /*********************************************************************
  39. * ZRule API
  40. *********************************************************************/
  41. /**
  42. * Disposes of the storage used by a ZRule object. This function should
  43. * be called exactly once for objects returned by zrule_open*.
  44. * @param set the object to dispose of
  45. */
  46. U_CAPI void U_EXPORT2
  47. zrule_close(ZRule* rule);
  48. /**
  49. * Returns true if rule1 is identical to rule2
  50. * and vis versa.
  51. * @param rule1 to be checked for containment
  52. * @param rule2 to be checked for containment
  53. * @return true if the test condition is met
  54. */
  55. U_CAPI UBool U_EXPORT2
  56. zrule_equals(const ZRule* rule1, const ZRule* rule2);
  57. /**
  58. * Fills in "name" with the name of this time zone.
  59. * @param rule, the Zrule to use
  60. * @param name Receives the name of this time zone.
  61. * @param nameLength, length of the returned name
  62. */
  63. U_CAPI void U_EXPORT2
  64. zrule_getName(ZRule* rule, UChar* name, int32_t nameLength);
  65. /**
  66. * Gets the standard time offset.
  67. * @param rule, the Zrule to use
  68. * @return The standard time offset from UTC in milliseconds.
  69. */
  70. U_CAPI int32_t U_EXPORT2
  71. zrule_getRawOffset(ZRule* rule);
  72. /**
  73. * Gets the amount of daylight saving delta time from the standard time.
  74. * @param rule, the Zrule to use
  75. * @return The amount of daylight saving offset used by this rule
  76. * in milliseconds.
  77. */
  78. U_CAPI int32_t U_EXPORT2
  79. zrule_getDSTSavings(ZRule* rule);
  80. /**
  81. * Returns if this rule represents the same rule and offsets as another.
  82. * When two ZRule objects differ only its names, this method
  83. * returns true.
  84. * @param rule1 to be checked for containment
  85. * @param rule2 to be checked for containment
  86. * @return true if the other <code>TimeZoneRule</code> is the same as this one.
  87. */
  88. U_CAPI UBool U_EXPORT2
  89. zrule_isEquivalentTo(ZRule* rule1, ZRule* rule2);
  90. /*********************************************************************
  91. * IZRule API
  92. *********************************************************************/
  93. /**
  94. * Constructs an IZRule with the name, the GMT offset of its
  95. * standard time and the amount of daylight saving offset adjustment.
  96. * @param name The time zone name.
  97. * @param nameLength The length of the time zone name.
  98. * @param rawOffset The UTC offset of its standard time in milliseconds.
  99. * @param dstSavings The amount of daylight saving offset adjustment in milliseconds.
  100. * If this ia a rule for standard time, the value of this argument is 0.
  101. */
  102. U_CAPI IZRule* U_EXPORT2
  103. izrule_open(const UChar* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings);
  104. /**
  105. * Disposes of the storage used by a IZRule object. This function should
  106. * be called exactly once for objects returned by izrule_open*.
  107. * @param set the object to dispose of
  108. */
  109. U_CAPI void U_EXPORT2
  110. izrule_close(IZRule* rule);
  111. /**
  112. * Returns a copy of this object.
  113. * @param rule the original IZRule
  114. * @return the newly allocated copy of the IZRule
  115. */
  116. U_CAPI IZRule* U_EXPORT2
  117. izrule_clone(IZRule *rule);
  118. /**
  119. * Returns true if rule1 is identical to rule2
  120. * and vis versa.
  121. * @param rule1 to be checked for containment
  122. * @param rule2 to be checked for containment
  123. * @return true if the test condition is met
  124. */
  125. U_CAPI UBool U_EXPORT2
  126. izrule_equals(const IZRule* rule1, const IZRule* rule2);
  127. /**
  128. * Fills in "name" with the name of this time zone.
  129. * @param rule, the IZrule to use
  130. * @param name Receives the name of this time zone.
  131. * @param nameLength, length of the returned name
  132. */
  133. U_CAPI void U_EXPORT2
  134. izrule_getName(IZRule* rule, UChar* & name, int32_t & nameLength);
  135. /**
  136. * Gets the standard time offset.
  137. * @param rule, the IZrule to use
  138. * @return The standard time offset from UTC in milliseconds.
  139. */
  140. U_CAPI int32_t U_EXPORT2
  141. izrule_getRawOffset(IZRule* rule);
  142. /**
  143. * Gets the amount of daylight saving delta time from the standard time.
  144. * @param rule, the IZrule to use
  145. * @return The amount of daylight saving offset used by this rule
  146. * in milliseconds.
  147. */
  148. U_CAPI int32_t U_EXPORT2
  149. izrule_getDSTSavings(IZRule* rule);
  150. /**
  151. * Returns if this rule represents the same rule and offsets as another.
  152. * When two IZRule objects differ only its names, this method
  153. * returns true.
  154. * @param rule1 to be checked for containment
  155. * @param rule2 to be checked for containment
  156. * @return true if the other <code>TimeZoneRule</code> is the same as this one.
  157. */
  158. U_CAPI UBool U_EXPORT2
  159. izrule_isEquivalentTo(IZRule* rule1, IZRule* rule2);
  160. /**
  161. * Gets the very first time when this rule takes effect.
  162. * @param rule The IZrule to use
  163. * @param prevRawOffset The standard time offset from UTC before this rule
  164. * takes effect in milliseconds.
  165. * @param prevDSTSavings The amount of daylight saving offset from the
  166. * standard time.
  167. * @param result Receives the very first time when this rule takes effect.
  168. * @return true if the start time is available. When false is returned, output parameter
  169. * "result" is unchanged.
  170. */
  171. U_CAPI UBool U_EXPORT2
  172. izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
  173. UDate& result);
  174. /**
  175. * Gets the final time when this rule takes effect.
  176. * @param rule The IZrule to use
  177. * @param prevRawOffset The standard time offset from UTC before this rule
  178. * takes effect in milliseconds.
  179. * @param prevDSTSavings The amount of daylight saving offset from the
  180. * standard time.
  181. * @param result Receives the final time when this rule takes effect.
  182. * @return true if the start time is available. When false is returned, output parameter
  183. * "result" is unchanged.
  184. */
  185. U_CAPI UBool U_EXPORT2
  186. izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
  187. UDate& result);
  188. /**
  189. * Gets the first time when this rule takes effect after the specified time.
  190. * @param rule The IZrule to use
  191. * @param base The first start time after this base time will be returned.
  192. * @param prevRawOffset The standard time offset from UTC before this rule
  193. * takes effect in milliseconds.
  194. * @param prevDSTSavings The amount of daylight saving offset from the
  195. * standard time.
  196. * @param inclusive Whether the base time is inclusive or not.
  197. * @param result Receives The first time when this rule takes effect after
  198. * the specified base time.
  199. * @return true if the start time is available. When false is returned, output parameter
  200. * "result" is unchanged.
  201. */
  202. U_CAPI UBool U_EXPORT2
  203. izrule_getNextStart(IZRule* rule, UDate base, int32_t prevRawOffset,
  204. int32_t prevDSTSavings, UBool inclusive, UDate& result);
  205. /**
  206. * Gets the most recent time when this rule takes effect before the specified time.
  207. * @param rule The IZrule to use
  208. * @param base The most recent time before this base time will be returned.
  209. * @param prevRawOffset The standard time offset from UTC before this rule
  210. * takes effect in milliseconds.
  211. * @param prevDSTSavings The amount of daylight saving offset from the
  212. * standard time.
  213. * @param inclusive Whether the base time is inclusive or not.
  214. * @param result Receives The most recent time when this rule takes effect before
  215. * the specified base time.
  216. * @return true if the start time is available. When false is returned, output parameter
  217. * "result" is unchanged.
  218. */
  219. U_CAPI UBool U_EXPORT2
  220. izrule_getPreviousStart(IZRule* rule, UDate base, int32_t prevRawOffset,
  221. int32_t prevDSTSavings, UBool inclusive, UDate& result);
  222. /**
  223. * Return the class ID for this class. This is useful only for comparing to
  224. * a return value from getDynamicClassID(). For example:
  225. * <pre>
  226. * . Base* polymorphic_pointer = createPolymorphicObject();
  227. * . if (polymorphic_pointer->getDynamicClassID() ==
  228. * . erived::getStaticClassID()) ...
  229. * </pre>
  230. * @param rule The IZrule to use
  231. * @return The class ID for all objects of this class.
  232. */
  233. U_CAPI UClassID U_EXPORT2
  234. izrule_getStaticClassID(IZRule* rule);
  235. /**
  236. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  237. * method is to implement a simple version of RTTI, since not all C++
  238. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  239. * methods call this method.
  240. *
  241. * @param rule The IZrule to use
  242. * @return The class ID for this object. All objects of a
  243. * given class have the same class ID. Objects of
  244. * other classes have different class IDs.
  245. */
  246. U_CAPI UClassID U_EXPORT2
  247. izrule_getDynamicClassID(IZRule* rule);
  248. #endif
  249. #endif