AceTime
1.6
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
|
6 #ifndef ACE_TIME_LOCAL_DATE_TIME_H
7 #define ACE_TIME_LOCAL_DATE_TIME_H
13 #include "LocalDate.h"
14 #include "LocalTime.h"
17 class __FlashStringHelper;
78 acetime_t days = (epochSeconds < 0)
79 ? (epochSeconds + 1) / 86400 - 1
80 : epochSeconds / 86400;
84 acetime_t seconds = epochSeconds - 86400 * days;
142 char buffer[kDateTimeStringLength + 2];
143 strncpy_P(buffer, (
const char*) dateString,
sizeof(buffer));
144 buffer[kDateTimeStringLength + 1] = 0;
147 size_t len = strlen(buffer);
148 if (len > kDateTimeStringLength) {
195 uint8_t
day()
const {
return mLocalDate.
day(); }
250 acetime_t seconds = mLocalTime.
toSeconds();
251 return days * 86400 + seconds;
275 if (dateCompare < 0)
return -1;
276 if (dateCompare > 0)
return 1;
278 if (timeCompare < 0)
return -1;
279 if (timeCompare > 0)
return 1;
288 void printTo(Print& printer)
const;
298 static const uint8_t kDateTimeStringLength = 19;
305 LocalDate mLocalDate;
306 LocalTime mLocalTime;
315 return a.mLocalDate == b.mLocalDate
316 && a.mLocalTime == b.mLocalTime;
acetime_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
void day(uint8_t day)
Set the day of the month.
static LocalDate forError()
Factory method that returns a LocalDate which represents an error condition.
void yearTiny(int8_t yearTiny)
Set the single-byte year offset from year 2000.
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).
uint8_t dayOfWeek() const
Return the day of the week, Monday=1, Sunday=7 (per ISO 8601).
static LocalDate forEpochDays(acetime_t epochDays)
Factory method using the number of days since AceTime epoch of 2000-01-01.
static LocalDateTime forUnixSeconds(acetime_t unixSeconds)
Factory method that takes the number of seconds since Unix Epoch of 1970-01-01.
uint8_t month() const
Return the month with January=1, December=12.
uint8_t hour() const
Return the hour.
static const acetime_t kInvalidEpochSeconds
Sentinel epochSeconds which indicates an error.
static LocalDateTime forTinyComponents(int8_t yearTiny, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
Factory method using components with an int8_t yearTiny.
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
static const acetime_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
acetime_t toEpochDays() const
Return number of days since AceTime epoch (2000-01-01 00:00:00Z).
void printTo(Print &printer) const
Print LocalDateTime to 'printer' in ISO 8601 format.
uint8_t dayOfWeek() const
Calculate the day of week given the (year, month, day).
static LocalDateTime forError()
Factory method that returns an instance where isError() returns true.
void month(uint8_t month)
Set the month.
The date (year, month, day) representing the date without regards to time zone.
acetime_t toEpochDays() const
Return number of whole days since AceTime epoch (2000-01-01 00:00:00Z).
void minute(uint8_t minute)
Set the minute.
void second(uint8_t second)
Set the second.
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.
uint8_t month() const
Return the month with January=1, December=12.
friend bool operator==(const LocalDateTime &a, const LocalDateTime &b)
Return true if two LocalDateTime objects are equal in all components.
bool isError() const
Return true if any component is outside the normal time range of 00:00:00 to 23:59:59.
static const int8_t kInvalidYearTiny
Sentinel yearTiny which indicates an error condition or sometimes a year that 'does not exist'.
static LocalTime forError()
Factory method that returns an instance which indicates an error condition.
static LocalDateTime forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
uint8_t second() const
Return the second.
uint8_t day() const
Return the day of the month.
void hour(uint8_t hour)
Set the hour.
const LocalTime & localTime() const
Return the LocalTime.
bool isError() const
Return true if any component indicates an error condition.
uint8_t minute() const
Return the minute.
const LocalDate & localDate() const
Return the LocalDate.
static LocalDate forTinyComponents(int8_t yearTiny, uint8_t month, uint8_t day)
Factory method using components with an int8_t yearTiny.
bool isError() const
Return true if any component indicates an error condition.
int16_t year() const
Return the full year instead of just the last 2 digits.
acetime_t toEpochSeconds() const
Return seconds since AceTime epoch 2000-01-01 00:00:00Z, after assuming that the date and time compon...
static const int16_t kEpochYear
Base year of epoch.
int16_t year() const
Return the year.
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
int8_t compareTo(const LocalDateTime &that) const
Compare 'this' LocalDateTime with 'that' LocalDateTime, and return (<0, 0, >0) according to whether '...
LocalDateTime()
Constructor.
uint8_t hour() const
Return the hour.
int8_t compareTo(const LocalDate &that) const
Compare 'this' LocalDate to 'that' LocalDate, returning (<0, 0, >0) according to whether 'this' occur...
uint8_t second() const
Return the second.
acetime_t toSeconds() const
Return the number of seconds since midnight.
acetime_t toUnixSeconds() const
Return seconds from Unix epoch 1970-01-01 00:00:00Z, after assuming that the date and time components...
uint8_t minute() const
Return the minute.
static LocalDateTime forDateString(const char *dateString)
Factory method.
void year(int16_t year)
Set the year.
uint8_t day() const
Return the day of the month.
static LocalTime forComponents(uint8_t hour, uint8_t minute, uint8_t second)
Factory method using separated date, time, and time zone fields.
int8_t compareTo(const LocalTime &that) const
Compare 'this' LocalTime with 'that' LocalTime, and return (<0, 0, >0) according to whether 'this' oc...
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).
static bool isYearValid(int16_t year)
Return true if year is within valid range of [1873, 2127].
static LocalDateTime forEpochSeconds(acetime_t epochSeconds)
Factory method.
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
static LocalTime forSeconds(acetime_t seconds)
Factory method.
static LocalDateTime forDateString(const __FlashStringHelper *dateString)
Factory method.