6 #ifndef ACE_TIME_LOCAL_DATE_TIME_H
7 #define ACE_TIME_LOCAL_DATE_TIME_H
12 #include "LocalDate.h"
13 #include "LocalTime.h"
16 class __FlashStringHelper;
70 int32_t days = (epochSeconds < 0)
71 ? (epochSeconds + 1) / 86400 - 1
72 : epochSeconds / 86400;
76 int32_t seconds = epochSeconds - 86400 * days;
91 int64_t unixSeconds, uint8_t
fold = 0) {
96 int64_t epochSeconds64 = unixSeconds
100 int32_t days = (epochSeconds64 < 0)
101 ? (epochSeconds64 + 1) / 86400 - 1
102 : epochSeconds64 / 86400;
103 int32_t seconds = epochSeconds64 - (int64_t) 86400 * days;
168 uint8_t
day()
const {
return mLocalDate.
day(); }
233 int32_t seconds = mLocalTime.
toSeconds();
234 return (int32_t) 86400 * days + seconds;
248 int32_t seconds = mLocalTime.
toSeconds();
249 return (int64_t) 86400 * days + seconds;
260 if (dateCompare != 0)
return dateCompare;
262 if (timeCompare != 0)
return timeCompare;
271 void printTo(Print& printer)
const;
281 static const uint8_t kDateTimeStringLength = 19;
288 LocalDate mLocalDate;
289 LocalTime mLocalTime;
298 return a.mLocalDate == b.mLocalDate
299 && a.mLocalTime == b.mLocalTime;
static int32_t daysToCurrentEpochFromUnixEpoch()
Return the number of days from the Unix epoch (1970-01-01T00:00:00) to the current epoch.
static int64_t secondsToCurrentEpochFromUnixEpoch64()
Return the number of seconds from the Unix epoch (1970-01-01T00:00:00) to the current epoch.
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
int64_t toUnixSeconds64() const
Return 64-bit seconds from Unix epoch 1970-01-01 00:00:00 UTC, after assuming that the date and time ...
void hour(uint8_t hour)
Set the hour.
void printTo(Print &printer) const
Print LocalDateTime to 'printer' in ISO 8601 format.
static LocalDateTime forEpochSeconds(acetime_t epochSeconds, uint8_t fold=0)
Factory method.
LocalDateTime()
Constructor.
void fold(uint8_t fold)
Set the fold.
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.
void minute(uint8_t minute)
Set the minute.
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.
int8_t compareTo(const LocalDateTime &that) const
Compare 'this' LocalDateTime with 'that' LocalDateTime, and return (<0, 0, >0) according to whether '...
static LocalDateTime forUnixSeconds64(int64_t unixSeconds, uint8_t fold=0)
Factory method that takes the 64-bit number of seconds since Unix Epoch of 1970-01-01.
void month(uint8_t month)
Set the month.
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.
static LocalDateTime forDateString(const char *dateString)
Factory method.
uint8_t second() const
Return the second.
void day(uint8_t day)
Set the day of the month.
uint8_t minute() const
Return the minute.
void year(int16_t year)
Set the year.
int32_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
const LocalTime & localTime() const
Return the LocalTime.
int32_t toEpochDays() const
Return number of whole days since AceTime epoch.
uint8_t hour() const
Return the hour.
static LocalDateTime forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).
friend bool operator==(const LocalDateTime &a, const LocalDateTime &b)
Return true if two LocalDateTime objects are equal in all components.
void second(uint8_t second)
Set the second.
acetime_t toEpochSeconds() const
Return seconds since the current AceTime epoch defined by Epoch::currentEpochYear().
int16_t year() const
Return the year.
The date (year, month, day) representing the date without regards to time zone.
static LocalDate forComponents(int16_t year, uint8_t month, uint8_t day)
Factory method using separated year, month and day fields.
static const int32_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
bool isError() const
Return true if any component indicates an error condition.
static LocalDate forError()
Factory method that returns a LocalDate which represents an error condition.
static const int64_t kInvalidUnixSeconds64
Sentinel unixSeconds64 which indicates an error.
uint8_t dayOfWeek() const
Calculate the day of week given the (year, month, day).
int8_t compareTo(const LocalDate &that) const
Compare 'this' LocalDate to 'that' LocalDate, returning (<0, 0, >0) according to whether 'this' occur...
static const int32_t kInvalidEpochSeconds
Sentinel epochSeconds which indicates an error.
int16_t year() const
Return the year.
int32_t toEpochDays() const
Return number of days since the current epoch year sCurrentEpochYear.
static LocalDate forEpochDays(int32_t epochDays)
Factory method using the number of days since the current epoch (usually 2000-01-01).
uint8_t month() const
Return the month with January=1, December=12.
uint8_t day() const
Return the day of the month.
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
static LocalTime forComponents(uint8_t hour, uint8_t minute, uint8_t second, uint8_t fold=0)
Factory method using separated date, time, and time zone fields.
uint8_t fold() const
Return the fold.
acetime_t toSeconds() const
Return the number of seconds since midnight.
static LocalTime forError()
Factory method that returns an instance which indicates an error condition.
uint8_t hour() const
Return the hour.
uint8_t minute() const
Return the minute.
static LocalTime forSeconds(acetime_t seconds, uint8_t fold=0)
Factory method.
uint8_t second() const
Return the second.
bool isError() const
Return true if any component is outside the normal time range of 00:00:00 to 23:59:59.
int8_t compareTo(const LocalTime &that) const
Compare 'this' LocalTime with 'that' LocalTime, and return (<0, 0, >0) according to whether 'this' oc...
int32_t acetime_t
Type for the number of seconds from epoch.