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