simpletz.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
********************************************************************************
* Copyright (C) 1997-2013, International Business Machines *
* Corporation and others. All Rights Reserved. *
********************************************************************************
*
* File SIMPLETZ.H
*
* Modification History:
*
* Date Name Description
* 04/21/97 aliu Overhauled header.
* 08/10/98 stephen JDK 1.2 sync
* Added setStartRule() / setEndRule() overloads
* Added hasSameRules()
* 09/02/98 stephen Added getOffset(monthLen)
* Changed getOffset() to take UErrorCode
* 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
* 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
* methods that take TimeMode. Added to docs.
********************************************************************************
*/
#ifndef SIMPLETZ_H
#define SIMPLETZ_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/basictz.h"
U_NAMESPACE_BEGIN
// forward declaration
class InitialTimeZoneRule;
class TimeZoneTransition;
class AnnualTimeZoneRule;
class U_I18N_API SimpleTimeZone: public BasicTimeZone {
public:
enum TimeMode {
WALL_TIME = 0,
STANDARD_TIME,
UTC_TIME
};
SimpleTimeZone(const SimpleTimeZone& source);
SimpleTimeZone& operator=(const SimpleTimeZone& right);
virtual ~SimpleTimeZone();
virtual bool operator==(const TimeZone& that) const override;
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID);
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
UErrorCode& status);
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
int32_t savingsDST, UErrorCode& status);
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
TimeMode savingsStartTimeMode,
int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode,
int32_t savingsDST, UErrorCode& status);
void setStartYear(int32_t year);
void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
int32_t time, UErrorCode& status);
void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
int32_t time, TimeMode mode, UErrorCode& status);
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
UErrorCode& status);
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
TimeMode mode, UErrorCode& status);
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
int32_t time, UBool after, UErrorCode& status);
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
int32_t time, TimeMode mode, UBool after, UErrorCode& status);
void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
int32_t time, UErrorCode& status);
void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
int32_t time, TimeMode mode, UErrorCode& status);
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status);
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time,
TimeMode mode, UErrorCode& status);
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
int32_t time, UBool after, UErrorCode& status);
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
int32_t time, TimeMode mode, UBool after, UErrorCode& status);
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const override;
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
uint8_t dayOfWeek, int32_t milliseconds,
int32_t monthLength, UErrorCode& status) const override;
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
uint8_t dayOfWeek, int32_t milliseconds,
int32_t monthLength, int32_t prevMonthLength,
UErrorCode& status) const;
virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
int32_t& dstOffset, UErrorCode& ec) const override;
virtual void getOffsetFromLocal(
UDate date, UTimeZoneLocalOption nonExistingTimeOpt,
UTimeZoneLocalOption duplicatedTimeOpt,
int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const override;
virtual int32_t getRawOffset() const override;
virtual void setRawOffset(int32_t offsetMillis) override;
void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
virtual int32_t getDSTSavings() const override;
virtual UBool useDaylightTime() const override;
#ifndef U_FORCE_HIDE_DEPRECATED_API
virtual UBool inDaylightTime(UDate date, UErrorCode& status) const override;
#endif // U_FORCE_HIDE_DEPRECATED_API
UBool hasSameRules(const TimeZone& other) const override;
virtual SimpleTimeZone* clone() const override;
virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const override;
virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const override;
virtual int32_t countTransitionRules(UErrorCode& status) const override;
virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const override;
public:
virtual UClassID getDynamicClassID() const override;
static UClassID U_EXPORT2 getStaticClassID();
private:
enum EMode
{
DOM_MODE = 1,
DOW_IN_MONTH_MODE,
DOW_GE_DOM_MODE,
DOW_LE_DOM_MODE
};
SimpleTimeZone() = delete; // default constructor not implemented
void construct(int32_t rawOffsetGMT,
int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
int32_t startTime, TimeMode startTimeMode,
int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
int32_t endTime, TimeMode endTimeMode,
int32_t dstSavings, UErrorCode& status);
static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
int8_t dayOfMonth,
int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
int8_t ruleDay, int32_t ruleMillis);
void decodeRules(UErrorCode& status);
void decodeStartRule(UErrorCode& status);
void decodeEndRule(UErrorCode& status);
int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts
int32_t startTime;
TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
int32_t endTime;
int32_t startYear; // the year these DST rules took effect
int32_t rawOffset; // the TimeZone's raw GMT offset
UBool useDaylight; // flag indicating whether this TimeZone uses DST
static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
EMode startMode, endMode; // flags indicating what kind of rules the DST rules are
int32_t dstSavings;
/* Private for BasicTimeZone implementation */
void checkTransitionRules(UErrorCode& status) const;
void initTransitionRules(UErrorCode& status);
void clearTransitionRules();
void deleteTransitionRules();
UBool transitionRulesInitialized;
InitialTimeZoneRule* initialRule;
TimeZoneTransition* firstTransition;
AnnualTimeZoneRule* stdRule;
AnnualTimeZoneRule* dstRule;
};
inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
int32_t dayOfWeek,
int32_t time, UErrorCode& status) {
setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
}
inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
int32_t time,
UErrorCode& status) {
setStartRule(month, dayOfMonth, time, WALL_TIME, status);
}
inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
int32_t dayOfWeek,
int32_t time, UBool after, UErrorCode& status) {
setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
}
inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
int32_t dayOfWeek,
int32_t time, UErrorCode& status) {
setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
}
inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
int32_t time, UErrorCode& status) {
setEndRule(month, dayOfMonth, time, WALL_TIME, status);
}
inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
int32_t time, UBool after, UErrorCode& status) {
setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
}
inline void
SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
int32_t& dstOffsetRef, UErrorCode& ec) const {
TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // _SIMPLETZ
basictz.h
C++ API: ICU TimeZone base class.
icu::AnnualTimeZoneRule
AnnualTimeZoneRule is a class used for representing a time zone rule which takes effect annually.
Definition tzrule.h:366
icu::BasicTimeZone
BasicTimeZone is an abstract class extending TimeZone.
Definition basictz.h:38
icu::InitialTimeZoneRule
InitialTimeZoneRule represents a time zone rule representing a time zone effective from the beginning...
Definition tzrule.h:202
icu::LocalPointerBase
"Smart pointer" base class; do not use directly: use LocalPointer etc.
Definition localpointer.h:68
icu::SimpleTimeZone
SimpleTimeZone is a concrete subclass of TimeZone that represents a time zone for use with a Gregoria...
Definition simpletz.h:65
icu::SimpleTimeZone::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::SimpleTimeZone::SimpleTimeZone
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString &ID, int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, int8_t savingsStartDayOfWeek, int32_t savingsStartTime, int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, int8_t savingsEndDayOfWeek, int32_t savingsEndTime, int32_t savingsDST, UErrorCode &status)
Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, and times to start and end da...
icu::SimpleTimeZone::TimeMode
TimeMode
TimeMode is used, together with a millisecond offset after midnight, to specify a rule transition tim...
Definition simpletz.h:79
icu::SimpleTimeZone::setStartYear
void setStartYear(int32_t year)
Sets the daylight savings starting year, that is, the year this time zone began observing its specifi...
icu::SimpleTimeZone::getRawOffset
virtual int32_t getRawOffset() const override
Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add to GMT to get local ti...
icu::SimpleTimeZone::operator==
virtual bool operator==(const TimeZone &that) const override
Returns true if the two TimeZone objects are equal; that is, they have the same ID,...
icu::SimpleTimeZone::useDaylightTime
virtual UBool useDaylightTime() const override
Queries if this TimeZone uses Daylight Savings Time.
icu::SimpleTimeZone::inDaylightTime
virtual UBool inDaylightTime(UDate date, UErrorCode &status) const override
Returns true if the given date is within the period when daylight savings time is in effect; false ot...
icu::SimpleTimeZone::countTransitionRules
virtual int32_t countTransitionRules(UErrorCode &status) const override
Returns the number of TimeZoneRules which represents time transitions, for this time zone,...
icu::SimpleTimeZone::getOffset
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, uint8_t dayOfWeek, int32_t milliseconds, int32_t monthLength, int32_t prevMonthLength, UErrorCode &status) const
Gets the time zone offset, for current date, modified in case of daylight savings.
icu::SimpleTimeZone::setEndRule
void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, int32_t time, TimeMode mode, UErrorCode &status)
Sets the daylight savings ending rule.
icu::SimpleTimeZone::getOffsetFromLocal
virtual void getOffsetFromLocal(UDate date, UTimeZoneLocalOption nonExistingTimeOpt, UTimeZoneLocalOption duplicatedTimeOpt, int32_t &rawOffset, int32_t &dstOffset, UErrorCode &status) const override
Get time zone offsets from local wall time.
icu::SimpleTimeZone::getTimeZoneRules
virtual void getTimeZoneRules(const InitialTimeZoneRule *&initial, const TimeZoneRule *trsrules[], int32_t &trscount, UErrorCode &status) const override
Gets the InitialTimeZoneRule and the set of TimeZoneRule which represent time transitions for this ti...
icu::SimpleTimeZone::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Override TimeZone Returns a unique class ID POLYMORPHICALLY.
icu::SimpleTimeZone::getOffset
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, uint8_t dayOfWeek, int32_t milliseconds, int32_t monthLength, UErrorCode &status) const override
Gets the time zone offset, for current date, modified in case of daylight savings.
icu::SimpleTimeZone::getPreviousTransition
virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition &result) const override
Gets the most recent time zone transition before the base time.
icu::SimpleTimeZone::operator=
SimpleTimeZone & operator=(const SimpleTimeZone &right)
Default assignment operator.
icu::SimpleTimeZone::SimpleTimeZone
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString &ID, int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, int8_t savingsStartDayOfWeek, int32_t savingsStartTime, TimeMode savingsStartTimeMode, int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode, int32_t savingsDST, UErrorCode &status)
Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, and times to start and end da...
icu::SimpleTimeZone::getNextTransition
virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition &result) const override
Gets the first time zone transition after the base time.
icu::SimpleTimeZone::getOffset
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, uint8_t dayOfWeek, int32_t millis, UErrorCode &status) const override
Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add to GMT to get loc...
icu::SimpleTimeZone::setStartRule
void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, int32_t time, TimeMode mode, UErrorCode &status)
Sets the daylight savings starting rule.
icu::SimpleTimeZone::setEndRule
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, TimeMode mode, UErrorCode &status)
Sets the DST end rule to a fixed date within a month.
icu::SimpleTimeZone::setDSTSavings
void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode &status)
Sets the amount of time in ms that the clock is advanced during DST.
icu::SimpleTimeZone::SimpleTimeZone
SimpleTimeZone(const SimpleTimeZone &source)
Copy constructor.
icu::SimpleTimeZone::setRawOffset
virtual void setRawOffset(int32_t offsetMillis) override
Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add to GMT to get local time,...
icu::SimpleTimeZone::~SimpleTimeZone
virtual ~SimpleTimeZone()
Destructor.
icu::SimpleTimeZone::setEndRule
void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, int32_t time, TimeMode mode, UBool after, UErrorCode &status)
Sets the DST end rule to a weekday before or after a give date within a month, e.g....
icu::SimpleTimeZone::clone
virtual SimpleTimeZone * clone() const override
Clones TimeZone objects polymorphically.
icu::SimpleTimeZone::hasSameRules
UBool hasSameRules(const TimeZone &other) const override
Return true if this zone has the same rules and offset as another zone.
icu::SimpleTimeZone::SimpleTimeZone
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString &ID)
Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID, and which doesn't observe...
icu::SimpleTimeZone::setStartRule
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, int32_t time, TimeMode mode, UBool after, UErrorCode &status)
Sets the DST start rule to a weekday before or after a give date within a month, e....
icu::SimpleTimeZone::SimpleTimeZone
SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString &ID, int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, int8_t savingsStartDayOfWeek, int32_t savingsStartTime, int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, int8_t savingsEndDayOfWeek, int32_t savingsEndTime, UErrorCode &status)
Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, and times to start and end da...
icu::SimpleTimeZone::setStartRule
void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time, TimeMode mode, UErrorCode &status)
Sets the DST start rule to a fixed date within a month.
icu::SimpleTimeZone::getDSTSavings
virtual int32_t getDSTSavings() const override
Returns the amount of time in ms that the clock is advanced during DST.
icu::TimeZoneRule
TimeZoneRule is a class representing a rule for time zone.
Definition tzrule.h:36
icu::TimeZoneTransition
TimeZoneTransition is a class representing a time zone transition.
Definition tztrans.h:35
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:133
icu::TimeZone::getOffset
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, uint8_t dayOfWeek, int32_t millis, UErrorCode &status) const =0
Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add to GMT to get loc...
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
UTimeZoneLocalOption
UTimeZoneLocalOption
Options used by ucal_getTimeZoneOffsetFromLocal and BasicTimeZone::getOffsetFromLocal() to specify ho...
Definition ucal.h:1682
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:430
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316
UDate
double UDate
Date and Time data type.
Definition utypes.h:218