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