ICU 77.1  77.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tzrule.h
Go to the documentation of this file.
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 
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 
27 U_NAMESPACE_BEGIN
28 
37 public:
42  virtual ~TimeZoneRule();
43 
50  virtual TimeZoneRule* clone() const = 0;
51 
59  virtual bool operator==(const TimeZoneRule& that) const;
60 
68  virtual bool operator!=(const TimeZoneRule& that) const;
69 
77 
83  int32_t getRawOffset() const;
84 
91  int32_t getDSTSavings() const;
92 
101  virtual UBool isEquivalentTo(const TimeZoneRule& other) const;
102 
114  virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const = 0;
115 
127  virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const = 0;
128 
143  virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
144  UBool inclusive, UDate& result) const = 0;
145 
160  virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
161  UBool inclusive, UDate& result) const = 0;
162 
163 protected:
164 
174  TimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings);
175 
181  TimeZoneRule(const TimeZoneRule& source);
182 
189 
190 private:
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 
203 public:
213  InitialTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings);
214 
221 
227 
234  virtual InitialTimeZoneRule* clone() const override;
235 
242 
250  virtual bool operator==(const TimeZoneRule& that) const override;
251 
259  virtual bool operator!=(const TimeZoneRule& that) const override;
260 
269  virtual UBool isEquivalentTo(const TimeZoneRule& that) const override;
270 
282  virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const override;
283 
295  virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const override;
296 
311  virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
312  UBool inclusive, UDate& result) const override;
313 
328  virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
329  UBool inclusive, UDate& result) const override;
330 
331 public:
343  static UClassID U_EXPORT2 getStaticClassID();
344 
356  virtual UClassID getDynamicClassID() const override;
357 };
358 
367 public:
372  static const int32_t MAX_YEAR;
373 
390  AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
391  const DateTimeRule& dateTimeRule, int32_t startYear, int32_t endYear);
392 
409  AnnualTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
410  DateTimeRule* dateTimeRule, int32_t startYear, int32_t endYear);
411 
418 
424 
431  virtual AnnualTimeZoneRule* clone() const override;
432 
439 
447  virtual bool operator==(const TimeZoneRule& that) const override;
448 
456  virtual bool operator!=(const TimeZoneRule& that) const override;
457 
464  const DateTimeRule* getRule() const;
465 
472  int32_t getStartYear() const;
473 
480  int32_t getEndYear() const;
481 
494  UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const;
495 
504  virtual UBool isEquivalentTo(const TimeZoneRule& that) const override;
505 
517  virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const override;
518 
530  virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const override;
531 
546  virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
547  UBool inclusive, UDate& result) const override;
548 
563  virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
564  UBool inclusive, UDate& result) const override;
565 
566 
567 private:
568  DateTimeRule* fDateTimeRule;
569  int32_t fStartYear;
570  int32_t fEndYear;
571 
572 public:
584  static UClassID U_EXPORT2 getStaticClassID();
585 
597  virtual UClassID getDynamicClassID() const override;
598 };
599 
607 public:
625  TimeArrayTimeZoneRule(const UnicodeString& name, int32_t rawOffset, int32_t dstSavings,
626  const UDate* startTimes, int32_t numStartTimes, DateTimeRule::TimeRuleType timeRuleType);
627 
634 
640 
647  virtual TimeArrayTimeZoneRule* clone() const override;
648 
655 
663  virtual bool operator==(const TimeZoneRule& that) const override;
664 
672  virtual bool operator!=(const TimeZoneRule& that) const override;
673 
683 
693  UBool getStartTimeAt(int32_t index, UDate& result) const;
694 
700  int32_t countStartTimes() const;
701 
710  virtual UBool isEquivalentTo(const TimeZoneRule& that) const override;
711 
723  virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const override;
724 
736  virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate& result) const override;
737 
752  virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
753  UBool inclusive, UDate& result) const override;
754 
769  virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings,
770  UBool inclusive, UDate& result) const override;
771 
772 
773 private:
774  enum { TIMEARRAY_STACK_BUFFER_SIZE = 32 };
775  UBool initStartTimes(const UDate source[], int32_t size, UErrorCode& ec);
776  UDate getUTC(UDate time, int32_t raw, int32_t dst) const;
777 
778  DateTimeRule::TimeRuleType fTimeRuleType;
779  int32_t fNumStartTimes;
780  UDate* fStartTimes;
781  UDate fLocalStartTimes[TIMEARRAY_STACK_BUFFER_SIZE];
782 
783 public:
795  static UClassID U_EXPORT2 getStaticClassID();
796 
808  virtual UClassID getDynamicClassID() const override;
809 };
810 
811 
812 U_NAMESPACE_END
813 
814 #endif /* #if !UCONFIG_NO_FORMATTING */
815 
816 #endif /* U_SHOW_CPLUSPLUS_API */
817 
818 #endif // TZRULE_H
819 
820 //eof
AnnualTimeZoneRule is a class used for representing a time zone rule which takes effect annually.
Definition: tzrule.h:366
virtual ~AnnualTimeZoneRule()
Destructor.
AnnualTimeZoneRule(const UnicodeString &name, int32_t rawOffset, int32_t dstSavings, DateTimeRule *dateTimeRule, int32_t startYear, int32_t endYear)
Constructs a AnnualTimeZoneRule with the name, the GMT offset of its standard time,...
static const int32_t MAX_YEAR
The constant representing the maximum year used for designating a rule is permanent.
Definition: tzrule.h:372
virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, UBool inclusive, UDate &result) const override
Gets the first time when this rule takes effect after the specified time.
int32_t getEndYear() const
Gets the end year when this rule takes effect.
UBool getStartInYear(int32_t year, int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const
Gets the time when this rule takes effect in the given year.
virtual AnnualTimeZoneRule * clone() const override
Clone this AnnualTimeZoneRule object polymorphically.
AnnualTimeZoneRule(const UnicodeString &name, int32_t rawOffset, int32_t dstSavings, const DateTimeRule &dateTimeRule, int32_t startYear, int32_t endYear)
Constructs a AnnualTimeZoneRule with the name, the GMT offset of its standard time,...
AnnualTimeZoneRule & operator=(const AnnualTimeZoneRule &right)
Assignment operator.
virtual UBool isEquivalentTo(const TimeZoneRule &that) const override
Returns if this rule represents the same rule and offsets as another.
int32_t getStartYear() const
Gets the first year when this rule takes effect.
const DateTimeRule * getRule() const
Gets the start date/time rule used by this rule.
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const override
Gets the very first time when this rule takes effect.
virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const override
Gets the final time when this rule takes effect.
static UClassID getStaticClassID()
Return the class ID for this class.
virtual bool operator==(const TimeZoneRule &that) const override
Return true if the given TimeZoneRule objects are semantically equal.
virtual bool operator!=(const TimeZoneRule &that) const override
Return true if the given TimeZoneRule objects are semantically unequal.
virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, UBool inclusive, UDate &result) const override
Gets the most recent time when this rule takes effect before the specified time.
AnnualTimeZoneRule(const AnnualTimeZoneRule &source)
Copy constructor.
DateTimeRule is a class representing a time in a year by a rule specified by month,...
Definition: dtrule.h:33
TimeRuleType
Time rule type constants.
Definition: dtrule.h:55
InitialTimeZoneRule represents a time zone rule representing a time zone effective from the beginning...
Definition: tzrule.h:202
InitialTimeZoneRule(const UnicodeString &name, int32_t rawOffset, int32_t dstSavings)
Constructs an InitialTimeZoneRule with the name, the GMT offset of its standard time and the amount o...
virtual bool operator==(const TimeZoneRule &that) const override
Return true if the given TimeZoneRule objects are semantically equal.
InitialTimeZoneRule & operator=(const InitialTimeZoneRule &right)
Assignment operator.
static UClassID getStaticClassID()
Return the class ID for this class.
virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, UBool inclusive, UDate &result) const override
Gets the first time when this rule takes effect after the specified time.
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
virtual InitialTimeZoneRule * clone() const override
Clone this InitialTimeZoneRule object polymorphically.
virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const override
Gets the final time when this rule takes effect.
virtual bool operator!=(const TimeZoneRule &that) const override
Return true if the given TimeZoneRule objects are semantically unequal.
virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, UBool inclusive, UDate &result) const override
Gets the most recent time when this rule takes effect before the specified time.
InitialTimeZoneRule(const InitialTimeZoneRule &source)
Copy constructor.
virtual ~InitialTimeZoneRule()
Destructor.
virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const override
Gets the very first time when this rule takes effect.
virtual UBool isEquivalentTo(const TimeZoneRule &that) const override
Returns if this rule represents the same rule and offsets as another.
TimeArrayTimeZoneRule represents a time zone rule whose start times are defined by an array of millis...
Definition: tzrule.h:606
virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, UBool inclusive, UDate &result) const override
Gets the first time when this rule takes effect after the specified time.
virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const override
Gets the final time when this rule takes effect.
virtual ~TimeArrayTimeZoneRule()
Destructor.
virtual TimeArrayTimeZoneRule * clone() const override
Clone this TimeArrayTimeZoneRule object polymorphically.
TimeArrayTimeZoneRule(const UnicodeString &name, int32_t rawOffset, int32_t dstSavings, const UDate *startTimes, int32_t numStartTimes, DateTimeRule::TimeRuleType timeRuleType)
Constructs a TimeArrayTimeZoneRule with the name, the GMT offset of its standard time,...
virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const override
Gets the very first time when this rule takes effect.
virtual UBool isEquivalentTo(const TimeZoneRule &that) const override
Returns if this rule represents the same rule and offsets as another.
virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, UBool inclusive, UDate &result) const override
Gets the most recent time when this rule takes effect before the specified time.
UBool getStartTimeAt(int32_t index, UDate &result) const
Gets a start time at the index stored in this rule.
virtual bool operator==(const TimeZoneRule &that) const override
Return true if the given TimeZoneRule objects are semantically equal.
DateTimeRule::TimeRuleType getTimeType() const
Gets the time type of the start times used by this rule.
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
int32_t countStartTimes() const
Returns the number of start times stored in this rule.
TimeArrayTimeZoneRule(const TimeArrayTimeZoneRule &source)
Copy constructor.
static UClassID getStaticClassID()
Return the class ID for this class.
virtual bool operator!=(const TimeZoneRule &that) const override
Return true if the given TimeZoneRule objects are semantically unequal.
TimeArrayTimeZoneRule & operator=(const TimeArrayTimeZoneRule &right)
Assignment operator.
TimeZoneRule is a class representing a rule for time zone.
Definition: tzrule.h:36
virtual UBool getFirstStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const =0
Gets the very first time when this rule takes effect.
int32_t getRawOffset() const
Gets the standard time offset.
UnicodeString & getName(UnicodeString &name) const
Fills in "name" with the name of this time zone.
TimeZoneRule(const UnicodeString &name, int32_t rawOffset, int32_t dstSavings)
Constructs a TimeZoneRule with the name, the GMT offset of its standard time and the amount of daylig...
virtual UBool getNextStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, UBool inclusive, UDate &result) const =0
Gets the first time when this rule takes effect after the specified time.
virtual bool operator!=(const TimeZoneRule &that) const
Return true if the given TimeZoneRule objects are semantically unequal.
virtual ~TimeZoneRule()
Destructor.
virtual UBool isEquivalentTo(const TimeZoneRule &other) const
Returns if this rule represents the same rule and offsets as another.
virtual UBool getPreviousStart(UDate base, int32_t prevRawOffset, int32_t prevDSTSavings, UBool inclusive, UDate &result) const =0
Gets the most recent time when this rule takes effect before the specified time.
virtual bool operator==(const TimeZoneRule &that) const
Return true if the given TimeZoneRule objects are semantically equal.
virtual TimeZoneRule * clone() const =0
Clone this TimeZoneRule object polymorphically.
virtual UBool getFinalStart(int32_t prevRawOffset, int32_t prevDSTSavings, UDate &result) const =0
Gets the final time when this rule takes effect.
TimeZoneRule(const TimeZoneRule &source)
Copy constructor.
int32_t getDSTSavings() const
Gets the amount of daylight saving delta time from the standard time.
TimeZoneRule & operator=(const TimeZoneRule &right)
Assignment operator.
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
C++ API: Rule for specifying date and time in an year.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316
double UDate
Date and Time data type.
Definition: utypes.h:218