AceTime
1.3
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
|
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"
86 static const uint8_t kTypeError = 0;
87 static const uint8_t kTypeManual = 1;
90 static const uint8_t kTypeBasicManaged =
91 ZoneProcessorCache::kTypeBasicManaged;
92 static const uint8_t kTypeExtendedManaged =
93 ZoneProcessorCache::kTypeExtendedManaged;
108 return TimeZone(stdOffset, dstOffset);
121 return TimeZone(kTypeBasic, zoneInfo, zoneProcessor);
134 return TimeZone(kTypeExtended, zoneInfo, zoneProcessor);
148 mStdOffsetMinutes(0),
149 mDstOffsetMinutes(0) {}
178 case kTypeBasicManaged:
181 case kTypeExtendedManaged:
188 bool isError()
const {
return mType == kTypeError; }
201 case kTypeBasicManaged:
202 case kTypeExtendedManaged:
206 if (! processor)
break;
226 case kTypeBasicManaged:
227 case kTypeExtendedManaged:
231 if (! processor)
break;
264 return (mDstOffsetMinutes != 0) ?
"DST" :
"STD";
269 case kTypeBasicManaged:
270 case kTypeExtendedManaged:
274 if (! processor)
break;
275 return processor->
getAbbrev(epochSeconds);
299 case kTypeBasicManaged:
300 case kTypeExtendedManaged:
304 if (! processor)
break;
314 if (mType != kTypeManual)
return false;
315 return mStdOffsetMinutes == 0 && mDstOffsetMinutes == 0;
326 if (mType != kTypeManual)
return false;
327 return mDstOffsetMinutes != 0;
335 if (mType != kTypeManual)
return;
336 mStdOffsetMinutes = stdOffset.
toMinutes();
344 if (mType != kTypeManual)
return;
345 mDstOffsetMinutes = dstOffset.
toMinutes();
357 case TimeZone::kTypeManual:
358 d.stdOffsetMinutes = mStdOffsetMinutes;
359 d.dstOffsetMinutes = mDstOffsetMinutes;
360 d.type = TimeZoneData::kTypeManual;
362 case TimeZone::kTypeBasic:
363 case TimeZone::kTypeExtended:
364 case TimeZone::kTypeBasicManaged:
365 case TimeZone::kTypeExtendedManaged:
367 d.type = TimeZoneData::kTypeZoneId;
370 d.type = TimeZoneData::kTypeError;
383 void printTo(Print& printer)
const;
402 template<
typename ZI,
typename ZR,
typename ZSC>
412 explicit TimeZone(
const void* zoneInfo,
414 mType(zoneProcessorCache->
getType()),
424 explicit TimeZone(TimeOffset stdOffset, TimeOffset dstOffset):
426 mStdOffsetMinutes(stdOffset.toMinutes()),
427 mDstOffsetMinutes(dstOffset.toMinutes()) {}
434 explicit TimeZone(uint8_t type,
const void* zoneInfo,
450 int16_t mStdOffsetMinutes;
451 int16_t mDstOffsetMinutes;
472 inline bool operator==(
const TimeZone& a,
const TimeZone& b) {
473 if (a.mType != b.mType)
return false;
475 case TimeZone::kTypeError:
477 case TimeZone::kTypeManual:
478 return a.mStdOffsetMinutes == b.mStdOffsetMinutes
479 && a.mDstOffsetMinutes == b.mDstOffsetMinutes;
480 case TimeZone::kTypeBasic:
481 case TimeZone::kTypeExtended:
482 case TimeZone::kTypeBasicManaged:
483 case TimeZone::kTypeExtendedManaged:
484 return (a.mZoneInfo == b.mZoneInfo);
490 inline bool operator!=(
const TimeZone& a,
const TimeZone& b) {
virtual ZoneProcessor * getZoneProcessor(const void *zoneInfo)=0
Get ZoneProcessor from either a basic::ZoneInfo or an extended::ZoneInfo.
static TimeZone forZoneInfo(const basic::ZoneInfo *zoneInfo, BasicZoneProcessor *zoneProcessor)
Factory method to create from a zoneInfo and an associated BasicZoneProcessor.
void printTo(Print &printer) const
Print the human readable representation of the time zone.
static TimeZone forUtc()
Factory method to create a UTC TimeZone.
virtual void setZoneInfo(const void *zoneInfo)=0
Set the opaque zoneInfo.
ZoneProcessor * mZoneProcessor
Used by kTypeBasic, kTypeExtended.
static const uint8_t kTypeBasic
Indicate BasicZoneProcessor.
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
static TimeOffset forError()
Return an error indicator.
static const uint8_t kTypeExtended
Indicate ExtendedZoneProcessor.
bool isUtc() const
Return true if UTC (+00:00+00:00).
const void * mZoneInfo
Used by kTypeBasic, kTypeExtended, kTypeBasicManaged, kTypeExtendedManaged.
TimeOffset getStdOffset() const
Return the Standard TimeOffset.
uint8_t getType() const
Return the type of TimeZone.
void setDstOffset(TimeOffset dstOffset)
Sets the dstOffset of the TimeZone.
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
A thin wrapper around an extended::ZoneInfo data structure to provide a stable API access to some use...
static TimeZone forError()
Return a TimeZone representing an error condition.
virtual TimeOffset getDeltaOffset(acetime_t epochSeconds) const =0
Return the DST delta offset at epochSeconds.
A thin wrapper around a basic::ZoneInfo data structure to provide a stable API access to some useful ...
TimeOffset getUtcOffset(acetime_t epochSeconds) const
Return the total UTC offset at epochSeconds, including DST offset.
int16_t toMinutes() const
Return the time offset as minutes.
void printShortTo(Print &printer) const
Print the short human readable representation of the time zone.
void setStdOffset(TimeOffset stdOffset)
Sets the stdOffset of the TimeZone.
An implementation of ZoneProcessor that supports for all zones defined by the TZ Database.
OffsetDateTime getOffsetDateTime(const LocalDateTime &ldt) const
Return the best estimate of the OffsetDateTime at the given LocalDateTime for the current TimeZone.
bool isError() const
Return true if TimeZone is an error.
The date (year, month, day), time (hour, minute, second) and offset from UTC (timeOffset).
virtual const char * getAbbrev(acetime_t epochSeconds) const =0
Return the time zone abbreviation at epochSeconds.
const char * getAbbrev(acetime_t epochSeconds) const
Return the time zone abbreviation at the given epochSeconds.
Base interface for ZoneProcessor classes.
TimeZoneData toTimeZoneData() const
Convert to a TimeZoneData object, which can be fed back into ZoneManager::createForTimeZoneData() to ...
static OffsetDateTime forError()
Factory method that returns an instance whose isError() is true.
bool isDst() const
Return if mDstOffsetMinutes is not zero.
static TimeZone forZoneInfo(const extended::ZoneInfo *zoneInfo, ExtendedZoneProcessor *zoneProcessor)
Factory method to create from a zoneInfo and an associated ExtendedZoneProcessor.
virtual TimeOffset getUtcOffset(acetime_t epochSeconds) const =0
Return the total UTC offset at epochSeconds, including DST offset.
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
uint32_t getZoneId() const
Return the zoneId for kTypeBasic, kTypeExtended, kTypeBasicManaged, kTypeExtendedManaged.
Common interface to BasicZoneProcessorCache and ExtendedZoneProcessorCache.
ZoneProcessorCache * mZoneProcessorCache
Used by kTypeBasicManaged, kTypeExtendedManaged.
Data structure that captures the internal state of a TimeZone object with enough information so that ...
static OffsetDateTime forLocalDateTimeAndOffset(const LocalDateTime &localDateTime, TimeOffset timeOffset)
Factory method from LocalDateTime and TimeOffset.
A templatized implementation of ZoneManager that binds the (Basic|Extended)ZoneRegistrar with the cor...
Class that describes a time zone.
static TimeZone forTimeOffset(TimeOffset stdOffset, TimeOffset dstOffset=TimeOffset())
Factory method to create from a UTC offset and an optional DST offset.
An implementation of ZoneProcessor that supports a subset of the zones containing in the TZ Database.
uint32_t zoneId
All of kTypeBasic, kTypeExtended, kTypeBasicManaged, kTypeExtendedManaged collapse down to a kTypeZon...
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...
TimeOffset getDeltaOffset(acetime_t epochSeconds) const
Return the DST offset from standard UTC offset at epochSeconds.
TimeOffset getDstOffset() const
Return the DST TimeOffset.
TimeZone()
Default constructor creates a UTC TimeZone.