6 #ifndef ACE_TIME_TIME_ZONE_H 7 #define ACE_TIME_TIME_ZONE_H 10 #include "TimeOffset.h" 11 #include "ZoneProcessor.h" 12 #include "ZoneProcessorCache.h" 13 #include "BasicZone.h" 14 #include "ExtendedZone.h" 15 #include "TimeZoneData.h" 21 template<
typename ZI,
typename ZR,
typename ZSC>
class ZoneManager;
84 static const uint8_t kTypeError = 0;
85 static const uint8_t kTypeManual = 1;
88 static const uint8_t kTypeBasicManaged =
89 ZoneProcessorCache::kTypeBasicManaged;
90 static const uint8_t kTypeExtendedManaged =
91 ZoneProcessorCache::kTypeExtendedManaged;
106 return TimeZone(stdOffset, dstOffset);
119 return TimeZone(kTypeBasic, zoneInfo, zoneProcessor);
132 return TimeZone(kTypeExtended, zoneInfo, zoneProcessor);
146 mStdOffsetMinutes(0),
147 mDstOffsetMinutes(0) {}
176 case kTypeBasicManaged:
179 case kTypeExtendedManaged:
186 bool isError()
const {
return mType == kTypeError; }
199 case kTypeBasicManaged:
200 case kTypeExtendedManaged:
204 if (! processor)
break;
224 case kTypeBasicManaged:
225 case kTypeExtendedManaged:
229 if (! processor)
break;
262 return (mDstOffsetMinutes != 0) ?
"DST" :
"STD";
267 case kTypeBasicManaged:
268 case kTypeExtendedManaged:
272 if (! processor)
break;
273 return processor->
getAbbrev(epochSeconds);
297 case kTypeBasicManaged:
298 case kTypeExtendedManaged:
302 if (! processor)
break;
312 if (mType != kTypeManual)
return false;
313 return mStdOffsetMinutes == 0 && mDstOffsetMinutes == 0;
324 if (mType != kTypeManual)
return false;
325 return mDstOffsetMinutes != 0;
333 if (mType != kTypeManual)
return;
334 mStdOffsetMinutes = stdOffset.
toMinutes();
342 if (mType != kTypeManual)
return;
343 mDstOffsetMinutes = dstOffset.
toMinutes();
355 case TimeZone::kTypeManual:
356 d.stdOffsetMinutes = mStdOffsetMinutes;
357 d.dstOffsetMinutes = mDstOffsetMinutes;
358 d.type = TimeZoneData::kTypeManual;
360 case TimeZone::kTypeBasic:
361 case TimeZone::kTypeExtended:
362 case TimeZone::kTypeBasicManaged:
363 case TimeZone::kTypeExtendedManaged:
365 d.type = TimeZoneData::kTypeZoneId;
368 d.type = TimeZoneData::kTypeError;
381 void printTo(Print& printer)
const;
400 template<
typename ZI,
typename ZR,
typename ZSC>
friend class ZoneManager;
409 explicit TimeZone(
const void* zoneInfo,
411 mType(zoneProcessorCache->
getType()),
423 mStdOffsetMinutes(stdOffset.
toMinutes()),
424 mDstOffsetMinutes(dstOffset.
toMinutes()) {}
431 explicit TimeZone(uint8_t type,
const void* zoneInfo,
447 int16_t mStdOffsetMinutes;
448 int16_t mDstOffsetMinutes;
470 if (a.mType != b.mType)
return false;
472 case TimeZone::kTypeError:
474 case TimeZone::kTypeManual:
475 return a.mStdOffsetMinutes == b.mStdOffsetMinutes
476 && a.mDstOffsetMinutes == b.mDstOffsetMinutes;
477 case TimeZone::kTypeBasic:
478 case TimeZone::kTypeExtended:
479 case TimeZone::kTypeBasicManaged:
480 case TimeZone::kTypeExtendedManaged:
void setDstOffset(TimeOffset dstOffset)
Sets the dstOffset of the TimeZone.
static TimeOffset forError()
Return an error indicator.
Base interface for ZoneProcessor classes.
virtual TimeOffset getDeltaOffset(acetime_t epochSeconds) const =0
Return the DST delta offset at epochSeconds.
bool isUtc() const
Return true if UTC (+00:00+00:00).
static OffsetDateTime forLocalDateTimeAndOffset(const LocalDateTime &localDateTime, TimeOffset timeOffset)
Factory method from LocalDateTime and TimeOffset.
Representation of a given time zone, implemented as an array of ZoneEra records.
static TimeZone forError()
Return a TimeZone representing an error condition.
A thin wrapper around a basic::ZoneInfo data structure to provide a stable API access to some useful ...
static const uint8_t kTypeExtended
Indicate ExtendedZoneProcessor.
virtual ZoneProcessor * getZoneProcessor(const void *zoneInfo)=0
Get ZoneProcessor from either a basic::ZoneInfo or an extended::ZoneInfo.
bool isDst() const
Return if mDstOffsetMinutes is not zero.
Representation of a given time zone, implemented as an array of ZoneEra records.
void printShortTo(Print &printer) const
Print the short human readable representation of the time zone.
OffsetDateTime getOffsetDateTime(const LocalDateTime &ldt) const
Return the best estimate of the OffsetDateTime at the given LocalDateTime for the current TimeZone...
static TimeZone forZoneInfo(const basic::ZoneInfo *zoneInfo, BasicZoneProcessor *zoneProcessor)
Factory method to create from a zoneInfo and an associated BasicZoneProcessor.
void setStdOffset(TimeOffset stdOffset)
Sets the stdOffset of the TimeZone.
const void * mZoneInfo
Used by kTypeBasic, kTypeExtended, kTypeBasicManaged, kTypeExtendedManaged.
TimeOffset getDstOffset() const
Return the DST TimeOffset.
void printTo(Print &printer) const
Print the human readable representation of the time zone.
uint32_t getZoneId() const
Return the zoneId for kTypeBasic, kTypeExtended, kTypeBasicManaged, kTypeExtendedManaged.
virtual TimeOffset getUtcOffset(acetime_t epochSeconds) const =0
Return the total UTC offset at epochSeconds, including DST offset.
virtual void setZoneInfo(const void *zoneInfo)=0
Set the opaque zoneInfo.
TimeZone()
Default constructor creates a UTC TimeZone.
virtual const char * getAbbrev(acetime_t epochSeconds) const =0
Return the time zone abbreviation at epochSeconds.
int16_t toMinutes() const
Return the time offset as minutes.
virtual uint8_t getType()=0
Return the type of this cache.
An implementation of ZoneProcessor that supports for all zones defined by the TZ Database.
const char * getAbbrev(acetime_t epochSeconds) const
Return the time zone abbreviation at the given epochSeconds.
Returns the TimeZone given the zoneInfo, zoneName, or zoneId.
static TimeZone forUtc()
Factory method to create a UTC TimeZone.
A thin wrapper around an extended::ZoneInfo data structure to provide a stable API access to some use...
An implementation of ZoneProcessor that supports a subset of the zones containing in the TZ Database...
static TimeZone forZoneInfo(const extended::ZoneInfo *zoneInfo, ExtendedZoneProcessor *zoneProcessor)
Factory method to create from a zoneInfo and an associated ExtendedZoneProcessor. ...
The date (year, month, day), time (hour, minute, second) and offset from UTC (timeOffset).
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC...
static TimeZone forTimeOffset(TimeOffset stdOffset, TimeOffset dstOffset=TimeOffset())
Factory method to create from a UTC offset and an optional DST offset.
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
Common interface to BasicZoneProcessorCache and ExtendedZoneProcessorCache.
Class that describes a time zone.
TimeZoneData toTimeZoneData() const
Convert to a TimeZoneData object, which can be fed back into ZoneManager::createForTimeZoneData() to ...
Data structure that captures the internal state of a TimeZone object with enough information so that ...
uint8_t getType() const
Return the type of TimeZone.
TimeOffset getStdOffset() const
Return the Standard TimeOffset.
ZoneProcessor * mZoneProcessor
Used by kTypeBasic, kTypeExtended.
static const uint8_t kTypeBasic
Indicate BasicZoneProcessor.
bool isError() const
Return true if TimeZone is an error.
virtual OffsetDateTime getOffsetDateTime(const LocalDateTime &ldt) const =0
Return the best estimate of the OffsetDateTime at the given LocalDateTime for the timezone of the cur...
ZoneProcessorCache * mZoneProcessorCache
Used by kTypeBasicManaged, kTypeExtendedManaged.
static OffsetDateTime forError()
Factory method that returns an instance whose isError() is true.
uint32_t zoneId
All of kTypeBasic, kTypeExtended, kTypeBasicManaged, kTypeExtendedManaged collapse down to a kTypeZon...
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
TimeOffset getUtcOffset(acetime_t epochSeconds) const
Return the total UTC offset at epochSeconds, including DST offset.
TimeOffset getDeltaOffset(acetime_t epochSeconds) const
Return the DST offset from standard UTC offset at epochSeconds.