AceTime
1.11.2
Date and time classes for Arduino that support timezones from the TZ Database.
|
6 #ifndef ACE_TIME_TIME_ZONE_H
7 #define ACE_TIME_TIME_ZONE_H
10 #include "TimeOffset.h"
11 #include "ZoneProcessor.h"
12 #include "BasicZoneProcessor.h"
13 #include "ExtendedZoneProcessor.h"
14 #include "TimeZoneData.h"
118 return TimeZone(stdOffset, dstOffset);
174 const basic::ZoneInfo* zoneInfo,
179 (uintptr_t) zoneInfo,
193 const extended::ZoneInfo* zoneInfo,
198 (uintptr_t) zoneInfo,
223 mStdOffsetMinutes(0),
224 mDstOffsetMinutes(0) {}
254 return getBoundZoneProcessor()->
isLink();
275 return getBoundZoneProcessor()->
getZoneId(followLink);
295 return getBoundZoneProcessor()->
getUtcOffset(epochSeconds);
347 return (mDstOffsetMinutes != 0) ?
"DST" :
"STD";
351 return getBoundZoneProcessor()->
getAbbrev(epochSeconds);
409 return mStdOffsetMinutes == 0 && mDstOffsetMinutes == 0;
421 return mDstOffsetMinutes != 0;
430 mStdOffsetMinutes = stdOffset.
toMinutes();
439 mDstOffsetMinutes = dstOffset.
toMinutes();
453 d.type = TimeZoneData::kTypeError;
457 d.stdOffsetMinutes = mStdOffsetMinutes;
458 d.dstOffsetMinutes = mDstOffsetMinutes;
459 d.type = TimeZoneData::kTypeManual;
464 d.type = TimeZoneData::kTypeZoneId;
479 void printTo(Print& printer,
bool followLink =
false)
const;
499 void printShortTo(Print& printer,
bool followLink =
false)
const;
516 mStdOffsetMinutes(stdOffset.toMinutes()),
517 mDstOffsetMinutes(dstOffset.toMinutes()) {}
527 ZoneProcessor* zoneProcessor
541 ZoneProcessor* getBoundZoneProcessor()
const {
555 int16_t mStdOffsetMinutes;
556 int16_t mDstOffsetMinutes;
582 inline bool operator==(
const TimeZone& a,
const TimeZone& b) {
583 if (a.mType != b.mType)
return false;
590 return a.mStdOffsetMinutes == b.mStdOffsetMinutes
591 && a.mDstOffsetMinutes == b.mDstOffsetMinutes;
594 return (a.mZoneKey == b.mZoneKey);
598 inline bool operator!=(
const TimeZone& a,
const TimeZone& b) {
TimeZoneData toTimeZoneData(bool followLink=false) const
Convert to a TimeZoneData object, which can be fed back into ZoneManager::createForTimeZoneData() to ...
uintptr_t mZoneKey
An opaque zone key.
static TimeZone forZoneInfo(const basic::ZoneInfo *zoneInfo, BasicZoneProcessor *zoneProcessor)
Convenience factory method to create from a zoneInfo and an associated BasicZoneProcessor.
static TimeZone forUtc()
Factory method to create a UTC TimeZone.
ZoneProcessor * mZoneProcessor
An instance of a ZoneProcessor, for example, BasicZoneProcessor or ExtendedZoneProcessor.
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
static TimeOffset forError()
Return an error indicator.
virtual void setZoneKey(uintptr_t zoneKey)=0
Set the opaque zoneKey of this object to a new value, reseting any internally cached information.
bool isUtc() const
Return true if UTC (+00:00+00:00).
OffsetDateTime getOffsetDateTime(acetime_t epochSeconds) const
Return the best estimate of the OffsetDateTime at the given epochSeconds.
TimeOffset getStdOffset() const
Return the Standard TimeOffset.
uint8_t getType() const
Return the type of TimeZone, used to determine the behavior of certain methods at runtime.
void setDstOffset(TimeOffset dstOffset)
Sets the dstOffset of the TimeZone.
static const uint8_t kTypeManual
Manual STD offset and DST offset.
uint8_t getType() const
Return the kTypeXxx of the current instance.
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
static TimeZone forHours(int8_t stdHours, int8_t dstHours=0)
Factory method to create from UTC hour offset and optional DST hour offset.
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.
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 setStdOffset(TimeOffset stdOffset)
Sets the stdOffset of the TimeZone.
A specific implementation of ExtendedZoneProcessorTemplate that uses ZoneXxxBrokers which read from z...
OffsetDateTime getOffsetDateTime(const LocalDateTime &ldt) const
Return the best estimate of the OffsetDateTime at the given LocalDateTime for the current TimeZone.
virtual bool isLink() const =0
Return true if timezone is a Link entry pointing to a Zone entry.
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.
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)
Convenience factory method to create from a zoneInfo and an associated ExtendedZoneProcessor.
uint32_t getZoneId(bool followLink=false) const
Return the zoneId for kTypeBasic, kTypeExtended.
virtual TimeOffset getUtcOffset(acetime_t epochSeconds) const =0
Return the total UTC offset at epochSeconds, including DST offset.
static const uint8_t kTypeReserved
Reserved for future use.
static TimeOffset forHourMinute(int8_t hour, int8_t minute)
Create TimeOffset from (hour, minute) offset.
static const uint8_t kTypeError
A TimeZone that represents an invalid condition.
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
void printTo(Print &printer, bool followLink=false) const
Print the text representation of the time zone using the full canonical time zone name or UTC offset ...
static TimeZone forHourMinute(int8_t stdHour, int8_t stdMinute, int8_t dstHour=0, int8_t dstMinute=0)
Factory method to create from UTC (hour, minute) pair and optional DST (hour, minute) pair.
void printShortTo(Print &printer, bool followLink=false) const
Print the short human readable representation of the time zone.
Data structure that captures the internal state of a TimeZone object with enough information so that ...
virtual uint32_t getZoneId(bool followLink=false) const =0
Return the unique stable zoneId.
static OffsetDateTime forLocalDateTimeAndOffset(const LocalDateTime &localDateTime, TimeOffset timeOffset)
Factory method from LocalDateTime and TimeOffset.
bool isLink() const
Return true if timezone is a Link entry pointing to a Zone entry.
static TimeOffset forHours(int8_t hours)
Create TimeOffset with the corresponding hour offset.
static TimeZone forMinutes(int8_t stdMinutes, int8_t dstMinutes=0)
Factory method to create from UTC minute offset and optional DST minute offset.
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.
A specific implementation of BasicZoneProcessorTemplate that uses ZoneXxxBrokers which read from zone...
uint32_t zoneId
Both TimeZone::kTypeBasic and TimeZone::kTypeExtended are mapped to a TimeZoneData::kTypeZoneId.
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.
static TimeZone forZoneKey(uintptr_t zoneKey, ZoneProcessor *processor)
Factory method to create from a generic zoneKey and a generic zoneProcessor.
static OffsetDateTime forEpochSeconds(acetime_t epochSeconds, TimeOffset timeOffset, uint8_t fold=0)
Factory method.