AceTime
1.1.2
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_OFFSET_DATE_TIME_H
7 #define ACE_TIME_OFFSET_DATE_TIME_H
10 #include "TimeOffset.h"
11 #include "LocalDateTime.h"
132 char buffer[kDateStringLength + 2];
133 strncpy_P(buffer, (
const char*) dateString,
sizeof(buffer));
134 buffer[kDateStringLength + 1] = 0;
137 size_t len = strlen(buffer);
138 if (len > kDateStringLength) {
160 int16_t
year()
const {
return mLocalDateTime.
year(); }
186 uint8_t
day()
const {
return mLocalDateTime.
day(); }
192 uint8_t
hour()
const {
return mLocalDateTime.
hour(); }
248 if (
timeOffset >= 86400)
return epochDays + 1;
289 if (thisSeconds < thatSeconds)
return -1;
290 if (thisSeconds > thatSeconds)
return 1;
299 void printTo(Print& printer)
const;
309 static const uint8_t kDateStringLength = 25;
316 LocalDateTime mLocalDateTime;
317 TimeOffset mTimeOffset;
326 return a.mLocalDateTime == b.mLocalDateTime
327 && a.mTimeOffset == b.mTimeOffset;
void printTo(Print &printer) const
Print OffsetDateTime to 'printer' in ISO 8601 format.
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).
acetime_t toUnixSeconds() const
Return the number of seconds from Unix epoch 1970-01-01 00:00:00Z.
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.
uint8_t hour() const
Return the hour.
OffsetDateTime()
Constructor.
static const acetime_t kInvalidEpochSeconds
Sentinel epochSeconds which indicates an error.
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
static TimeOffset forError()
Return an error indicator.
bool isError() const
Return true if this TimeOffset represents an error.
int32_t toSeconds() const
Return the time offset as seconds.
static const acetime_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
void second(uint8_t second)
Set the second.
acetime_t toEpochDays() const
Return number of days since AceTime epoch (2000-01-01 00:00:00Z).
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.
uint8_t month() const
Return the month with January=1, December=12.
void day(uint8_t day)
Set the day of the month.
void year(int16_t year)
Set the year.
static LocalDateTime forError()
Factory method that returns an instance where isError() returns true.
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
static OffsetDateTime forEpochSeconds(acetime_t epochSeconds, TimeOffset timeOffset)
Factory method.
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
The date (year, month, day) representing the date without regards to time zone.
static OffsetDateTime 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).
OffsetDateTime convertToTimeOffset(TimeOffset timeOffset) const
Create a OffsetDateTime in a different offset zone code (with the same epochSeconds).
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.
void yearTiny(int8_t yearTiny)
Set the single-byte year offset from year 2000.
The date (year, month, day), time (hour, minute, second) and offset from UTC (timeOffset).
static OffsetDateTime forError()
Factory method that returns an instance whose isError() is true.
uint8_t second() const
Return the second.
friend bool operator==(const OffsetDateTime &a, const OffsetDateTime &b)
Return true if two OffsetDateTime objects are equal in all components.
uint8_t second() const
Return the second.
const LocalTime & localTime() const
Return the LocalTime.
acetime_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
void month(uint8_t month)
Set the month.
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.
void minute(uint8_t minute)
Set the minute.
int8_t compareTo(const OffsetDateTime &that) const
Compare this OffsetDateTime with another OffsetDateTime, and return (<0, 0, >0) according to whether ...
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.
static OffsetDateTime forDateString(const __FlashStringHelper *dateString)
Factory method.
int16_t year() const
Return the year.
TimeOffset timeOffset() const
Return the offset zone of the OffsetDateTime.
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
void hour(uint8_t hour)
Set the hour.
uint8_t day() const
Return the day of the month.
uint8_t minute() const
Return the minute.
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.
acetime_t toSeconds() const
Return the number of seconds since midnight.
static OffsetDateTime forUnixSeconds(acetime_t unixSeconds, TimeOffset timeOffset)
Factory method that takes the number of seconds since Unix Epoch of 1970-01-01.
uint8_t day() const
Return the day of the month.
static OffsetDateTime forLocalDateTimeAndOffset(const LocalDateTime &localDateTime, TimeOffset timeOffset)
Factory method from LocalDateTime and TimeOffset.
bool isError() const
Return true if any component indicates an error condition.
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).
const LocalDateTime & localDateTime() const
Return the LocalDateTime.
const LocalTime & localTime() const
Return the LocalTime.
int16_t year() const
Return the year.
static LocalDateTime forEpochSeconds(acetime_t epochSeconds)
Factory method.
acetime_t toEpochDays() const
Return number of whole days since AceTime epoch (2000-01-01 00:00:00Z), taking into account the offse...
The time (hour, minute, second) fields representing the time without regards to the day or the time z...