AceTime
1.2
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"
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()),
421 explicit TimeZone(TimeOffset stdOffset, TimeOffset dstOffset):
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;
469 inline bool operator==(
const TimeZone& a,
const TimeZone& b) {
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:
481 return (a.mZoneInfo == b.mZoneInfo);
487 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.
Returns the TimeZone given the zoneInfo, zoneName, or zoneId.
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.
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.