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;
254 case kTypeBasicManaged:
255 case kTypeExtendedManaged:
259 if (! processor)
break;
269 if (mType != kTypeManual)
return false;
270 return mStdOffsetMinutes == 0 && mDstOffsetMinutes == 0;
281 if (mType != kTypeManual)
return false;
282 return mDstOffsetMinutes != 0;
290 if (mType != kTypeManual)
return;
291 mStdOffsetMinutes = stdOffset.
toMinutes();
299 if (mType != kTypeManual)
return;
300 mDstOffsetMinutes = dstOffset.
toMinutes();
312 case TimeZone::kTypeManual:
313 d.stdOffsetMinutes = mStdOffsetMinutes;
314 d.dstOffsetMinutes = mDstOffsetMinutes;
315 d.type = TimeZoneData::kTypeManual;
317 case TimeZone::kTypeBasic:
318 case TimeZone::kTypeExtended:
319 case TimeZone::kTypeBasicManaged:
320 case TimeZone::kTypeExtendedManaged:
322 d.type = TimeZoneData::kTypeZoneId;
325 d.type = TimeZoneData::kTypeError;
338 void printTo(Print& printer)
const;
354 void printAbbrevTo(Print& printer, acetime_t epochSeconds)
const;
365 template<
typename ZI,
typename ZR,
typename ZSC>
friend class ZoneManager;
374 explicit TimeZone(
const void* zoneInfo,
376 mType(zoneProcessorCache->
getType()),
388 mStdOffsetMinutes(stdOffset.
toMinutes()),
389 mDstOffsetMinutes(dstOffset.
toMinutes()) {}
396 explicit TimeZone(uint8_t type,
const void* zoneInfo,
412 int16_t mStdOffsetMinutes;
413 int16_t mDstOffsetMinutes;
435 if (a.mType != b.mType)
return false;
437 case TimeZone::kTypeError:
439 case TimeZone::kTypeManual:
440 return a.mStdOffsetMinutes == b.mStdOffsetMinutes
441 && a.mDstOffsetMinutes == b.mDstOffsetMinutes;
442 case TimeZone::kTypeBasic:
443 case TimeZone::kTypeExtended:
444 case TimeZone::kTypeBasicManaged:
445 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.
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.
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.
void printAbbrevTo(Print &printer, acetime_t epochSeconds) const
Print the time zone abbreviation for the given epochSeconds.
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.