simpletz.h 45 KB

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