tzrule.h 35 KB

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