1 #ifndef ACE_TIME_OFFSET_DATE_TIME_H 2 #define ACE_TIME_OFFSET_DATE_TIME_H 5 #include "TimeOffset.h" 6 #include "LocalDateTime.h" 130 char buffer[kDateStringLength + 2];
131 strncpy_P(buffer, (
const char*) dateString,
sizeof(buffer));
132 buffer[kDateStringLength + 1] = 0;
135 size_t len = strlen(buffer);
136 if (len > kDateStringLength) {
158 int16_t
year()
const {
return mLocalDateTime.
year(); }
176 uint8_t
day()
const {
return mLocalDateTime.
day(); }
182 uint8_t
hour()
const {
return mLocalDateTime.
hour(); }
238 if (timeOffset >= 86400)
return epochDays + 1;
239 if (timeOffset < 0)
return epochDays - 1;
279 if (thisSeconds < thatSeconds)
return -1;
280 if (thisSeconds > thatSeconds)
return 1;
289 void printTo(Print& printer)
const;
299 static const uint8_t kDateStringLength = 25;
304 mTimeOffset(timeOffset) {}
316 return a.mLocalDateTime == b.mLocalDateTime
317 && a.mTimeOffset == b.mTimeOffset;
acetime_t toSeconds() const
Return the number of seconds since midnight.
const LocalTime & localTime() const
Return the LocalTime.
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 minute() const
Return the minute.
int16_t year() const
Return the year.
uint8_t minute() const
Return the minute.
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)...
uint8_t second() const
Return the second.
void minute(uint8_t minute)
Set the minute.
static const acetime_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
void day(uint8_t day)
Set 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...
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...
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).
bool isError() const
Return true if this TimeOffset represents an error.
OffsetDateTime convertToTimeOffset(TimeOffset timeOffset) const
Create a OffsetDateTime in a different offset zone code (with the same epochSeconds).
acetime_t toEpochDays() const
Return number of days since AceTime epoch (2000-01-01 00:00:00Z).
uint8_t month() const
Return the month with January=1, December=12.
static OffsetDateTime forLocalDateTimeAndOffset(const LocalDateTime &localDateTime, TimeOffset timeOffset)
Factory method from LocalDateTime and TimeOffset.
int32_t toSeconds() const
Return the time offset as seconds.
uint8_t hour() const
Return the hour.
uint8_t day() const
Return the day of the month.
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
static LocalDateTime forEpochSeconds(acetime_t epochSeconds)
Factory method.
acetime_t toUnixSeconds() const
Return the number of seconds from Unix epoch 1970-01-01 00:00:00Z.
void year(int16_t year)
Set the year.
void printTo(Print &printer) const
Print OffsetDateTime to 'printer' in ISO 8601 format.
static OffsetDateTime forComponents(int16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, TimeOffset timeOffset)
Factory method using separated date, time, and UTC offset fields.
int8_t compareTo(const OffsetDateTime &that) const
Compare this OffsetDateTime with another OffsetDateTime, and return (<0, 0, >0) according to whether ...
OffsetDateTime()
Constructor.
void second(uint8_t second)
Set the second.
uint8_t month() const
Return the month with January=1, December=12.
static OffsetDateTime forEpochSeconds(acetime_t epochSeconds, TimeOffset timeOffset)
Factory method.
static LocalDateTime forComponents(int16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
Factory method using separated date and time components.
acetime_t toEpochSeconds() const
Return seconds since AceTime epoch 2000-01-01 00:00:00Z, after assuming that the date and time compon...
void timeOffset(TimeOffset timeOffset)
Set the offset zone.
void yearTiny(int8_t yearTiny)
Set the single-byte year offset from year 2000.
const LocalDate & localDate() const
Return the LocalDate.
friend bool operator==(const OffsetDateTime &a, const OffsetDateTime &b)
Return true if two OffsetDateTime objects are equal in all components.
TimeOffset timeOffset() const
Return the offset zone of the OffsetDateTime.
const LocalTime & localTime() const
Return the LocalTime.
void month(uint8_t month)
Set the month.
static OffsetDateTime forDateString(const __FlashStringHelper *dateString)
Factory method.
acetime_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
uint8_t hour() const
Return the hour.
int16_t year() const
Return the year.
const LocalDateTime & localDateTime() const
Return the LocalDateTime.
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).
The date (year, month, day) and time (hour, minute, second) fields representing the time with an offs...
uint8_t second() const
Return the second.
acetime_t toEpochSeconds() const
Return seconds since AceTime epoch (2000-01-01 00:00:00Z), taking into account the offset zone...
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.
The date (year, month, day) representing the date without regards to time zone.
void hour(uint8_t hour)
Set the hour.
const LocalDate & localDate() const
Return the LocalDate.
static OffsetDateTime forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
uint8_t day() const
Return the day of the month.
static OffsetDateTime forUnixSeconds(acetime_t unixSeconds, TimeOffset timeOffset)
Factory method that takes the number of seconds since Unix Epoch of 1970-01-01.
bool isError() const
Return true if any component indicates an error condition.
bool isError() const
Return true if any component indicates an error condition.
static OffsetDateTime forError()
Factory method that returns an instance whose isError() is true.
static OffsetDateTime forDateString(const char *dateString)
Factory method.