simpletz.h 45 KB

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