1 #ifndef ACE_TIME_OFFSET_DATE_TIME_H 2 #define ACE_TIME_OFFSET_DATE_TIME_H 5 #include "TimeOffset.h" 6 #include "LocalDateTime.h" 118 char buffer[kDateStringLength + 2];
119 strncpy_P(buffer, (
const char*) dateString,
sizeof(buffer));
120 buffer[kDateStringLength + 1] = 0;
123 size_t len = strlen(buffer);
124 if (len > kDateStringLength) {
146 int16_t
year()
const {
return mLocalDateTime.
year(); }
149 void year(int16_t year) { mLocalDateTime.
year(year); }
164 uint8_t
day()
const {
return mLocalDateTime.
day(); }
167 void day(uint8_t day) { mLocalDateTime.
day(day); }
170 uint8_t
hour()
const {
return mLocalDateTime.
hour(); }
173 void hour(uint8_t hour) { mLocalDateTime.
hour(hour); }
215 void printTo(Print& printer)
const;
229 if (timeOffset >= 86400)
return epochDays + 1;
230 if (timeOffset < 0)
return epochDays - 1;
270 if (thisSeconds < thatSeconds)
return -1;
271 if (thisSeconds > thatSeconds)
return 1;
285 static const uint8_t kDateStringLength = 25;
294 static OffsetDateTime forDateStringChainable(
const char*& dateString);
311 uint8_t hour, uint8_t minute, uint8_t second,
313 mLocalDateTime(year, month, day, hour, minute, second),
319 mTimeOffset(timeOffset) {}
331 return a.mLocalDateTime == b.mLocalDateTime
332 && a.mTimeOffset == b.mTimeOffset;
static const acetime_t kSecondsSinceUnixEpoch
Number of seconds from Unix epoch (1970-01-01 00:00:00Z) to the AceTime epoch (2000-01-01 00:00:00Z)...
static TimeOffset forError()
Return an error indicator.
uint8_t hour() const
Return the hour.
static const acetime_t kDaysSinceUnixEpoch
Number of days from Unix epoch (1970-01-01 00:00:00Z) to the AceTime epoch (2000-01-01 00:00:00Z)...
void minute(uint8_t minute)
Set the minute.
uint8_t month() const
Return the month with January=1, December=12.
static const acetime_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).
void day(uint8_t day)
Set the day of the month.
static const acetime_t kInvalidEpochSeconds
Sentinel epochSeconds which indicates an error.
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
static OffsetDateTime forComponents(int16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, TimeOffset timeOffset=TimeOffset())
Factory method using separated date, time, and UTC offset fields.
uint8_t second() const
Return the second.
uint8_t minute() const
Return the minute.
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
static LocalDateTime forEpochSeconds(acetime_t epochSeconds)
Factory method.
acetime_t toSeconds() const
Return the number of seconds since midnight.
bool isError() const
Return true if any component indicates an error condition.
void year(int16_t year)
Set the year.
const LocalDate & localDate() const
Return the LocalDate.
acetime_t toEpochSeconds() const
Return seconds since AceTime epoch (2000-01-01 00:00:00Z), taking into account the offset zone...
bool isError() const
Return true if this TimeOffset represents an error.
const LocalTime & localTime() const
Return the LocalTime.
OffsetDateTime()
Constructor.
void second(uint8_t second)
Set the second.
const LocalDate & localDate() const
Return the LocalDate.
int16_t year() const
Return the year.
uint8_t month() const
Return the month with January=1, December=12.
acetime_t toEpochSeconds() const
Return seconds since AceTime epoch (2000-01-01 00:00:00Z).
void timeOffset(TimeOffset timeOffset)
Set the offset zone.
void yearTiny(int8_t yearTiny)
Set the single-byte year offset from year 2000.
friend bool operator==(const OffsetDateTime &a, const OffsetDateTime &b)
Return true if two OffsetDateTime objects are equal in all components.
uint8_t day() const
Return the day of the month.
acetime_t toEpochDays() const
Return number of whole days since AceTime epoch (2000-01-01 00:00:00Z), taking into account the offse...
void month(uint8_t month)
Set the month.
static OffsetDateTime forDateString(const __FlashStringHelper *dateString)
Factory method.
uint8_t hour() const
Return the hour.
OffsetDateTime convertToTimeOffset(TimeOffset timeOffset) const
Create a OffsetDateTime in a different offset zone code (with the same epochSeconds).
int8_t compareTo(const OffsetDateTime &that) const
Compare this OffsetDateTime with another OffsetDateTime, and return (<0, 0, >0) according to whether ...
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
acetime_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
The date (year, month, day) and time (hour, minute, second) fields representing the time with an offs...
bool isError() const
Return true if any component indicates an error condition.
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC...
static LocalDateTime forError()
Factory method that returns an instance where isError() returns true.
int16_t year() const
Return the year.
static OffsetDateTime forEpochSeconds(acetime_t epochSeconds, TimeOffset timeOffset=TimeOffset())
Factory method.
uint8_t day() const
Return the day of the month.
The date (year, month, day) representing the date without regards to time zone.
TimeOffset timeOffset() const
Return the offset zone of the OffsetDateTime.
The date (year, month, day) and time (hour, minute, second) fields representing an instant in time...
uint8_t second() const
Return the second.
const LocalTime & localTime() const
Return the LocalTime.
void hour(uint8_t hour)
Set the hour.
static OffsetDateTime forUnixSeconds(acetime_t unixSeconds, TimeOffset timeOffset=TimeOffset())
Factory method that takes the number of seconds since Unix Epoch of 1970-01-01.
int32_t toSeconds() const
Return the time offset as seconds.
acetime_t toUnixSeconds() const
Return the number of seconds from Unix epoch 1970-01-01 00:00:00Z.
void printTo(Print &printer) const
Print OffsetDateTime to 'printer' in ISO 8601 format.
uint8_t minute() const
Return the minute.
acetime_t toEpochDays() const
Return number of days since AceTime epoch (2000-01-01 00:00:00Z).
An implementation of ZoneSpecifier that supports a subset of the zones containing in the TZ Database...
static OffsetDateTime forError()
Factory method that returns an instance whose isError() is true.
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).
static OffsetDateTime forDateString(const char *dateString)
Factory method.