tzrule.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. // Copyright (C) 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. * Copyright (C) 2007-2008, International Business Machines Corporation and *
  6. * others. All Rights Reserved. *
  7. *******************************************************************************
  8. */
  9. #ifndef TZRULE_H
  10. #define TZRULE_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. #include "unicode/unistr.h"
  19. #include "unicode/dtrule.h"
  20. U_NAMESPACE_BEGIN
  21. /**
  22. * <code>TimeZoneRule</code> is a class representing a rule for time zone.
  23. * <code>TimeZoneRule</code> has a set of time zone attributes, such as zone name,
  24. * raw offset (UTC offset for standard time) and daylight saving time offset.
  25. *
  26. * @stable ICU 3.8
  27. */
  28. class U_I18N_API TimeZoneRule : public UObject {
  29. public:
  30. /**
  31. * Destructor.
  32. * @stable ICU 3.8
  33. */
  34. virtual ~TimeZoneRule();
  35. /**
  36. * Clone this TimeZoneRule object polymorphically. The caller owns the result and
  37. * should delete it when done.
  38. * @return A copy of the object.
  39. * @stable ICU 3.8
  40. */
  41. virtual TimeZoneRule* clone(void) const = 0;
  42. /**
  43. * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
  44. * of different subclasses are considered unequal.
  45. * @param that The object to be compared with.
  46. * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
  47. * @stable ICU 3.8
  48. */
  49. virtual UBool operator==(const TimeZoneRule& that) const;
  50. /**
  51. * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
  52. * of different subclasses are considered unequal.
  53. * @param that The object to be compared with.
  54. * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
  55. * @stable ICU 3.8
  56. */
  57. virtual UBool operator!=(const TimeZoneRule& that) const;
  58. /**
  59. * Fills in "name" with the name of this time zone.
  60. * @param name Receives the name of this time zone.
  61. * @return A reference to "name"
  62. * @stable ICU 3.8
  63. */
  64. UnicodeString& getName(UnicodeString& name) const;
  65. /**
  66. * Gets the standard time offset.
  67. * @return The standard time offset from UTC in milliseconds.
  68. * @stable ICU 3.8
  69. */
  70. int32_t getRawOffset(void) const;
  71. /**
  72. * Gets the amount of daylight saving delta time from the standard time.
  73. * @return The amount of daylight saving offset used by this rule
  74. * in milliseconds.
  75. * @stable ICU 3.8
  76. */
  77. int32_t getDSTSavings(void) const;
  78. /**
  79. * Returns if this rule represents the same rule and offsets as another.
  80. * When two <code>TimeZoneRule</code> objects differ only its names, this method
  81. * returns true.
  82. * @param other The <code>TimeZoneRule</code> object to be compared with.
  83. * @return true if the other <code>TimeZoneRule</code> is the same as this one.
  84. * @stable ICU 3.8
  85. */
  86. virtual UBool isEquivalentTo(const TimeZoneRule& other) const;
  87. /**
  88. * Gets the very first time when this rule takes effect.
  89. * @param prevRawOffset The standard time offset from UTC before this rule
  90. * takes effect in milliseconds.
  91. * @param prevDSTSavings The amount of daylight saving offset from the
  92. * standard time.
  93. * @param result Receives the very first time when this rule takes effect.
  94. * @return true if the start time is available. When false is returned, output parameter
  95. * "result" is unchanged.
  96. * @stable ICU 3.8
  97. */
  98. virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const = 0;
  99. /**
  100. * Gets the final time when this rule takes effect.
  101. * @param prevRawOffset The standard time offset from UTC before this rule
  102. * takes effect in milliseconds.
  103. * @param prevDSTSavings The amount of daylight saving offset from the
  104. * standard time.
  105. * @param result Receives the final time when this rule takes effect.
  106. * @return true if the start time is available. When false is returned, output parameter
  107. * "result" is unchanged.
  108. * @stable ICU 3.8
  109. */
  110. virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const = 0;
  111. /**
  112. * Gets the first time when this rule takes effect after the specified time.
  113. * @param base The first start time after this base time will be returned.
  114. * @param prevRawOffset The standard time offset from UTC before this rule
  115. * takes effect in milliseconds.
  116. * @param prevDSTSavings The amount of daylight saving offset from the
  117. * standard time.
  118. * @param inclusive Whether the base time is inclusive or not.
  119. * @param result Receives The first time when this rule takes effect after
  120. * the specified base time.
  121. * @return true if the start time is available. When false is returned, output parameter
  122. * "result" is unchanged.
  123. * @stable ICU 3.8
  124. */
  125. virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  126. UBool inclusive, UDate& result) const = 0;
  127. /**
  128. * Gets the most recent time when this rule takes effect before the specified time.
  129. * @param base The most recent time before this base time will be returned.
  130. * @param prevRawOffset The standard time offset from UTC before this rule
  131. * takes effect in milliseconds.
  132. * @param prevDSTSavings The amount of daylight saving offset from the
  133. * standard time.
  134. * @param inclusive Whether the base time is inclusive or not.
  135. * @param result Receives The most recent time when this rule takes effect before
  136. * the specified base time.
  137. * @return true if the start time is available. When false is returned, output parameter
  138. * "result" is unchanged.
  139. * @stable ICU 3.8
  140. */
  141. virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  142. UBool inclusive, UDate& result) const = 0;
  143. protected:
  144. /**
  145. * Constructs a <code>TimeZoneRule</code> with the name, the GMT offset of its
  146. * standard time and the amount of daylight saving offset adjustment.
  147. * @param name The time zone name.
  148. * @param rawOffset The UTC offset of its standard time in milliseconds.
  149. * @param dstSavings The amount of daylight saving offset adjustment in milliseconds.
  150. * If this ia a rule for standard time, the value of this argument is 0.
  151. * @stable ICU 3.8
  152. */
  153. TimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings);
  154. /**
  155. * Copy constructor.
  156. * @param source The TimeZoneRule object to be copied.
  157. * @stable ICU 3.8
  158. */
  159. TimeZoneRule(const TimeZoneRule& source);
  160. /**
  161. * Assignment operator.
  162. * @param right The object to be copied.
  163. * @stable ICU 3.8
  164. */
  165. TimeZoneRule& operator=(const TimeZoneRule& right);
  166. private:
  167. UnicodeString fName; // time name
  168. int32_t fRawOffset; // UTC offset of the standard time in milliseconds
  169. int32_t fDSTSavings; // DST saving amount in milliseconds
  170. };
  171. /**
  172. * <code>InitialTimeZoneRule</code> represents a time zone rule
  173. * representing a time zone effective from the beginning and
  174. * has no actual start times.
  175. * @stable ICU 3.8
  176. */
  177. class U_I18N_API InitialTimeZoneRule : public TimeZoneRule {
  178. public:
  179. /**
  180. * Constructs an <code>InitialTimeZoneRule</code> with the name, the GMT offset of its
  181. * standard time and the amount of daylight saving offset adjustment.
  182. * @param name The time zone name.
  183. * @param rawOffset The UTC offset of its standard time in milliseconds.
  184. * @param dstSavings The amount of daylight saving offset adjustment in milliseconds.
  185. * If this ia a rule for standard time, the value of this argument is 0.
  186. * @stable ICU 3.8
  187. */
  188. InitialTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings);
  189. /**
  190. * Copy constructor.
  191. * @param source The InitialTimeZoneRule object to be copied.
  192. * @stable ICU 3.8
  193. */
  194. InitialTimeZoneRule(const InitialTimeZoneRule& source);
  195. /**
  196. * Destructor.
  197. * @stable ICU 3.8
  198. */
  199. virtual ~InitialTimeZoneRule();
  200. /**
  201. * Clone this InitialTimeZoneRule object polymorphically. The caller owns the result and
  202. * should delete it when done.
  203. * @return A copy of the object.
  204. * @stable ICU 3.8
  205. */
  206. virtual InitialTimeZoneRule* clone(void) const;
  207. /**
  208. * Assignment operator.
  209. * @param right The object to be copied.
  210. * @stable ICU 3.8
  211. */
  212. InitialTimeZoneRule& operator=(const InitialTimeZoneRule& right);
  213. /**
  214. * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
  215. * of different subclasses are considered unequal.
  216. * @param that The object to be compared with.
  217. * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
  218. * @stable ICU 3.8
  219. */
  220. virtual UBool operator==(const TimeZoneRule& that) const;
  221. /**
  222. * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
  223. * of different subclasses are considered unequal.
  224. * @param that The object to be compared with.
  225. * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
  226. * @stable ICU 3.8
  227. */
  228. virtual UBool operator!=(const TimeZoneRule& that) const;
  229. /**
  230. * Gets the time when this rule takes effect in the given year.
  231. * @param year The Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
  232. * @param prevRawOffset The standard time offset from UTC before this rule
  233. * takes effect in milliseconds.
  234. * @param prevDSTSavings The amount of daylight saving offset from the
  235. * standard time.
  236. * @param result Receives the start time in the year.
  237. * @return true if this rule takes effect in the year and the result is set to
  238. * "result".
  239. * @stable ICU 3.8
  240. */
  241. UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  242. /**
  243. * Returns if this rule represents the same rule and offsets as another.
  244. * When two <code>TimeZoneRule</code> objects differ only its names, this method
  245. * returns true.
  246. * @param that The <code>TimeZoneRule</code> object to be compared with.
  247. * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
  248. * @stable ICU 3.8
  249. */
  250. virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
  251. /**
  252. * Gets the very first time when this rule takes effect.
  253. * @param prevRawOffset The standard time offset from UTC before this rule
  254. * takes effect in milliseconds.
  255. * @param prevDSTSavings The amount of daylight saving offset from the
  256. * standard time.
  257. * @param result Receives the very first time when this rule takes effect.
  258. * @return true if the start time is available. When false is returned, output parameter
  259. * "result" is unchanged.
  260. * @stable ICU 3.8
  261. */
  262. virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  263. /**
  264. * Gets the final time when this rule takes effect.
  265. * @param prevRawOffset The standard time offset from UTC before this rule
  266. * takes effect in milliseconds.
  267. * @param prevDSTSavings The amount of daylight saving offset from the
  268. * standard time.
  269. * @param result Receives the final time when this rule takes effect.
  270. * @return true if the start time is available. When false is returned, output parameter
  271. * "result" is unchanged.
  272. * @stable ICU 3.8
  273. */
  274. virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  275. /**
  276. * Gets the first time when this rule takes effect after the specified time.
  277. * @param base The first start time after this base time will be returned.
  278. * @param prevRawOffset The standard time offset from UTC before this rule
  279. * takes effect in milliseconds.
  280. * @param prevDSTSavings The amount of daylight saving offset from the
  281. * standard time.
  282. * @param inclusive Whether the base time is inclusive or not.
  283. * @param result Receives The first time when this rule takes effect after
  284. * the specified base time.
  285. * @return true if the start time is available. When false is returned, output parameter
  286. * "result" is unchanged.
  287. * @stable ICU 3.8
  288. */
  289. virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  290. UBool inclusive, UDate& result) const;
  291. /**
  292. * Gets the most recent time when this rule takes effect before the specified time.
  293. * @param base The most recent time before this base time will be returned.
  294. * @param prevRawOffset The standard time offset from UTC before this rule
  295. * takes effect in milliseconds.
  296. * @param prevDSTSavings The amount of daylight saving offset from the
  297. * standard time.
  298. * @param inclusive Whether the base time is inclusive or not.
  299. * @param result Receives The most recent time when this rule takes effect before
  300. * the specified base time.
  301. * @return true if the start time is available. When false is returned, output parameter
  302. * "result" is unchanged.
  303. * @stable ICU 3.8
  304. */
  305. virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  306. UBool inclusive, UDate& result) const;
  307. public:
  308. /**
  309. * Return the class ID for this class. This is useful only for comparing to
  310. * a return value from getDynamicClassID(). For example:
  311. * <pre>
  312. * . Base* polymorphic_pointer = createPolymorphicObject();
  313. * . if (polymorphic_pointer->getDynamicClassID() ==
  314. * . erived::getStaticClassID()) ...
  315. * </pre>
  316. * @return The class ID for all objects of this class.
  317. * @stable ICU 3.8
  318. */
  319. static UClassID U_EXPORT2 getStaticClassID(void);
  320. /**
  321. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  322. * method is to implement a simple version of RTTI, since not all C++
  323. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  324. * methods call this method.
  325. *
  326. * @return The class ID for this object. All objects of a
  327. * given class have the same class ID. Objects of
  328. * other classes have different class IDs.
  329. * @stable ICU 3.8
  330. */
  331. virtual UClassID getDynamicClassID(void) const;
  332. };
  333. /**
  334. * <code>AnnualTimeZoneRule</code> is a class used for representing a time zone
  335. * rule which takes effect annually. The calenday system used for the rule is
  336. * is based on Gregorian calendar
  337. *
  338. * @stable ICU 3.8
  339. */
  340. class U_I18N_API AnnualTimeZoneRule : public TimeZoneRule {
  341. public:
  342. /**
  343. * The constant representing the maximum year used for designating
  344. * a rule is permanent.
  345. */
  346. static const int32_t MAX_YEAR;
  347. /**
  348. * Constructs a <code>AnnualTimeZoneRule</code> with the name, the GMT offset of its
  349. * standard time, the amount of daylight saving offset adjustment, the annual start
  350. * time rule and the start/until years. The input DateTimeRule is copied by this
  351. * constructor, so the caller remains responsible for deleting the object.
  352. * @param name The time zone name.
  353. * @param rawOffset The GMT offset of its standard time in milliseconds.
  354. * @param dstSavings The amount of daylight saving offset adjustment in
  355. * milliseconds. If this ia a rule for standard time,
  356. * the value of this argument is 0.
  357. * @param dateTimeRule The start date/time rule repeated annually.
  358. * @param startYear The first year when this rule takes effect.
  359. * @param endYear The last year when this rule takes effect. If this
  360. * rule is effective forever in future, specify MAX_YEAR.
  361. * @stable ICU 3.8
  362. */
  363. AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
  364. const DateTimeRule& dateTimeRule, int32_t startYear, int32_t endYear);
  365. /**
  366. * Constructs a <code>AnnualTimeZoneRule</code> with the name, the GMT offset of its
  367. * standard time, the amount of daylight saving offset adjustment, the annual start
  368. * time rule and the start/until years. The input DateTimeRule object is adopted
  369. * by this object, therefore, the caller must not delete the object.
  370. * @param name The time zone name.
  371. * @param rawOffset The GMT offset of its standard time in milliseconds.
  372. * @param dstSavings The amount of daylight saving offset adjustment in
  373. * milliseconds. If this ia a rule for standard time,
  374. * the value of this argument is 0.
  375. * @param dateTimeRule The start date/time rule repeated annually.
  376. * @param startYear The first year when this rule takes effect.
  377. * @param endYear The last year when this rule takes effect. If this
  378. * rule is effective forever in future, specify MAX_YEAR.
  379. * @stable ICU 3.8
  380. */
  381. AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
  382. DateTimeRule* dateTimeRule, int32_t startYear, int32_t endYear);
  383. /**
  384. * Copy constructor.
  385. * @param source The AnnualTimeZoneRule object to be copied.
  386. * @stable ICU 3.8
  387. */
  388. AnnualTimeZoneRule(const AnnualTimeZoneRule& source);
  389. /**
  390. * Destructor.
  391. * @stable ICU 3.8
  392. */
  393. virtual ~AnnualTimeZoneRule();
  394. /**
  395. * Clone this AnnualTimeZoneRule object polymorphically. The caller owns the result and
  396. * should delete it when done.
  397. * @return A copy of the object.
  398. * @stable ICU 3.8
  399. */
  400. virtual AnnualTimeZoneRule* clone(void) const;
  401. /**
  402. * Assignment operator.
  403. * @param right The object to be copied.
  404. * @stable ICU 3.8
  405. */
  406. AnnualTimeZoneRule& operator=(const AnnualTimeZoneRule& right);
  407. /**
  408. * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
  409. * of different subclasses are considered unequal.
  410. * @param that The object to be compared with.
  411. * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
  412. * @stable ICU 3.8
  413. */
  414. virtual UBool operator==(const TimeZoneRule& that) const;
  415. /**
  416. * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
  417. * of different subclasses are considered unequal.
  418. * @param that The object to be compared with.
  419. * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
  420. * @stable ICU 3.8
  421. */
  422. virtual UBool operator!=(const TimeZoneRule& that) const;
  423. /**
  424. * Gets the start date/time rule used by this rule.
  425. * @return The <code>AnnualDateTimeRule</code> which represents the start date/time
  426. * rule used by this time zone rule.
  427. * @stable ICU 3.8
  428. */
  429. const DateTimeRule* getRule(void) const;
  430. /**
  431. * Gets the first year when this rule takes effect.
  432. * @return The start year of this rule. The year is in Gregorian calendar
  433. * with 0 == 1 BCE, -1 == 2 BCE, etc.
  434. * @stable ICU 3.8
  435. */
  436. int32_t getStartYear(void) const;
  437. /**
  438. * Gets the end year when this rule takes effect.
  439. * @return The end year of this rule (inclusive). The year is in Gregorian calendar
  440. * with 0 == 1 BCE, -1 == 2 BCE, etc.
  441. * @stable ICU 3.8
  442. */
  443. int32_t getEndYear(void) const;
  444. /**
  445. * Gets the time when this rule takes effect in the given year.
  446. * @param year The Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
  447. * @param prevRawOffset The standard time offset from UTC before this rule
  448. * takes effect in milliseconds.
  449. * @param prevDSTSavings The amount of daylight saving offset from the
  450. * standard time.
  451. * @param result Receives the start time in the year.
  452. * @return true if this rule takes effect in the year and the result is set to
  453. * "result".
  454. * @stable ICU 3.8
  455. */
  456. UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  457. /**
  458. * Returns if this rule represents the same rule and offsets as another.
  459. * When two <code>TimeZoneRule</code> objects differ only its names, this method
  460. * returns true.
  461. * @param that The <code>TimeZoneRule</code> object to be compared with.
  462. * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
  463. * @stable ICU 3.8
  464. */
  465. virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
  466. /**
  467. * Gets the very first time when this rule takes effect.
  468. * @param prevRawOffset The standard time offset from UTC before this rule
  469. * takes effect in milliseconds.
  470. * @param prevDSTSavings The amount of daylight saving offset from the
  471. * standard time.
  472. * @param result Receives the very first time when this rule takes effect.
  473. * @return true if the start time is available. When false is returned, output parameter
  474. * "result" is unchanged.
  475. * @stable ICU 3.8
  476. */
  477. virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  478. /**
  479. * Gets the final time when this rule takes effect.
  480. * @param prevRawOffset The standard time offset from UTC before this rule
  481. * takes effect in milliseconds.
  482. * @param prevDSTSavings The amount of daylight saving offset from the
  483. * standard time.
  484. * @param result Receives the final time when this rule takes effect.
  485. * @return true if the start time is available. When false is returned, output parameter
  486. * "result" is unchanged.
  487. * @stable ICU 3.8
  488. */
  489. virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  490. /**
  491. * Gets the first time when this rule takes effect after the specified time.
  492. * @param base The first start time after this base time will be returned.
  493. * @param prevRawOffset The standard time offset from UTC before this rule
  494. * takes effect in milliseconds.
  495. * @param prevDSTSavings The amount of daylight saving offset from the
  496. * standard time.
  497. * @param inclusive Whether the base time is inclusive or not.
  498. * @param result Receives The first time when this rule takes effect after
  499. * the specified base time.
  500. * @return true if the start time is available. When false is returned, output parameter
  501. * "result" is unchanged.
  502. * @stable ICU 3.8
  503. */
  504. virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  505. UBool inclusive, UDate& result) const;
  506. /**
  507. * Gets the most recent time when this rule takes effect before the specified time.
  508. * @param base The most recent time before this base time will be returned.
  509. * @param prevRawOffset The standard time offset from UTC before this rule
  510. * takes effect in milliseconds.
  511. * @param prevDSTSavings The amount of daylight saving offset from the
  512. * standard time.
  513. * @param inclusive Whether the base time is inclusive or not.
  514. * @param result Receives The most recent time when this rule takes effect before
  515. * the specified base time.
  516. * @return true if the start time is available. When false is returned, output parameter
  517. * "result" is unchanged.
  518. * @stable ICU 3.8
  519. */
  520. virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  521. UBool inclusive, UDate& result) const;
  522. private:
  523. DateTimeRule* fDateTimeRule;
  524. int32_t fStartYear;
  525. int32_t fEndYear;
  526. public:
  527. /**
  528. * Return the class ID for this class. This is useful only for comparing to
  529. * a return value from getDynamicClassID(). For example:
  530. * <pre>
  531. * . Base* polymorphic_pointer = createPolymorphicObject();
  532. * . if (polymorphic_pointer->getDynamicClassID() ==
  533. * . erived::getStaticClassID()) ...
  534. * </pre>
  535. * @return The class ID for all objects of this class.
  536. * @stable ICU 3.8
  537. */
  538. static UClassID U_EXPORT2 getStaticClassID(void);
  539. /**
  540. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  541. * method is to implement a simple version of RTTI, since not all C++
  542. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  543. * methods call this method.
  544. *
  545. * @return The class ID for this object. All objects of a
  546. * given class have the same class ID. Objects of
  547. * other classes have different class IDs.
  548. * @stable ICU 3.8
  549. */
  550. virtual UClassID getDynamicClassID(void) const;
  551. };
  552. /**
  553. * <code>TimeArrayTimeZoneRule</code> represents a time zone rule whose start times are
  554. * defined by an array of milliseconds since the standard base time.
  555. *
  556. * @stable ICU 3.8
  557. */
  558. class U_I18N_API TimeArrayTimeZoneRule : public TimeZoneRule {
  559. public:
  560. /**
  561. * Constructs a <code>TimeArrayTimeZoneRule</code> with the name, the GMT offset of its
  562. * standard time, the amount of daylight saving offset adjustment and
  563. * the array of times when this rule takes effect.
  564. * @param name The time zone name.
  565. * @param rawOffset The UTC offset of its standard time in milliseconds.
  566. * @param dstSavings The amount of daylight saving offset adjustment in
  567. * milliseconds. If this ia a rule for standard time,
  568. * the value of this argument is 0.
  569. * @param startTimes The array start times in milliseconds since the base time
  570. * (January 1, 1970, 00:00:00).
  571. * @param numStartTimes The number of elements in the parameter "startTimes"
  572. * @param timeRuleType The time type of the start times, which is one of
  573. * <code>DataTimeRule::WALL_TIME</code>, <code>STANDARD_TIME</code>
  574. * and <code>UTC_TIME</code>.
  575. * @stable ICU 3.8
  576. */
  577. TimeArrayTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
  578. const UDate* startTimes, int32_t numStartTimes, DateTimeRule::TimeRuleType timeRuleType);
  579. /**
  580. * Copy constructor.
  581. * @param source The TimeArrayTimeZoneRule object to be copied.
  582. * @stable ICU 3.8
  583. */
  584. TimeArrayTimeZoneRule(const TimeArrayTimeZoneRule& source);
  585. /**
  586. * Destructor.
  587. * @stable ICU 3.8
  588. */
  589. virtual ~TimeArrayTimeZoneRule();
  590. /**
  591. * Clone this TimeArrayTimeZoneRule object polymorphically. The caller owns the result and
  592. * should delete it when done.
  593. * @return A copy of the object.
  594. * @stable ICU 3.8
  595. */
  596. virtual TimeArrayTimeZoneRule* clone(void) const;
  597. /**
  598. * Assignment operator.
  599. * @param right The object to be copied.
  600. * @stable ICU 3.8
  601. */
  602. TimeArrayTimeZoneRule& operator=(const TimeArrayTimeZoneRule& right);
  603. /**
  604. * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
  605. * of different subclasses are considered unequal.
  606. * @param that The object to be compared with.
  607. * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
  608. * @stable ICU 3.8
  609. */
  610. virtual UBool operator==(const TimeZoneRule& that) const;
  611. /**
  612. * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
  613. * of different subclasses are considered unequal.
  614. * @param that The object to be compared with.
  615. * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
  616. * @stable ICU 3.8
  617. */
  618. virtual UBool operator!=(const TimeZoneRule& that) const;
  619. /**
  620. * Gets the time type of the start times used by this rule. The return value
  621. * is either <code>DateTimeRule::WALL_TIME</code> or <code>STANDARD_TIME</code>
  622. * or <code>UTC_TIME</code>.
  623. *
  624. * @return The time type used of the start times used by this rule.
  625. * @stable ICU 3.8
  626. */
  627. DateTimeRule::TimeRuleType getTimeType(void) const;
  628. /**
  629. * Gets a start time at the index stored in this rule.
  630. * @param index The index of start times
  631. * @param result Receives the start time at the index
  632. * @return true if the index is within the valid range and
  633. * and the result is set. When false, the output
  634. * parameger "result" is unchanged.
  635. * @stable ICU 3.8
  636. */
  637. UBool getStartTimeAt(int32_t index, UDate& result) const;
  638. /**
  639. * Returns the number of start times stored in this rule
  640. * @return The number of start times.
  641. * @stable ICU 3.8
  642. */
  643. int32_t countStartTimes(void) const;
  644. /**
  645. * Returns if this rule represents the same rule and offsets as another.
  646. * When two <code>TimeZoneRule</code> objects differ only its names, this method
  647. * returns true.
  648. * @param that The <code>TimeZoneRule</code> object to be compared with.
  649. * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
  650. * @stable ICU 3.8
  651. */
  652. virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
  653. /**
  654. * Gets the very first time when this rule takes effect.
  655. * @param prevRawOffset The standard time offset from UTC before this rule
  656. * takes effect in milliseconds.
  657. * @param prevDSTSavings The amount of daylight saving offset from the
  658. * standard time.
  659. * @param result Receives the very first time when this rule takes effect.
  660. * @return true if the start time is available. When false is returned, output parameter
  661. * "result" is unchanged.
  662. * @stable ICU 3.8
  663. */
  664. virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  665. /**
  666. * Gets the final time when this rule takes effect.
  667. * @param prevRawOffset The standard time offset from UTC before this rule
  668. * takes effect in milliseconds.
  669. * @param prevDSTSavings The amount of daylight saving offset from the
  670. * standard time.
  671. * @param result Receives the final time when this rule takes effect.
  672. * @return true if the start time is available. When false is returned, output parameter
  673. * "result" is unchanged.
  674. * @stable ICU 3.8
  675. */
  676. virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  677. /**
  678. * Gets the first time when this rule takes effect after the specified time.
  679. * @param base The first start time after this base time will be returned.
  680. * @param prevRawOffset The standard time offset from UTC before this rule
  681. * takes effect in milliseconds.
  682. * @param prevDSTSavings The amount of daylight saving offset from the
  683. * standard time.
  684. * @param inclusive Whether the base time is inclusive or not.
  685. * @param result Receives The first time when this rule takes effect after
  686. * the specified base time.
  687. * @return true if the start time is available. When false is returned, output parameter
  688. * "result" is unchanged.
  689. * @stable ICU 3.8
  690. */
  691. virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  692. UBool inclusive, UDate& result) const;
  693. /**
  694. * Gets the most recent time when this rule takes effect before the specified time.
  695. * @param base The most recent time before this base time will be returned.
  696. * @param prevRawOffset The standard time offset from UTC before this rule
  697. * takes effect in milliseconds.
  698. * @param prevDSTSavings The amount of daylight saving offset from the
  699. * standard time.
  700. * @param inclusive Whether the base time is inclusive or not.
  701. * @param result Receives The most recent time when this rule takes effect before
  702. * the specified base time.
  703. * @return true if the start time is available. When false is returned, output parameter
  704. * "result" is unchanged.
  705. * @stable ICU 3.8
  706. */
  707. virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  708. UBool inclusive, UDate& result) const;
  709. private:
  710. enum { TIMEARRAY_STACK_BUFFER_SIZE = 32 };
  711. UBool initStartTimes(const UDate source[], int32_t size, UErrorCode& ec);
  712. UDate getUTC(UDate time, int32_t raw, int32_t dst) const;
  713. DateTimeRule::TimeRuleType fTimeRuleType;
  714. int32_t fNumStartTimes;
  715. UDate* fStartTimes;
  716. UDate fLocalStartTimes[TIMEARRAY_STACK_BUFFER_SIZE];
  717. public:
  718. /**
  719. * Return the class ID for this class. This is useful only for comparing to
  720. * a return value from getDynamicClassID(). For example:
  721. * <pre>
  722. * . Base* polymorphic_pointer = createPolymorphicObject();
  723. * . if (polymorphic_pointer->getDynamicClassID() ==
  724. * . erived::getStaticClassID()) ...
  725. * </pre>
  726. * @return The class ID for all objects of this class.
  727. * @stable ICU 3.8
  728. */
  729. static UClassID U_EXPORT2 getStaticClassID(void);
  730. /**
  731. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  732. * method is to implement a simple version of RTTI, since not all C++
  733. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  734. * methods call this method.
  735. *
  736. * @return The class ID for this object. All objects of a
  737. * given class have the same class ID. Objects of
  738. * other classes have different class IDs.
  739. * @stable ICU 3.8
  740. */
  741. virtual UClassID getDynamicClassID(void) const;
  742. };
  743. U_NAMESPACE_END
  744. #endif /* #if !UCONFIG_NO_FORMATTING */
  745. #endif // TZRULE_H
  746. //eof