simpletz.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ********************************************************************************
  5. * Copyright (C) 1997-2013, International Business Machines *
  6. * Corporation and others. All Rights Reserved. *
  7. ********************************************************************************
  8. *
  9. * File SIMPLETZ.H
  10. *
  11. * Modification History:
  12. *
  13. * Date Name Description
  14. * 04/21/97 aliu Overhauled header.
  15. * 08/10/98 stephen JDK 1.2 sync
  16. * Added setStartRule() / setEndRule() overloads
  17. * Added hasSameRules()
  18. * 09/02/98 stephen Added getOffset(monthLen)
  19. * Changed getOffset() to take UErrorCode
  20. * 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
  21. * 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
  22. * methods that take TimeMode. Added to docs.
  23. ********************************************************************************
  24. */
  25. #ifndef SIMPLETZ_H
  26. #define SIMPLETZ_H
  27. #include "unicode/utypes.h"
  28. #if U_SHOW_CPLUSPLUS_API
  29. /**
  30. * \file
  31. * \brief C++ API: SimpleTimeZone is a concrete subclass of TimeZone.
  32. */
  33. #if !UCONFIG_NO_FORMATTING
  34. #include "unicode/basictz.h"
  35. U_NAMESPACE_BEGIN
  36. // forward declaration
  37. class InitialTimeZoneRule;
  38. class TimeZoneTransition;
  39. class AnnualTimeZoneRule;
  40. /**
  41. * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
  42. * that represents a time zone for use with a Gregorian calendar. This
  43. * class does not handle historical changes.
  44. * <P>
  45. * When specifying daylight-savings-time begin and end dates, use a negative value for
  46. * <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should
  47. * count from the end of the month backwards. For example, if Daylight Savings
  48. * Time starts or ends at the last Sunday a month, use <code>dayOfWeekInMonth = -1</code>
  49. * along with <code>dayOfWeek = UCAL_SUNDAY</code> to specify the rule.
  50. *
  51. * @see Calendar
  52. * @see GregorianCalendar
  53. * @see TimeZone
  54. * @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
  55. */
  56. class U_I18N_API SimpleTimeZone: public BasicTimeZone {
  57. public:
  58. /**
  59. * TimeMode is used, together with a millisecond offset after
  60. * midnight, to specify a rule transition time. Most rules
  61. * transition at a local wall time, that is, according to the
  62. * current time in effect, either standard, or DST. However, some
  63. * rules transition at local standard time, and some at a specific
  64. * UTC time. Although it might seem that all times could be
  65. * converted to wall time, thus eliminating the need for this
  66. * parameter, this is not the case.
  67. * @stable ICU 2.0
  68. */
  69. enum TimeMode {
  70. WALL_TIME = 0,
  71. STANDARD_TIME,
  72. UTC_TIME
  73. };
  74. /**
  75. * Copy constructor
  76. * @param source the object to be copied.
  77. * @stable ICU 2.0
  78. */
  79. SimpleTimeZone(const SimpleTimeZone& source);
  80. /**
  81. * Default assignment operator
  82. * @param right the object to be copied.
  83. * @stable ICU 2.0
  84. */
  85. SimpleTimeZone& operator=(const SimpleTimeZone& right);
  86. /**
  87. * Destructor
  88. * @stable ICU 2.0
  89. */
  90. virtual ~SimpleTimeZone();
  91. /**
  92. * Returns true if the two TimeZone objects are equal; that is, they have
  93. * the same ID, raw GMT offset, and DST rules.
  94. *
  95. * @param that The SimpleTimeZone object to be compared with.
  96. * @return true if the given time zone is equal to this time zone; false
  97. * otherwise.
  98. * @stable ICU 2.0
  99. */
  100. virtual bool operator==(const TimeZone& that) const override;
  101. /**
  102. * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID,
  103. * and which doesn't observe daylight savings time. Normally you should use
  104. * TimeZone::createInstance() to create a TimeZone instead of creating a
  105. * SimpleTimeZone directly with this constructor.
  106. *
  107. * @param rawOffsetGMT The given base time zone offset to GMT.
  108. * @param ID The timezone ID which is obtained from
  109. * TimeZone.getAvailableIDs.
  110. * @stable ICU 2.0
  111. */
  112. SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID);
  113. /**
  114. * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
  115. * and times to start and end daylight savings time. To create a TimeZone that
  116. * doesn't observe daylight savings time, don't use this constructor; use
  117. * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
  118. * TimeZone.createInstance() to create a TimeZone instead of creating a
  119. * SimpleTimeZone directly with this constructor.
  120. * <P>
  121. * Various types of daylight-savings time rules can be specified by using different
  122. * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
  123. * complete explanation of how these parameters work, see the documentation for
  124. * setStartRule().
  125. *
  126. * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
  127. * @param ID The new SimpleTimeZone's time zone ID.
  128. * @param savingsStartMonth The daylight savings starting month. Month is
  129. * 0-based. eg, 0 for January.
  130. * @param savingsStartDayOfWeekInMonth The daylight savings starting
  131. * day-of-week-in-month. See setStartRule() for a
  132. * complete explanation.
  133. * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
  134. * See setStartRule() for a complete explanation.
  135. * @param savingsStartTime The daylight savings starting time, expressed as the
  136. * number of milliseconds after midnight.
  137. * @param savingsEndMonth The daylight savings ending month. Month is
  138. * 0-based. eg, 0 for January.
  139. * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
  140. * See setStartRule() for a complete explanation.
  141. * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
  142. * See setStartRule() for a complete explanation.
  143. * @param savingsEndTime The daylight savings ending time, expressed as the
  144. * number of milliseconds after midnight.
  145. * @param status An UErrorCode to receive the status.
  146. * @stable ICU 2.0
  147. */
  148. SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
  149. int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
  150. int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
  151. int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
  152. int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
  153. UErrorCode& status);
  154. /**
  155. * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
  156. * and times to start and end daylight savings time. To create a TimeZone that
  157. * doesn't observe daylight savings time, don't use this constructor; use
  158. * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
  159. * TimeZone.createInstance() to create a TimeZone instead of creating a
  160. * SimpleTimeZone directly with this constructor.
  161. * <P>
  162. * Various types of daylight-savings time rules can be specified by using different
  163. * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
  164. * complete explanation of how these parameters work, see the documentation for
  165. * setStartRule().
  166. *
  167. * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
  168. * @param ID The new SimpleTimeZone's time zone ID.
  169. * @param savingsStartMonth The daylight savings starting month. Month is
  170. * 0-based. eg, 0 for January.
  171. * @param savingsStartDayOfWeekInMonth The daylight savings starting
  172. * day-of-week-in-month. See setStartRule() for a
  173. * complete explanation.
  174. * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
  175. * See setStartRule() for a complete explanation.
  176. * @param savingsStartTime The daylight savings starting time, expressed as the
  177. * number of milliseconds after midnight.
  178. * @param savingsEndMonth The daylight savings ending month. Month is
  179. * 0-based. eg, 0 for January.
  180. * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
  181. * See setStartRule() for a complete explanation.
  182. * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
  183. * See setStartRule() for a complete explanation.
  184. * @param savingsEndTime The daylight savings ending time, expressed as the
  185. * number of milliseconds after midnight.
  186. * @param savingsDST The number of milliseconds added to standard time
  187. * to get DST time. Default is one hour.
  188. * @param status An UErrorCode to receive the status.
  189. * @stable ICU 2.0
  190. */
  191. SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
  192. int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
  193. int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
  194. int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
  195. int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
  196. int32_t savingsDST, UErrorCode& status);
  197. /**
  198. * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
  199. * and times to start and end daylight savings time. To create a TimeZone that
  200. * doesn't observe daylight savings time, don't use this constructor; use
  201. * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
  202. * TimeZone.createInstance() to create a TimeZone instead of creating a
  203. * SimpleTimeZone directly with this constructor.
  204. * <P>
  205. * Various types of daylight-savings time rules can be specified by using different
  206. * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
  207. * complete explanation of how these parameters work, see the documentation for
  208. * setStartRule().
  209. *
  210. * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
  211. * @param ID The new SimpleTimeZone's time zone ID.
  212. * @param savingsStartMonth The daylight savings starting month. Month is
  213. * 0-based. eg, 0 for January.
  214. * @param savingsStartDayOfWeekInMonth The daylight savings starting
  215. * day-of-week-in-month. See setStartRule() for a
  216. * complete explanation.
  217. * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
  218. * See setStartRule() for a complete explanation.
  219. * @param savingsStartTime The daylight savings starting time, expressed as the
  220. * number of milliseconds after midnight.
  221. * @param savingsStartTimeMode Whether the start time is local wall time, local
  222. * standard time, or UTC time. Default is local wall time.
  223. * @param savingsEndMonth The daylight savings ending month. Month is
  224. * 0-based. eg, 0 for January.
  225. * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month.
  226. * See setStartRule() for a complete explanation.
  227. * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
  228. * See setStartRule() for a complete explanation.
  229. * @param savingsEndTime The daylight savings ending time, expressed as the
  230. * number of milliseconds after midnight.
  231. * @param savingsEndTimeMode Whether the end time is local wall time, local
  232. * standard time, or UTC time. Default is local wall time.
  233. * @param savingsDST The number of milliseconds added to standard time
  234. * to get DST time. Default is one hour.
  235. * @param status An UErrorCode to receive the status.
  236. * @stable ICU 2.0
  237. */
  238. SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
  239. int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
  240. int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
  241. TimeMode savingsStartTimeMode,
  242. int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
  243. int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode,
  244. int32_t savingsDST, UErrorCode& status);
  245. /**
  246. * Sets the daylight savings starting year, that is, the year this time zone began
  247. * observing its specified daylight savings time rules. The time zone is considered
  248. * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't
  249. * support historical daylight-savings-time rules.
  250. * @param year the daylight savings starting year.
  251. * @stable ICU 2.0
  252. */
  253. void setStartYear(int32_t year);
  254. /**
  255. * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
  256. * Time starts at the second Sunday in March, at 2 AM in standard time.
  257. * Therefore, you can set the start rule by calling:
  258. * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
  259. * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
  260. * the exact starting date. Their exact meaning depend on their respective signs,
  261. * allowing various types of rules to be constructed, as follows:
  262. * <ul>
  263. * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
  264. * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
  265. * of the month).</li>
  266. * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
  267. * the day of week in the month counting backward from the end of the month.
  268. * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
  269. * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
  270. * specifies the day of the month, regardless of what day of the week it is.
  271. * (e.g., (10, 0) is the tenth day of the month)</li>
  272. * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
  273. * specifies the day of the month counting backward from the end of the
  274. * month, regardless of what day of the week it is (e.g., (-2, 0) is the
  275. * next-to-last day of the month).</li>
  276. * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
  277. * first specified day of the week on or after the specified day of the month.
  278. * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
  279. * [or the 15th itself if the 15th is a Sunday].)</li>
  280. * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
  281. * last specified day of the week on or before the specified day of the month.
  282. * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
  283. * [or the 20th itself if the 20th is a Tuesday].)</li>
  284. * </ul>
  285. * @param month the daylight savings starting month. Month is 0-based.
  286. * eg, 0 for January.
  287. * @param dayOfWeekInMonth the daylight savings starting
  288. * day-of-week-in-month. Please see the member description for an example.
  289. * @param dayOfWeek the daylight savings starting day-of-week. Please see
  290. * the member description for an example.
  291. * @param time the daylight savings starting time. Please see the member
  292. * description for an example.
  293. * @param status An UErrorCode
  294. * @stable ICU 2.0
  295. */
  296. void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
  297. int32_t time, UErrorCode& status);
  298. /**
  299. * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
  300. * Time starts at the second Sunday in March, at 2 AM in standard time.
  301. * Therefore, you can set the start rule by calling:
  302. * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
  303. * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
  304. * the exact starting date. Their exact meaning depend on their respective signs,
  305. * allowing various types of rules to be constructed, as follows:
  306. * <ul>
  307. * <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
  308. * day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
  309. * of the month).</li>
  310. * <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
  311. * the day of week in the month counting backward from the end of the month.
  312. * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
  313. * <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
  314. * specifies the day of the month, regardless of what day of the week it is.
  315. * (e.g., (10, 0) is the tenth day of the month)</li>
  316. * <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
  317. * specifies the day of the month counting backward from the end of the
  318. * month, regardless of what day of the week it is (e.g., (-2, 0) is the
  319. * next-to-last day of the month).</li>
  320. * <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
  321. * first specified day of the week on or after the specified day of the month.
  322. * (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
  323. * [or the 15th itself if the 15th is a Sunday].)</li>
  324. * <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
  325. * last specified day of the week on or before the specified day of the month.
  326. * (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
  327. * [or the 20th itself if the 20th is a Tuesday].)</li>
  328. * </ul>
  329. * @param month the daylight savings starting month. Month is 0-based.
  330. * eg, 0 for January.
  331. * @param dayOfWeekInMonth the daylight savings starting
  332. * day-of-week-in-month. Please see the member description for an example.
  333. * @param dayOfWeek the daylight savings starting day-of-week. Please see
  334. * the member description for an example.
  335. * @param time the daylight savings starting time. Please see the member
  336. * description for an example.
  337. * @param mode whether the time is local wall time, local standard time,
  338. * or UTC time. Default is local wall time.
  339. * @param status An UErrorCode
  340. * @stable ICU 2.0
  341. */
  342. void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
  343. int32_t time, TimeMode mode, UErrorCode& status);
  344. /**
  345. * Sets the DST start rule to a fixed date within a month.
  346. *
  347. * @param month The month in which this rule occurs (0-based).
  348. * @param dayOfMonth The date in that month (1-based).
  349. * @param time The time of that day (number of millis after midnight)
  350. * when DST takes effect in local wall time, which is
  351. * standard time in this case.
  352. * @param status An UErrorCode
  353. * @stable ICU 2.0
  354. */
  355. void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
  356. UErrorCode& status);
  357. /**
  358. * Sets the DST start rule to a fixed date within a month.
  359. *
  360. * @param month The month in which this rule occurs (0-based).
  361. * @param dayOfMonth The date in that month (1-based).
  362. * @param time The time of that day (number of millis after midnight)
  363. * when DST takes effect in local wall time, which is
  364. * standard time in this case.
  365. * @param mode whether the time is local wall time, local standard time,
  366. * or UTC time. Default is local wall time.
  367. * @param status An UErrorCode
  368. * @stable ICU 2.0
  369. */
  370. void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
  371. TimeMode mode, UErrorCode& status);
  372. /**
  373. * Sets the DST start rule to a weekday before or after a give date within
  374. * a month, e.g., the first Monday on or after the 8th.
  375. *
  376. * @param month The month in which this rule occurs (0-based).
  377. * @param dayOfMonth A date within that month (1-based).
  378. * @param dayOfWeek The day of the week on which this rule occurs.
  379. * @param time The time of that day (number of millis after midnight)
  380. * when DST takes effect in local wall time, which is
  381. * standard time in this case.
  382. * @param after If true, this rule selects the first dayOfWeek on
  383. * or after dayOfMonth. If false, this rule selects
  384. * the last dayOfWeek on or before dayOfMonth.
  385. * @param status An UErrorCode
  386. * @stable ICU 2.0
  387. */
  388. void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
  389. int32_t time, UBool after, UErrorCode& status);
  390. /**
  391. * Sets the DST start rule to a weekday before or after a give date within
  392. * a month, e.g., the first Monday on or after the 8th.
  393. *
  394. * @param month The month in which this rule occurs (0-based).
  395. * @param dayOfMonth A date within that month (1-based).
  396. * @param dayOfWeek The day of the week on which this rule occurs.
  397. * @param time The time of that day (number of millis after midnight)
  398. * when DST takes effect in local wall time, which is
  399. * standard time in this case.
  400. * @param mode whether the time is local wall time, local standard time,
  401. * or UTC time. Default is local wall time.
  402. * @param after If true, this rule selects the first dayOfWeek on
  403. * or after dayOfMonth. If false, this rule selects
  404. * the last dayOfWeek on or before dayOfMonth.
  405. * @param status An UErrorCode
  406. * @stable ICU 2.0
  407. */
  408. void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
  409. int32_t time, TimeMode mode, UBool after, UErrorCode& status);
  410. /**
  411. * Sets the daylight savings ending rule. For example, if Daylight
  412. * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
  413. * Therefore, you can set the end rule by calling:
  414. * <pre>
  415. * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
  416. * </pre>
  417. * Various other types of rules can be specified by manipulating the dayOfWeek
  418. * and dayOfWeekInMonth parameters. For complete details, see the documentation
  419. * for setStartRule().
  420. *
  421. * @param month the daylight savings ending month. Month is 0-based.
  422. * eg, 0 for January.
  423. * @param dayOfWeekInMonth the daylight savings ending
  424. * day-of-week-in-month. See setStartRule() for a complete explanation.
  425. * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
  426. * for a complete explanation.
  427. * @param time the daylight savings ending time. Please see the member
  428. * description for an example.
  429. * @param status An UErrorCode
  430. * @stable ICU 2.0
  431. */
  432. void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
  433. int32_t time, UErrorCode& status);
  434. /**
  435. * Sets the daylight savings ending rule. For example, if Daylight
  436. * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
  437. * Therefore, you can set the end rule by calling:
  438. * <pre>
  439. * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
  440. * </pre>
  441. * Various other types of rules can be specified by manipulating the dayOfWeek
  442. * and dayOfWeekInMonth parameters. For complete details, see the documentation
  443. * for setStartRule().
  444. *
  445. * @param month the daylight savings ending month. Month is 0-based.
  446. * eg, 0 for January.
  447. * @param dayOfWeekInMonth the daylight savings ending
  448. * day-of-week-in-month. See setStartRule() for a complete explanation.
  449. * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
  450. * for a complete explanation.
  451. * @param time the daylight savings ending time. Please see the member
  452. * description for an example.
  453. * @param mode whether the time is local wall time, local standard time,
  454. * or UTC time. Default is local wall time.
  455. * @param status An UErrorCode
  456. * @stable ICU 2.0
  457. */
  458. void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
  459. int32_t time, TimeMode mode, UErrorCode& status);
  460. /**
  461. * Sets the DST end rule to a fixed date within a month.
  462. *
  463. * @param month The month in which this rule occurs (0-based).
  464. * @param dayOfMonth The date in that month (1-based).
  465. * @param time The time of that day (number of millis after midnight)
  466. * when DST ends in local wall time, which is daylight
  467. * time in this case.
  468. * @param status An UErrorCode
  469. * @stable ICU 2.0
  470. */
  471. void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status);
  472. /**
  473. * Sets the DST end rule to a fixed date within a month.
  474. *
  475. * @param month The month in which this rule occurs (0-based).
  476. * @param dayOfMonth The date in that month (1-based).
  477. * @param time The time of that day (number of millis after midnight)
  478. * when DST ends in local wall time, which is daylight
  479. * time in this case.
  480. * @param mode whether the time is local wall time, local standard time,
  481. * or UTC time. Default is local wall time.
  482. * @param status An UErrorCode
  483. * @stable ICU 2.0
  484. */
  485. void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time,
  486. TimeMode mode, UErrorCode& status);
  487. /**
  488. * Sets the DST end rule to a weekday before or after a give date within
  489. * a month, e.g., the first Monday on or after the 8th.
  490. *
  491. * @param month The month in which this rule occurs (0-based).
  492. * @param dayOfMonth A date within that month (1-based).
  493. * @param dayOfWeek The day of the week on which this rule occurs.
  494. * @param time The time of that day (number of millis after midnight)
  495. * when DST ends in local wall time, which is daylight
  496. * time in this case.
  497. * @param after If true, this rule selects the first dayOfWeek on
  498. * or after dayOfMonth. If false, this rule selects
  499. * the last dayOfWeek on or before dayOfMonth.
  500. * @param status An UErrorCode
  501. * @stable ICU 2.0
  502. */
  503. void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
  504. int32_t time, UBool after, UErrorCode& status);
  505. /**
  506. * Sets the DST end rule to a weekday before or after a give date within
  507. * a month, e.g., the first Monday on or after the 8th.
  508. *
  509. * @param month The month in which this rule occurs (0-based).
  510. * @param dayOfMonth A date within that month (1-based).
  511. * @param dayOfWeek The day of the week on which this rule occurs.
  512. * @param time The time of that day (number of millis after midnight)
  513. * when DST ends in local wall time, which is daylight
  514. * time in this case.
  515. * @param mode whether the time is local wall time, local standard time,
  516. * or UTC time. Default is local wall time.
  517. * @param after If true, this rule selects the first dayOfWeek on
  518. * or after dayOfMonth. If false, this rule selects
  519. * the last dayOfWeek on or before dayOfMonth.
  520. * @param status An UErrorCode
  521. * @stable ICU 2.0
  522. */
  523. void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
  524. int32_t time, TimeMode mode, UBool after, UErrorCode& status);
  525. /**
  526. * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
  527. * to GMT to get local time in this time zone, taking daylight savings time into
  528. * account) as of a particular reference date. The reference date is used to determine
  529. * whether daylight savings time is in effect and needs to be figured into the offset
  530. * that is returned (in other words, what is the adjusted GMT offset in this time zone
  531. * at this particular date and time?). For the time zones produced by createTimeZone(),
  532. * the reference data is specified according to the Gregorian calendar, and the date
  533. * and time fields are in GMT, NOT local time.
  534. *
  535. * @param era The reference date's era
  536. * @param year The reference date's year
  537. * @param month The reference date's month (0-based; 0 is January)
  538. * @param day The reference date's day-in-month (1-based)
  539. * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
  540. * @param millis The reference date's milliseconds in day, UTT (NOT local time).
  541. * @param status An UErrorCode to receive the status.
  542. * @return The offset in milliseconds to add to GMT to get local time.
  543. * @stable ICU 2.0
  544. */
  545. virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
  546. uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const override;
  547. /**
  548. * Gets the time zone offset, for current date, modified in case of
  549. * daylight savings. This is the offset to add *to* UTC to get local time.
  550. * @param era the era of the given date.
  551. * @param year the year in the given date.
  552. * @param month the month in the given date.
  553. * Month is 0-based. e.g., 0 for January.
  554. * @param day the day-in-month of the given date.
  555. * @param dayOfWeek the day-of-week of the given date.
  556. * @param milliseconds the millis in day in <em>standard</em> local time.
  557. * @param monthLength the length of the given month in days.
  558. * @param status An UErrorCode to receive the status.
  559. * @return the offset to add *to* GMT to get local time.
  560. * @stable ICU 2.0
  561. */
  562. virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
  563. uint8_t dayOfWeek, int32_t milliseconds,
  564. int32_t monthLength, UErrorCode& status) const override;
  565. /**
  566. * Gets the time zone offset, for current date, modified in case of
  567. * daylight savings. This is the offset to add *to* UTC to get local time.
  568. * @param era the era of the given date.
  569. * @param year the year in the given date.
  570. * @param month the month in the given date.
  571. * Month is 0-based. e.g., 0 for January.
  572. * @param day the day-in-month of the given date.
  573. * @param dayOfWeek the day-of-week of the given date.
  574. * @param milliseconds the millis in day in <em>standard</em> local time.
  575. * @param monthLength the length of the given month in days.
  576. * @param prevMonthLength length of the previous month in days.
  577. * @param status An UErrorCode to receive the status.
  578. * @return the offset to add *to* GMT to get local time.
  579. * @stable ICU 2.0
  580. */
  581. virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
  582. uint8_t dayOfWeek, int32_t milliseconds,
  583. int32_t monthLength, int32_t prevMonthLength,
  584. UErrorCode& status) const;
  585. /**
  586. * Redeclared TimeZone method. This implementation simply calls
  587. * the base class method, which otherwise would be hidden.
  588. * @stable ICU 2.8
  589. */
  590. virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
  591. int32_t& dstOffset, UErrorCode& ec) const override;
  592. /**
  593. * Get time zone offsets from local wall time.
  594. * @stable ICU 69
  595. */
  596. virtual void getOffsetFromLocal(
  597. UDate date, UTimeZoneLocalOption nonExistingTimeOpt,
  598. UTimeZoneLocalOption duplicatedTimeOpt,
  599. int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const override;
  600. /**
  601. * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
  602. * to GMT to get local time, before taking daylight savings time into account).
  603. *
  604. * @return The TimeZone's raw GMT offset.
  605. * @stable ICU 2.0
  606. */
  607. virtual int32_t getRawOffset() const override;
  608. /**
  609. * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
  610. * to GMT to get local time, before taking daylight savings time into account).
  611. *
  612. * @param offsetMillis The new raw GMT offset for this time zone.
  613. * @stable ICU 2.0
  614. */
  615. virtual void setRawOffset(int32_t offsetMillis) override;
  616. /**
  617. * Sets the amount of time in ms that the clock is advanced during DST.
  618. * @param millisSavedDuringDST the number of milliseconds the time is
  619. * advanced with respect to standard time when the daylight savings rules
  620. * are in effect. Typically one hour (+3600000). The amount could be negative,
  621. * but not 0.
  622. * @param status An UErrorCode to receive the status.
  623. * @stable ICU 2.0
  624. */
  625. void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
  626. /**
  627. * Returns the amount of time in ms that the clock is advanced during DST.
  628. * @return the number of milliseconds the time is
  629. * advanced with respect to standard time when the daylight savings rules
  630. * are in effect. Typically one hour (+3600000). The amount could be negative,
  631. * but not 0.
  632. * @stable ICU 2.0
  633. */
  634. virtual int32_t getDSTSavings() const override;
  635. /**
  636. * Queries if this TimeZone uses Daylight Savings Time.
  637. *
  638. * @return True if this TimeZone uses Daylight Savings Time; false otherwise.
  639. * @stable ICU 2.0
  640. */
  641. virtual UBool useDaylightTime() const override;
  642. #ifndef U_FORCE_HIDE_DEPRECATED_API
  643. /**
  644. * Returns true if the given date is within the period when daylight savings time
  645. * is in effect; false otherwise. If the TimeZone doesn't observe daylight savings
  646. * time, this functions always returns false.
  647. * This method is wasteful since it creates a new GregorianCalendar and
  648. * deletes it each time it is called. This is a deprecated method
  649. * and provided only for Java compatibility.
  650. *
  651. * @param date The date to test.
  652. * @param status An UErrorCode to receive the status.
  653. * @return true if the given date is in Daylight Savings Time;
  654. * false otherwise.
  655. * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
  656. */
  657. virtual UBool inDaylightTime(UDate date, UErrorCode& status) const override;
  658. #endif // U_FORCE_HIDE_DEPRECATED_API
  659. /**
  660. * Return true if this zone has the same rules and offset as another zone.
  661. * @param other the TimeZone object to be compared with
  662. * @return true if the given zone has the same rules and offset as this one
  663. * @stable ICU 2.0
  664. */
  665. UBool hasSameRules(const TimeZone& other) const override;
  666. /**
  667. * Clones TimeZone objects polymorphically. Clients are responsible for deleting
  668. * the TimeZone object cloned.
  669. *
  670. * @return A new copy of this TimeZone object.
  671. * @stable ICU 2.0
  672. */
  673. virtual SimpleTimeZone* clone() const override;
  674. /**
  675. * Gets the first time zone transition after the base time.
  676. * @param base The base time.
  677. * @param inclusive Whether the base time is inclusive or not.
  678. * @param result Receives the first transition after the base time.
  679. * @return true if the transition is found.
  680. * @stable ICU 3.8
  681. */
  682. virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const override;
  683. /**
  684. * Gets the most recent time zone transition before the base time.
  685. * @param base The base time.
  686. * @param inclusive Whether the base time is inclusive or not.
  687. * @param result Receives the most recent transition before the base time.
  688. * @return true if the transition is found.
  689. * @stable ICU 3.8
  690. */
  691. virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const override;
  692. /**
  693. * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
  694. * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
  695. * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
  696. * @param status Receives error status code.
  697. * @return The number of <code>TimeZoneRule</code>s representing time transitions.
  698. * @stable ICU 3.8
  699. */
  700. virtual int32_t countTransitionRules(UErrorCode& status) const override;
  701. /**
  702. * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
  703. * which represent time transitions for this time zone. On successful return,
  704. * the argument initial points to non-nullptr <code>InitialTimeZoneRule</code> and
  705. * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
  706. * instances up to the size specified by trscount. The results are referencing the
  707. * rule instance held by this time zone instance. Therefore, after this time zone
  708. * is destructed, they are no longer available.
  709. * @param initial Receives the initial timezone rule
  710. * @param trsrules Receives the timezone transition rules
  711. * @param trscount On input, specify the size of the array 'transitions' receiving
  712. * the timezone transition rules. On output, actual number of
  713. * rules filled in the array will be set.
  714. * @param status Receives error status code.
  715. * @stable ICU 3.8
  716. */
  717. virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
  718. const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const override;
  719. public:
  720. /**
  721. * Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
  722. * override. This method is to implement a simple version of RTTI, since not all C++
  723. * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
  724. * this method.
  725. *
  726. * @return The class ID for this object. All objects of a given class have the
  727. * same class ID. Objects of other classes have different class IDs.
  728. * @stable ICU 2.0
  729. */
  730. virtual UClassID getDynamicClassID() const override;
  731. /**
  732. * Return the class ID for this class. This is useful only for comparing to a return
  733. * value from getDynamicClassID(). For example:
  734. * <pre>
  735. * . Base* polymorphic_pointer = createPolymorphicObject();
  736. * . if (polymorphic_pointer->getDynamicClassID() ==
  737. * . Derived::getStaticClassID()) ...
  738. * </pre>
  739. * @return The class ID for all objects of this class.
  740. * @stable ICU 2.0
  741. */
  742. static UClassID U_EXPORT2 getStaticClassID();
  743. private:
  744. /**
  745. * Constants specifying values of startMode and endMode.
  746. */
  747. enum EMode
  748. {
  749. DOM_MODE = 1,
  750. DOW_IN_MONTH_MODE,
  751. DOW_GE_DOM_MODE,
  752. DOW_LE_DOM_MODE
  753. };
  754. SimpleTimeZone() = delete; // default constructor not implemented
  755. /**
  756. * Internal construction method.
  757. * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
  758. * @param startMonth the month DST starts
  759. * @param startDay the day DST starts
  760. * @param startDayOfWeek the DOW DST starts
  761. * @param startTime the time DST starts
  762. * @param startTimeMode Whether the start time is local wall time, local
  763. * standard time, or UTC time. Default is local wall time.
  764. * @param endMonth the month DST ends
  765. * @param endDay the day DST ends
  766. * @param endDayOfWeek the DOW DST ends
  767. * @param endTime the time DST ends
  768. * @param endTimeMode Whether the end time is local wall time, local
  769. * standard time, or UTC time. Default is local wall time.
  770. * @param dstSavings The number of milliseconds added to standard time
  771. * to get DST time. Default is one hour.
  772. * @param status An UErrorCode to receive the status.
  773. */
  774. void construct(int32_t rawOffsetGMT,
  775. int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
  776. int32_t startTime, TimeMode startTimeMode,
  777. int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
  778. int32_t endTime, TimeMode endTimeMode,
  779. int32_t dstSavings, UErrorCode& status);
  780. /**
  781. * Compare a given date in the year to a rule. Return 1, 0, or -1, depending
  782. * on whether the date is after, equal to, or before the rule date. The
  783. * millis are compared directly against the ruleMillis, so any
  784. * standard-daylight adjustments must be handled by the caller.
  785. *
  786. * @return 1 if the date is after the rule date, -1 if the date is before
  787. * the rule date, or 0 if the date is equal to the rule date.
  788. */
  789. static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
  790. int8_t dayOfMonth,
  791. int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
  792. EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
  793. int8_t ruleDay, int32_t ruleMillis);
  794. /**
  795. * Given a set of encoded rules in startDay and startDayOfMonth, decode
  796. * them and set the startMode appropriately. Do the same for endDay and
  797. * endDayOfMonth.
  798. * <P>
  799. * Upon entry, the day of week variables may be zero or
  800. * negative, in order to indicate special modes. The day of month
  801. * variables may also be negative.
  802. * <P>
  803. * Upon exit, the mode variables will be
  804. * set, and the day of week and day of month variables will be positive.
  805. * <P>
  806. * This method also recognizes a startDay or endDay of zero as indicating
  807. * no DST.
  808. */
  809. void decodeRules(UErrorCode& status);
  810. void decodeStartRule(UErrorCode& status);
  811. void decodeEndRule(UErrorCode& status);
  812. int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts
  813. int32_t startTime;
  814. TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
  815. int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
  816. int32_t endTime;
  817. int32_t startYear; // the year these DST rules took effect
  818. int32_t rawOffset; // the TimeZone's raw GMT offset
  819. UBool useDaylight; // flag indicating whether this TimeZone uses DST
  820. static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
  821. EMode startMode, endMode; // flags indicating what kind of rules the DST rules are
  822. /**
  823. * A positive value indicating the amount of time saved during DST in ms.
  824. * Typically one hour; sometimes 30 minutes.
  825. */
  826. int32_t dstSavings;
  827. /* Private for BasicTimeZone implementation */
  828. void checkTransitionRules(UErrorCode& status) const;
  829. void initTransitionRules(UErrorCode& status);
  830. void clearTransitionRules();
  831. void deleteTransitionRules();
  832. UBool transitionRulesInitialized;
  833. InitialTimeZoneRule* initialRule;
  834. TimeZoneTransition* firstTransition;
  835. AnnualTimeZoneRule* stdRule;
  836. AnnualTimeZoneRule* dstRule;
  837. };
  838. inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
  839. int32_t dayOfWeek,
  840. int32_t time, UErrorCode& status) {
  841. setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
  842. }
  843. inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
  844. int32_t time,
  845. UErrorCode& status) {
  846. setStartRule(month, dayOfMonth, time, WALL_TIME, status);
  847. }
  848. inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
  849. int32_t dayOfWeek,
  850. int32_t time, UBool after, UErrorCode& status) {
  851. setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
  852. }
  853. inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
  854. int32_t dayOfWeek,
  855. int32_t time, UErrorCode& status) {
  856. setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
  857. }
  858. inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
  859. int32_t time, UErrorCode& status) {
  860. setEndRule(month, dayOfMonth, time, WALL_TIME, status);
  861. }
  862. inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
  863. int32_t time, UBool after, UErrorCode& status) {
  864. setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
  865. }
  866. inline void
  867. SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
  868. int32_t& dstOffsetRef, UErrorCode& ec) const {
  869. TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
  870. }
  871. U_NAMESPACE_END
  872. #endif /* #if !UCONFIG_NO_FORMATTING */
  873. #endif /* U_SHOW_CPLUSPLUS_API */
  874. #endif // _SIMPLETZ