AceTime
1.11.2
Date and time classes for Arduino that support timezones from the TZ Database.
|
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;
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, uint8_t fold=0)
Factory method using separated date, time, and UTC offset fields.
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 int32_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.
static const int32_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
int32_t toSeconds() const
Return the time offset as seconds.
uint8_t fold() const
Return the fold.
void second(uint8_t second)
Set the second.
const LocalDate & localDate() const
Return the LocalDate.
int32_t toEpochDays() const
Return number of whole days since AceTime epoch (2000-01-01 00:00:00Z), taking into account the offse...
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 fold(uint8_t fold)
Set the fold.
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.
static LocalDateTime forEpochSeconds(acetime_t epochSeconds, uint8_t fold=0)
Factory method.
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
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).
int32_t toUnixSeconds() const
Return the number of seconds from Unix epoch 1970-01-01 00:00:00Z.
int64_t toUnixSeconds64() const
Return the 64-bit number of seconds from Unix epoch 1970-01-01 00:00:00Z.
static const int64_t kMinValidUnixSeconds64
Minimum 64-bit Unix seconds supported by acetime_t.
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 const int32_t kInvalidUnixDays
Sentinel unixDays which indicates an error.
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.
void month(uint8_t month)
Set the month.
bool isError() const
Return true if any component indicates an error condition.
static const int32_t kInvalidUnixSeconds
Sentinel unixSeconds which indicates an error.
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 'that' OffsetDateTime, and return (<0, 0, >0) according to whether...
int32_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
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 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).
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.
acetime_t toSeconds() const
Return the number of seconds since midnight.
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.
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.
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 int64_t kInvalidUnixSeconds64
Sentinel 64-bit unixSeconds which indicates an error.
static OffsetDateTime forUnixSeconds(int32_t unixSeconds, TimeOffset timeOffset)
Factory method that takes the number of seconds since Unix Epoch of 1970-01-01.
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).
const LocalDateTime & localDateTime() const
Return the LocalDateTime.
const LocalTime & localTime() const
Return the LocalTime.
uint8_t fold() const
Return the fold.
int32_t toEpochDays() const
Return number of days since AceTime epoch (2000-01-01 00:00:00Z).
int16_t year() const
Return the year.
static const int64_t kMaxValidUnixSeconds64
Maximum 64-bit Unix seconds supported by acetime_t.
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
static OffsetDateTime forEpochSeconds(acetime_t epochSeconds, TimeOffset timeOffset, uint8_t fold=0)
Factory method.