6 #ifndef ACE_TIME_OFFSET_DATE_TIME_H
7 #define ACE_TIME_OFFSET_DATE_TIME_H
10 #include "TimeOffset.h"
11 #include "LocalDateTime.h"
165 char buffer[kDateStringLength + 2];
166 strncpy_P(buffer, (
const char*) dateString,
sizeof(buffer));
167 buffer[kDateStringLength + 1] = 0;
170 size_t len = strlen(buffer);
171 if (len > kDateStringLength) {
193 int16_t
year()
const {
return mLocalDateTime.
year(); }
219 uint8_t
day()
const {
return mLocalDateTime.
day(); }
225 uint8_t
hour()
const {
return mLocalDateTime.
hour(); }
243 uint8_t
fold()
const {
return mLocalDateTime.
fold(); }
287 if (
timeOffset >= 86400)
return epochDays + 1;
350 if (thisSeconds < thatSeconds)
return -1;
351 if (thisSeconds > thatSeconds)
return 1;
360 void printTo(Print& printer)
const;
370 static const uint8_t kDateStringLength = 25;
377 LocalDateTime mLocalDateTime;
378 TimeOffset mTimeOffset;
387 return a.mLocalDateTime == b.mLocalDateTime
388 && a.mTimeOffset == b.mTimeOffset;
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
static LocalDateTime forEpochSeconds(acetime_t epochSeconds, uint8_t fold=0)
Factory method.
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
static LocalDateTime forComponents(int16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint8_t fold=0)
Factory method using separated date and time components.
uint8_t day() const
Return the day of the month.
const LocalDate & localDate() const
Return the LocalDate.
bool isError() const
Return true if any component indicates an error condition.
static LocalDateTime forError()
Factory method that returns an instance where isError() returns true.
uint8_t month() const
Return the month with January=1, December=12.
uint8_t fold() const
Return the fold.
uint8_t second() const
Return the second.
uint8_t minute() const
Return the minute.
const LocalTime & localTime() const
Return the LocalTime.
uint8_t hour() const
Return the hour.
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).
acetime_t toEpochSeconds() const
Return seconds since AceTime epoch 2000-01-01 00:00:00Z, after assuming that the date and time compon...
int16_t year() const
Return the year.
The date (year, month, day) representing the date without regards to time zone.
static const int32_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 const int32_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
static const int64_t kMaxValidUnixSeconds64
Maximum 64-bit Unix seconds supported by acetime_t.
static const int64_t kInvalidUnixSeconds64
Sentinel 64-bit unixSeconds which indicates an error.
static const int32_t kInvalidUnixDays
Sentinel unixDays which indicates an error.
static const int64_t kMinValidUnixSeconds64
Minimum 64-bit Unix seconds supported by acetime_t.
static const int32_t kInvalidUnixSeconds
Sentinel unixSeconds which indicates an error.
static const int32_t kInvalidEpochSeconds
Sentinel epochSeconds which indicates an error.
static const int32_t kDaysSinceUnixEpoch
Number of days from Unix epoch (1970-01-01 00:00:00Z) to the AceTime epoch (2000-01-01 00:00:00Z).
int32_t toEpochDays() const
Return number of days since AceTime epoch (2000-01-01 00:00:00Z).
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
acetime_t toSeconds() const
Return the number of seconds since midnight.
The date (year, month, day), time (hour, minute, second) and offset from UTC (timeOffset).
const LocalTime & localTime() const
Return the LocalTime.
uint8_t day() const
Return the day of the month.
TimeOffset timeOffset() const
Return the offset zone of the OffsetDateTime.
int64_t toUnixSeconds64() const
Return the 64-bit number of seconds from Unix epoch 1970-01-01 00:00:00Z.
static OffsetDateTime forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
void month(uint8_t month)
Set the month.
bool isError() const
Return true if any component indicates an error condition.
const LocalDateTime & localDateTime() const
Return the LocalDateTime.
uint8_t hour() const
Return the hour.
void timeOffset(TimeOffset timeOffset)
Set the offset zone.
OffsetDateTime()
Constructor.
uint8_t month() const
Return the month with January=1, December=12.
void printTo(Print &printer) const
Print OffsetDateTime to 'printer' in ISO 8601 format.
void minute(uint8_t minute)
Set the minute.
static OffsetDateTime forLocalDateTimeAndOffset(const LocalDateTime &localDateTime, TimeOffset timeOffset)
Factory method from LocalDateTime and TimeOffset.
acetime_t toEpochSeconds() const
Return seconds since AceTime epoch (2000-01-01 00:00:00Z), taking into account the offset zone.
static OffsetDateTime forError()
Factory method that returns an instance whose isError() is true.
uint8_t fold() const
Return the fold.
int8_t compareTo(const OffsetDateTime &that) const
Compare 'this' OffsetDateTime with 'that' OffsetDateTime, and return (<0, 0, >0) according to whether...
void hour(uint8_t hour)
Set the hour.
uint8_t minute() const
Return the minute.
OffsetDateTime convertToTimeOffset(TimeOffset timeOffset) const
Create a OffsetDateTime in a different offset zone code (with the same epochSeconds).
int16_t year() const
Return the year.
void yearTiny(int8_t yearTiny)
Set the single-byte year offset from year 2000.
void day(uint8_t day)
Set the day of the month.
int8_t yearTiny() const
Return 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.
static OffsetDateTime forDateString(const char *dateString)
Factory method.
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).
int32_t toEpochDays() const
Return number of whole days since AceTime epoch (2000-01-01 00:00:00Z), taking into account the offse...
int32_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
static OffsetDateTime forEpochSeconds(acetime_t epochSeconds, TimeOffset timeOffset, uint8_t fold=0)
Factory method.
static OffsetDateTime forDateString(const __FlashStringHelper *dateString)
Factory method.
void year(int16_t year)
Set the year.
void second(uint8_t second)
Set the second.
void fold(uint8_t fold)
Set the fold.
static OffsetDateTime forUnixSeconds64(int64_t unixSeconds, TimeOffset timeOffset)
Factory method that takes the number of seconds (64-bit) since Unix Epoch of 1970-01-01.
int32_t toUnixSeconds() const
Return the number of seconds from Unix epoch 1970-01-01 00:00:00Z.
uint8_t second() const
Return the second.
static OffsetDateTime forUnixSeconds(int32_t unixSeconds, TimeOffset timeOffset)
Factory method that takes the number of seconds since Unix Epoch of 1970-01-01.
static OffsetDateTime forComponents(int16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, TimeOffset timeOffset, uint8_t fold=0)
Factory method using separated date, time, and UTC offset fields.
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
static TimeOffset forError()
Return an error indicator.
int32_t toSeconds() const
Return the time offset as seconds.
bool isError() const
Return true if this TimeOffset represents an error.