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