tzrule.h 35 KB

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