]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/i18n/unicode/tzrule.h
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / tzrule.h
... / ...
CommitLineData
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 !UCONFIG_NO_FORMATTING
20
21#include "unicode/uobject.h"
22#include "unicode/unistr.h"
23#include "unicode/dtrule.h"
24
25#if U_SHOW_CPLUSPLUS_API
26U_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 *
33 * @stable ICU 3.8
34 */
35class U_I18N_API TimeZoneRule : public UObject {
36public:
37 /**
38 * Destructor.
39 * @stable ICU 3.8
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.
47 * @stable ICU 3.8
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.
56 * @stable ICU 3.8
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.
65 * @stable ICU 3.8
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"
73 * @stable ICU 3.8
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.
80 * @stable ICU 3.8
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.
88 * @stable ICU 3.8
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.
98 * @stable ICU 3.8
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.
111 * @stable ICU 3.8
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.
124 * @stable ICU 3.8
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.
140 * @stable ICU 3.8
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.
157 * @stable ICU 3.8
158 */
159 virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
160 UBool inclusive, UDate& result) const = 0;
161
162protected:
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.
171 * @stable ICU 3.8
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.
178 * @stable ICU 3.8
179 */
180 TimeZoneRule(const TimeZoneRule& source);
181
182 /**
183 * Assignment operator.
184 * @param right The object to be copied.
185 * @stable ICU 3.8
186 */
187 TimeZoneRule& operator=(const TimeZoneRule& right);
188
189private:
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.
199 * @stable ICU 3.8
200 */
201class U_I18N_API InitialTimeZoneRule : public TimeZoneRule {
202public:
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.
210 * @stable ICU 3.8
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.
217 * @stable ICU 3.8
218 */
219 InitialTimeZoneRule(const InitialTimeZoneRule& source);
220
221 /**
222 * Destructor.
223 * @stable ICU 3.8
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.
231 * @stable ICU 3.8
232 */
233 virtual InitialTimeZoneRule* clone(void) const;
234
235 /**
236 * Assignment operator.
237 * @param right The object to be copied.
238 * @stable ICU 3.8
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.
247 * @stable ICU 3.8
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.
256 * @stable ICU 3.8
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".
270 * @stable ICU 3.8
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.
280 * @stable ICU 3.8
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.
293 * @stable ICU 3.8
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.
306 * @stable ICU 3.8
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.
322 * @stable ICU 3.8
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.
339 * @stable ICU 3.8
340 */
341 virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
342 UBool inclusive, UDate& result) const;
343
344public:
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.
354 * @stable ICU 3.8
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.
367 * @stable ICU 3.8
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 *
377 * @stable ICU 3.8
378 */
379class U_I18N_API AnnualTimeZoneRule : public TimeZoneRule {
380public:
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.
401 * @stable ICU 3.8
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.
420 * @stable ICU 3.8
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.
428 * @stable ICU 3.8
429 */
430 AnnualTimeZoneRule(const AnnualTimeZoneRule& source);
431
432 /**
433 * Destructor.
434 * @stable ICU 3.8
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.
442 * @stable ICU 3.8
443 */
444 virtual AnnualTimeZoneRule* clone(void) const;
445
446 /**
447 * Assignment operator.
448 * @param right The object to be copied.
449 * @stable ICU 3.8
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.
458 * @stable ICU 3.8
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.
467 * @stable ICU 3.8
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.
475 * @stable ICU 3.8
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.
483 * @stable ICU 3.8
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.
491 * @stable ICU 3.8
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".
505 * @stable ICU 3.8
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.
515 * @stable ICU 3.8
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.
528 * @stable ICU 3.8
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.
541 * @stable ICU 3.8
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.
557 * @stable ICU 3.8
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.
574 * @stable ICU 3.8
575 */
576 virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
577 UBool inclusive, UDate& result) const;
578
579
580private:
581 DateTimeRule* fDateTimeRule;
582 int32_t fStartYear;
583 int32_t fEndYear;
584
585public:
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.
595 * @stable ICU 3.8
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.
608 * @stable ICU 3.8
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 *
617 * @stable ICU 3.8
618 */
619class U_I18N_API TimeArrayTimeZoneRule : public TimeZoneRule {
620public:
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>.
636 * @stable ICU 3.8
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.
644 * @stable ICU 3.8
645 */
646 TimeArrayTimeZoneRule(const TimeArrayTimeZoneRule& source);
647
648 /**
649 * Destructor.
650 * @stable ICU 3.8
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.
658 * @stable ICU 3.8
659 */
660 virtual TimeArrayTimeZoneRule* clone(void) const;
661
662 /**
663 * Assignment operator.
664 * @param right The object to be copied.
665 * @stable ICU 3.8
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.
674 * @stable ICU 3.8
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.
683 * @stable ICU 3.8
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.
693 * @stable ICU 3.8
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.
704 * @stable ICU 3.8
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.
711 * @stable ICU 3.8
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.
721 * @stable ICU 3.8
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.
734 * @stable ICU 3.8
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.
747 * @stable ICU 3.8
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.
763 * @stable ICU 3.8
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.
780 * @stable ICU 3.8
781 */
782 virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
783 UBool inclusive, UDate& result) const;
784
785
786private:
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
796public:
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.
806 * @stable ICU 3.8
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.
819 * @stable ICU 3.8
820 */
821 virtual UClassID getDynamicClassID(void) const;
822};
823
824
825U_NAMESPACE_END
826#endif // U_SHOW_CPLUSPLUS_API
827
828#endif /* #if !UCONFIG_NO_FORMATTING */
829
830#endif // TZRULE_H
831
832//eof