tzrule.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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 UBool 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 UBool 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(void) 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(void) 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;
  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 UBool operator==(const TimeZoneRule& that) const;
  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 UBool operator!=(const TimeZoneRule& that) const;
  230. /**
  231. * Gets the time when this rule takes effect in the given year.
  232. * @param year The Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
  233. * @param prevRawOffset The standard time offset from UTC before this rule
  234. * takes effect in milliseconds.
  235. * @param prevDSTSavings The amount of daylight saving offset from the
  236. * standard time.
  237. * @param result Receives the start time in the year.
  238. * @return true if this rule takes effect in the year and the result is set to
  239. * "result".
  240. * @stable ICU 3.8
  241. */
  242. UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  243. /**
  244. * Returns if this rule represents the same rule and offsets as another.
  245. * When two <code>TimeZoneRule</code> objects differ only its names, this method
  246. * returns true.
  247. * @param that The <code>TimeZoneRule</code> object to be compared with.
  248. * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
  249. * @stable ICU 3.8
  250. */
  251. virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
  252. /**
  253. * Gets the very first time when this rule takes effect.
  254. * @param prevRawOffset The standard time offset from UTC before this rule
  255. * takes effect in milliseconds.
  256. * @param prevDSTSavings The amount of daylight saving offset from the
  257. * standard time.
  258. * @param result Receives the very first time when this rule takes effect.
  259. * @return true if the start time is available. When false is returned, output parameter
  260. * "result" is unchanged.
  261. * @stable ICU 3.8
  262. */
  263. virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  264. /**
  265. * Gets the final time when this rule takes effect.
  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 result Receives the final time when this rule takes effect.
  271. * @return true if the start time is available. When false is returned, output parameter
  272. * "result" is unchanged.
  273. * @stable ICU 3.8
  274. */
  275. virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  276. /**
  277. * Gets the first time when this rule takes effect after the specified time.
  278. * @param base The first start time after this base time will be returned.
  279. * @param prevRawOffset The standard time offset from UTC before this rule
  280. * takes effect in milliseconds.
  281. * @param prevDSTSavings The amount of daylight saving offset from the
  282. * standard time.
  283. * @param inclusive Whether the base time is inclusive or not.
  284. * @param result Receives The first time when this rule takes effect after
  285. * the specified base time.
  286. * @return true if the start time is available. When false is returned, output parameter
  287. * "result" is unchanged.
  288. * @stable ICU 3.8
  289. */
  290. virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  291. UBool inclusive, UDate& result) const;
  292. /**
  293. * Gets the most recent time when this rule takes effect before the specified time.
  294. * @param base The most recent time before this base time will be returned.
  295. * @param prevRawOffset The standard time offset from UTC before this rule
  296. * takes effect in milliseconds.
  297. * @param prevDSTSavings The amount of daylight saving offset from the
  298. * standard time.
  299. * @param inclusive Whether the base time is inclusive or not.
  300. * @param result Receives The most recent time when this rule takes effect before
  301. * the specified base time.
  302. * @return true if the start time is available. When false is returned, output parameter
  303. * "result" is unchanged.
  304. * @stable ICU 3.8
  305. */
  306. virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  307. UBool inclusive, UDate& result) const;
  308. public:
  309. /**
  310. * Return the class ID for this class. This is useful only for comparing to
  311. * a return value from getDynamicClassID(). For example:
  312. * <pre>
  313. * . Base* polymorphic_pointer = createPolymorphicObject();
  314. * . if (polymorphic_pointer->getDynamicClassID() ==
  315. * . erived::getStaticClassID()) ...
  316. * </pre>
  317. * @return The class ID for all objects of this class.
  318. * @stable ICU 3.8
  319. */
  320. static UClassID U_EXPORT2 getStaticClassID(void);
  321. /**
  322. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  323. * method is to implement a simple version of RTTI, since not all C++
  324. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  325. * methods call this method.
  326. *
  327. * @return The class ID for this object. All objects of a
  328. * given class have the same class ID. Objects of
  329. * other classes have different class IDs.
  330. * @stable ICU 3.8
  331. */
  332. virtual UClassID getDynamicClassID(void) const;
  333. };
  334. /**
  335. * <code>AnnualTimeZoneRule</code> is a class used for representing a time zone
  336. * rule which takes effect annually. The calenday system used for the rule is
  337. * is based on Gregorian calendar
  338. *
  339. * @stable ICU 3.8
  340. */
  341. class U_I18N_API AnnualTimeZoneRule : public TimeZoneRule {
  342. public:
  343. /**
  344. * The constant representing the maximum year used for designating
  345. * a rule is permanent.
  346. */
  347. static const int32_t MAX_YEAR;
  348. /**
  349. * Constructs a <code>AnnualTimeZoneRule</code> with the name, the GMT offset of its
  350. * standard time, the amount of daylight saving offset adjustment, the annual start
  351. * time rule and the start/until years. The input DateTimeRule is copied by this
  352. * constructor, so the caller remains responsible for deleting the object.
  353. * @param name The time zone name.
  354. * @param rawOffset The GMT offset of its standard time in milliseconds.
  355. * @param dstSavings The amount of daylight saving offset adjustment in
  356. * milliseconds. If this ia a rule for standard time,
  357. * the value of this argument is 0.
  358. * @param dateTimeRule The start date/time rule repeated annually.
  359. * @param startYear The first year when this rule takes effect.
  360. * @param endYear The last year when this rule takes effect. If this
  361. * rule is effective forever in future, specify MAX_YEAR.
  362. * @stable ICU 3.8
  363. */
  364. AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
  365. const DateTimeRule& dateTimeRule, int32_t startYear, int32_t endYear);
  366. /**
  367. * Constructs a <code>AnnualTimeZoneRule</code> with the name, the GMT offset of its
  368. * standard time, the amount of daylight saving offset adjustment, the annual start
  369. * time rule and the start/until years. The input DateTimeRule object is adopted
  370. * by this object, therefore, the caller must not delete the object.
  371. * @param name The time zone name.
  372. * @param rawOffset The GMT offset of its standard time in milliseconds.
  373. * @param dstSavings The amount of daylight saving offset adjustment in
  374. * milliseconds. If this ia a rule for standard time,
  375. * the value of this argument is 0.
  376. * @param dateTimeRule The start date/time rule repeated annually.
  377. * @param startYear The first year when this rule takes effect.
  378. * @param endYear The last year when this rule takes effect. If this
  379. * rule is effective forever in future, specify MAX_YEAR.
  380. * @stable ICU 3.8
  381. */
  382. AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
  383. DateTimeRule* dateTimeRule, int32_t startYear, int32_t endYear);
  384. /**
  385. * Copy constructor.
  386. * @param source The AnnualTimeZoneRule object to be copied.
  387. * @stable ICU 3.8
  388. */
  389. AnnualTimeZoneRule(const AnnualTimeZoneRule& source);
  390. /**
  391. * Destructor.
  392. * @stable ICU 3.8
  393. */
  394. virtual ~AnnualTimeZoneRule();
  395. /**
  396. * Clone this AnnualTimeZoneRule object polymorphically. The caller owns the result and
  397. * should delete it when done.
  398. * @return A copy of the object.
  399. * @stable ICU 3.8
  400. */
  401. virtual AnnualTimeZoneRule* clone() const;
  402. /**
  403. * Assignment operator.
  404. * @param right The object to be copied.
  405. * @stable ICU 3.8
  406. */
  407. AnnualTimeZoneRule& operator=(const AnnualTimeZoneRule& right);
  408. /**
  409. * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
  410. * of different subclasses are considered unequal.
  411. * @param that The object to be compared with.
  412. * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
  413. * @stable ICU 3.8
  414. */
  415. virtual UBool operator==(const TimeZoneRule& that) const;
  416. /**
  417. * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
  418. * of different subclasses are considered unequal.
  419. * @param that The object to be compared with.
  420. * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
  421. * @stable ICU 3.8
  422. */
  423. virtual UBool operator!=(const TimeZoneRule& that) const;
  424. /**
  425. * Gets the start date/time rule used by this rule.
  426. * @return The <code>AnnualDateTimeRule</code> which represents the start date/time
  427. * rule used by this time zone rule.
  428. * @stable ICU 3.8
  429. */
  430. const DateTimeRule* getRule(void) const;
  431. /**
  432. * Gets the first year when this rule takes effect.
  433. * @return The start year of this rule. The year is in Gregorian calendar
  434. * with 0 == 1 BCE, -1 == 2 BCE, etc.
  435. * @stable ICU 3.8
  436. */
  437. int32_t getStartYear(void) const;
  438. /**
  439. * Gets the end year when this rule takes effect.
  440. * @return The end year of this rule (inclusive). The year is in Gregorian calendar
  441. * with 0 == 1 BCE, -1 == 2 BCE, etc.
  442. * @stable ICU 3.8
  443. */
  444. int32_t getEndYear(void) const;
  445. /**
  446. * Gets the time when this rule takes effect in the given year.
  447. * @param year The Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc.
  448. * @param prevRawOffset The standard time offset from UTC before this rule
  449. * takes effect in milliseconds.
  450. * @param prevDSTSavings The amount of daylight saving offset from the
  451. * standard time.
  452. * @param result Receives the start time in the year.
  453. * @return true if this rule takes effect in the year and the result is set to
  454. * "result".
  455. * @stable ICU 3.8
  456. */
  457. UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  458. /**
  459. * Returns if this rule represents the same rule and offsets as another.
  460. * When two <code>TimeZoneRule</code> objects differ only its names, this method
  461. * returns true.
  462. * @param that The <code>TimeZoneRule</code> object to be compared with.
  463. * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
  464. * @stable ICU 3.8
  465. */
  466. virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
  467. /**
  468. * Gets the very first time when this rule takes effect.
  469. * @param prevRawOffset The standard time offset from UTC before this rule
  470. * takes effect in milliseconds.
  471. * @param prevDSTSavings The amount of daylight saving offset from the
  472. * standard time.
  473. * @param result Receives the very first time when this rule takes effect.
  474. * @return true if the start time is available. When false is returned, output parameter
  475. * "result" is unchanged.
  476. * @stable ICU 3.8
  477. */
  478. virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  479. /**
  480. * Gets the final time when this rule takes effect.
  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 result Receives the final time when this rule takes effect.
  486. * @return true if the start time is available. When false is returned, output parameter
  487. * "result" is unchanged.
  488. * @stable ICU 3.8
  489. */
  490. virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  491. /**
  492. * Gets the first time when this rule takes effect after the specified time.
  493. * @param base The first start time after this base time will be returned.
  494. * @param prevRawOffset The standard time offset from UTC before this rule
  495. * takes effect in milliseconds.
  496. * @param prevDSTSavings The amount of daylight saving offset from the
  497. * standard time.
  498. * @param inclusive Whether the base time is inclusive or not.
  499. * @param result Receives The first time when this rule takes effect after
  500. * the specified base time.
  501. * @return true if the start time is available. When false is returned, output parameter
  502. * "result" is unchanged.
  503. * @stable ICU 3.8
  504. */
  505. virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  506. UBool inclusive, UDate& result) const;
  507. /**
  508. * Gets the most recent time when this rule takes effect before the specified time.
  509. * @param base The most recent time before this base time will be returned.
  510. * @param prevRawOffset The standard time offset from UTC before this rule
  511. * takes effect in milliseconds.
  512. * @param prevDSTSavings The amount of daylight saving offset from the
  513. * standard time.
  514. * @param inclusive Whether the base time is inclusive or not.
  515. * @param result Receives The most recent time when this rule takes effect before
  516. * the specified base time.
  517. * @return true if the start time is available. When false is returned, output parameter
  518. * "result" is unchanged.
  519. * @stable ICU 3.8
  520. */
  521. virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  522. UBool inclusive, UDate& result) const;
  523. private:
  524. DateTimeRule* fDateTimeRule;
  525. int32_t fStartYear;
  526. int32_t fEndYear;
  527. public:
  528. /**
  529. * Return the class ID for this class. This is useful only for comparing to
  530. * a return value from getDynamicClassID(). For example:
  531. * <pre>
  532. * . Base* polymorphic_pointer = createPolymorphicObject();
  533. * . if (polymorphic_pointer->getDynamicClassID() ==
  534. * . erived::getStaticClassID()) ...
  535. * </pre>
  536. * @return The class ID for all objects of this class.
  537. * @stable ICU 3.8
  538. */
  539. static UClassID U_EXPORT2 getStaticClassID(void);
  540. /**
  541. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  542. * method is to implement a simple version of RTTI, since not all C++
  543. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  544. * methods call this method.
  545. *
  546. * @return The class ID for this object. All objects of a
  547. * given class have the same class ID. Objects of
  548. * other classes have different class IDs.
  549. * @stable ICU 3.8
  550. */
  551. virtual UClassID getDynamicClassID(void) const;
  552. };
  553. /**
  554. * <code>TimeArrayTimeZoneRule</code> represents a time zone rule whose start times are
  555. * defined by an array of milliseconds since the standard base time.
  556. *
  557. * @stable ICU 3.8
  558. */
  559. class U_I18N_API TimeArrayTimeZoneRule : public TimeZoneRule {
  560. public:
  561. /**
  562. * Constructs a <code>TimeArrayTimeZoneRule</code> with the name, the GMT offset of its
  563. * standard time, the amount of daylight saving offset adjustment and
  564. * the array of times when this rule takes effect.
  565. * @param name The time zone name.
  566. * @param rawOffset The UTC offset of its standard time in milliseconds.
  567. * @param dstSavings The amount of daylight saving offset adjustment in
  568. * milliseconds. If this ia a rule for standard time,
  569. * the value of this argument is 0.
  570. * @param startTimes The array start times in milliseconds since the base time
  571. * (January 1, 1970, 00:00:00).
  572. * @param numStartTimes The number of elements in the parameter "startTimes"
  573. * @param timeRuleType The time type of the start times, which is one of
  574. * <code>DataTimeRule::WALL_TIME</code>, <code>STANDARD_TIME</code>
  575. * and <code>UTC_TIME</code>.
  576. * @stable ICU 3.8
  577. */
  578. TimeArrayTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
  579. const UDate* startTimes, int32_t numStartTimes, DateTimeRule::TimeRuleType timeRuleType);
  580. /**
  581. * Copy constructor.
  582. * @param source The TimeArrayTimeZoneRule object to be copied.
  583. * @stable ICU 3.8
  584. */
  585. TimeArrayTimeZoneRule(const TimeArrayTimeZoneRule& source);
  586. /**
  587. * Destructor.
  588. * @stable ICU 3.8
  589. */
  590. virtual ~TimeArrayTimeZoneRule();
  591. /**
  592. * Clone this TimeArrayTimeZoneRule object polymorphically. The caller owns the result and
  593. * should delete it when done.
  594. * @return A copy of the object.
  595. * @stable ICU 3.8
  596. */
  597. virtual TimeArrayTimeZoneRule* clone() const;
  598. /**
  599. * Assignment operator.
  600. * @param right The object to be copied.
  601. * @stable ICU 3.8
  602. */
  603. TimeArrayTimeZoneRule& operator=(const TimeArrayTimeZoneRule& right);
  604. /**
  605. * Return true if the given <code>TimeZoneRule</code> objects are semantically equal. Objects
  606. * of different subclasses are considered unequal.
  607. * @param that The object to be compared with.
  608. * @return true if the given <code>TimeZoneRule</code> objects are semantically equal.
  609. * @stable ICU 3.8
  610. */
  611. virtual UBool operator==(const TimeZoneRule& that) const;
  612. /**
  613. * Return true if the given <code>TimeZoneRule</code> objects are semantically unequal. Objects
  614. * of different subclasses are considered unequal.
  615. * @param that The object to be compared with.
  616. * @return true if the given <code>TimeZoneRule</code> objects are semantically unequal.
  617. * @stable ICU 3.8
  618. */
  619. virtual UBool operator!=(const TimeZoneRule& that) const;
  620. /**
  621. * Gets the time type of the start times used by this rule. The return value
  622. * is either <code>DateTimeRule::WALL_TIME</code> or <code>STANDARD_TIME</code>
  623. * or <code>UTC_TIME</code>.
  624. *
  625. * @return The time type used of the start times used by this rule.
  626. * @stable ICU 3.8
  627. */
  628. DateTimeRule::TimeRuleType getTimeType(void) const;
  629. /**
  630. * Gets a start time at the index stored in this rule.
  631. * @param index The index of start times
  632. * @param result Receives the start time at the index
  633. * @return true if the index is within the valid range and
  634. * and the result is set. When false, the output
  635. * parameger "result" is unchanged.
  636. * @stable ICU 3.8
  637. */
  638. UBool getStartTimeAt(int32_t index, UDate& result) const;
  639. /**
  640. * Returns the number of start times stored in this rule
  641. * @return The number of start times.
  642. * @stable ICU 3.8
  643. */
  644. int32_t countStartTimes(void) const;
  645. /**
  646. * Returns if this rule represents the same rule and offsets as another.
  647. * When two <code>TimeZoneRule</code> objects differ only its names, this method
  648. * returns true.
  649. * @param that The <code>TimeZoneRule</code> object to be compared with.
  650. * @return true if the other <code>TimeZoneRule</code> is equivalent to this one.
  651. * @stable ICU 3.8
  652. */
  653. virtual UBool isEquivalentTo(const TimeZoneRule& that) const;
  654. /**
  655. * Gets the very first time when this rule takes effect.
  656. * @param prevRawOffset The standard time offset from UTC before this rule
  657. * takes effect in milliseconds.
  658. * @param prevDSTSavings The amount of daylight saving offset from the
  659. * standard time.
  660. * @param result Receives the very first time when this rule takes effect.
  661. * @return true if the start time is available. When false is returned, output parameter
  662. * "result" is unchanged.
  663. * @stable ICU 3.8
  664. */
  665. virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  666. /**
  667. * Gets the final time when this rule takes effect.
  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 result Receives the final time when this rule takes effect.
  673. * @return true if the start time is available. When false is returned, output parameter
  674. * "result" is unchanged.
  675. * @stable ICU 3.8
  676. */
  677. virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
  678. /**
  679. * Gets the first time when this rule takes effect after the specified time.
  680. * @param base The first start time after this base time will be returned.
  681. * @param prevRawOffset The standard time offset from UTC before this rule
  682. * takes effect in milliseconds.
  683. * @param prevDSTSavings The amount of daylight saving offset from the
  684. * standard time.
  685. * @param inclusive Whether the base time is inclusive or not.
  686. * @param result Receives The first time when this rule takes effect after
  687. * the specified base time.
  688. * @return true if the start time is available. When false is returned, output parameter
  689. * "result" is unchanged.
  690. * @stable ICU 3.8
  691. */
  692. virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  693. UBool inclusive, UDate& result) const;
  694. /**
  695. * Gets the most recent time when this rule takes effect before the specified time.
  696. * @param base The most recent time before this base time will be returned.
  697. * @param prevRawOffset The standard time offset from UTC before this rule
  698. * takes effect in milliseconds.
  699. * @param prevDSTSavings The amount of daylight saving offset from the
  700. * standard time.
  701. * @param inclusive Whether the base time is inclusive or not.
  702. * @param result Receives The most recent time when this rule takes effect before
  703. * the specified base time.
  704. * @return true if the start time is available. When false is returned, output parameter
  705. * "result" is unchanged.
  706. * @stable ICU 3.8
  707. */
  708. virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
  709. UBool inclusive, UDate& result) const;
  710. private:
  711. enum { TIMEARRAY_STACK_BUFFER_SIZE = 32 };
  712. UBool initStartTimes(const UDate source[], int32_t size, UErrorCode& ec);
  713. UDate getUTC(UDate time, int32_t raw, int32_t dst) const;
  714. DateTimeRule::TimeRuleType fTimeRuleType;
  715. int32_t fNumStartTimes;
  716. UDate* fStartTimes;
  717. UDate fLocalStartTimes[TIMEARRAY_STACK_BUFFER_SIZE];
  718. public:
  719. /**
  720. * Return the class ID for this class. This is useful only for comparing to
  721. * a return value from getDynamicClassID(). For example:
  722. * <pre>
  723. * . Base* polymorphic_pointer = createPolymorphicObject();
  724. * . if (polymorphic_pointer->getDynamicClassID() ==
  725. * . erived::getStaticClassID()) ...
  726. * </pre>
  727. * @return The class ID for all objects of this class.
  728. * @stable ICU 3.8
  729. */
  730. static UClassID U_EXPORT2 getStaticClassID(void);
  731. /**
  732. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  733. * method is to implement a simple version of RTTI, since not all C++
  734. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  735. * methods call this method.
  736. *
  737. * @return The class ID for this object. All objects of a
  738. * given class have the same class ID. Objects of
  739. * other classes have different class IDs.
  740. * @stable ICU 3.8
  741. */
  742. virtual UClassID getDynamicClassID(void) const;
  743. };
  744. U_NAMESPACE_END
  745. #endif /* #if !UCONFIG_NO_FORMATTING */
  746. #endif /* U_SHOW_CPLUSPLUS_API */
  747. #endif // TZRULE_H
  748. //eof