AceTime
1.11.2
Date and time classes for Arduino that support timezones from the TZ Database.
|
6 #ifndef ACE_TIME_LOCAL_DATE_H
7 #define ACE_TIME_LOCAL_DATE_H
10 #include "common/common.h"
11 #include "LocalTime.h"
180 int32_t days = (epochSeconds < 0)
181 ? (epochSeconds + 1) / 86400 - 1
182 : epochSeconds / 86400;
250 return ((
year % 4 == 0) && (
year % 100 != 0)) || (
year % 400 == 0);
261 uint8_t days = sDaysInMonth[
month - 1];
289 uint8_t
month()
const {
return mMonth; }
295 uint8_t
day()
const {
return mDay; }
308 int16_t y =
year() - (mMonth < 3);
309 int16_t d = y + y/4 - y/100 + y/400 + sDayOfWeek[mMonth-1] + mDay;
312 return (d < -1) ? (d + 1) % 7 + 8 : (d + 1) % 7 + 1;
318 || mDay < 1 || mDay > 31
319 || mMonth < 1 || mMonth > 12;
353 int8_t mm = (mMonth - 14)/12;
355 int32_t jdn = ((int32_t) 1461 * (yy + 4800 + mm))/4
356 + (367 * (mMonth - 2 - 12 * mm))/12
357 - (3 * ((yy + 4900 + mm)/100))/4
359 return jdn - kDaysSinceJulianEpoch;
406 if (mYearTiny < that.mYearTiny)
return -1;
407 if (mYearTiny > that.mYearTiny)
return 1;
408 if (mMonth < that.mMonth)
return -1;
409 if (mMonth > that.mMonth)
return 1;
410 if (mDay < that.mDay)
return -1;
411 if (mDay > that.mDay)
return 1;
421 void printTo(Print& printer)
const;
434 static const int32_t kDaysSinceJulianEpoch = 2451545;
437 static const uint8_t kDateStringLength = 10;
444 static const uint8_t sDayOfWeek[12];
447 static const uint8_t sDaysInMonth[12];
460 static void extractYearMonthDay(int32_t epochDays, int16_t&
year,
462 uint32_t J = epochDays + kDaysSinceJulianEpoch;
463 uint32_t f = J + 1401 + (((4 * J + 274277 ) / 146097) * 3) / 4 - 38;
464 uint32_t e = 4 * f + 3;
465 uint32_t g = e % 1461 / 4;
466 uint32_t h = 5 * g + 2;
467 day = (h % 153) / 5 + 1;
468 month = (h / 153 + 2) % 12 + 1;
469 year = (e / 1461) - 4716 + (12 + 2 -
month) / 12;
487 return a.mDay == b.mDay
488 && a.mMonth == b.mMonth
489 && a.mYearTiny == b.mYearTiny;
void printTo(Print &printer) const
Print LocalDate to 'printer' in ISO 8601 format, along with the day of week.
static LocalDate forError()
Factory method that returns a LocalDate which represents an error condition.
LocalDate()
Default constructor does nothing.
uint8_t month() const
Return the month with January=1, December=12.
static const int32_t kInvalidEpochSeconds
Sentinel epochSeconds which indicates an error.
static const int32_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
static const int8_t kMaxYearTiny
Sentinel yearTiny which represents the largest year, effectively +Infinity.
static const uint8_t kThursday
Thursday ISO 8601 number.
static bool isLeapYear(int16_t year)
True if year is a leap year.
static const int8_t kMinYearTiny
Sentinel yearTiny which represents the smallest year, effectively -Infinity.
uint8_t dayOfWeek() const
Calculate the day of week given the (year, month, day).
static LocalDate forEpochDays(int32_t epochDays)
Factory method using the number of days since AceTime epoch of 2000-01-01.
void year(int16_t year)
Set the year given the full year.
The date (year, month, day) representing the date without regards to time zone.
acetime_t toEpochSeconds() const
Return the number of seconds since AceTime epoch (2000-01-01 00:00:00).
friend bool operator==(const LocalDate &a, const LocalDate &b)
Return true if two LocalDate objects are equal in all components.
static LocalDate forEpochSeconds(acetime_t epochSeconds)
Factory method using the number of seconds since AceTime epoch of 2000-01-01.
static LocalDate forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
static const int64_t kMinValidUnixSeconds64
Minimum 64-bit Unix seconds supported by acetime_t.
static const uint8_t kFriday
Friday ISO 8601 number.
static LocalDate forDateString(const char *dateString)
Factory method.
static LocalDate forUnixSeconds(int32_t unixSeconds)
Factory method that takes the number of seconds since Unix Epoch of 1970-01-01.
static const int32_t kInvalidUnixDays
Sentinel unixDays which indicates an error.
static const int8_t kInvalidYearTiny
Sentinel yearTiny which indicates an error condition or sometimes a year that 'does not exist'.
int32_t toUnixSeconds() const
Return the number of seconds since Unix epoch (1970-01-01 00:00:00).
int32_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
uint8_t day() const
Return the day of the month.
static const uint8_t kSaturday
Saturday ISO 8601 number.
static const int32_t kInvalidUnixSeconds
Sentinel unixSeconds which indicates an error.
void day(uint8_t day)
Set the day of the month.
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.
static LocalDate forUnixSeconds64(int64_t unixSeconds)
Factory method that takes the 64-bit number of seconds since Unix Epoch of 1970-01-01.
static LocalDate forComponents(int16_t year, uint8_t month, uint8_t day)
Factory method using separated year, month and day fields.
int16_t year() const
Return the full year instead of just the last 2 digits.
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 int16_t kEpochYear
Base year of epoch.
static LocalDate forUnixDays(int32_t unixDays)
Factory method using the number of days since Unix epoch 1970-01-1.
static const uint8_t kSunday
Sunday ISO 8601 number.
int8_t compareTo(const LocalDate &that) const
Compare 'this' LocalDate to 'that' LocalDate, returning (<0, 0, >0) according to whether 'this' occur...
static const uint8_t kTuesday
Tuesday ISO 8601 number.
static uint8_t daysInMonth(int16_t year, uint8_t month)
Return the number of days in the current month.
static const int64_t kInvalidUnixSeconds64
Sentinel 64-bit unixSeconds which indicates an error.
void yearTiny(int8_t yearTiny)
Set the single-byte year offset from year 2000.
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).
void month(uint8_t month)
Set the month.
int32_t toEpochDays() const
Return number of days since 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 const int64_t kMaxValidUnixSeconds64
Maximum 64-bit Unix seconds supported by acetime_t.
int64_t toUnixSeconds64() const
Return the number of seconds since Unix epoch (1970-01-01 00:00:00).
static const uint8_t kMonday
Monday ISO 8601 number.
int8_t yearTiny() const
Return the single-byte year offset from year 2000.
static const uint8_t kWednesday
Wednesday ISO 8601 number.