6 #ifndef ACE_TIME_LOCAL_DATE_H
7 #define ACE_TIME_LOCAL_DATE_H
12 #include <AceCommon.h>
15 #include "common/DateStrings.h"
132 return ((
year % 4 == 0) && (
year % 100 != 0)) || (
year % 400 == 0);
137 uint8_t days = sDaysInMonth[
month - 1];
180 ACE_TIME_EPOCH_CONVERTER::fromEpochDays(epochDays,
year,
month,
day);
214 int32_t days = (epochSeconds < 0)
215 ? (epochSeconds + 1) / 86400 - 1
216 : epochSeconds / 86400;
231 int64_t epochSeconds64 = unixSeconds
233 int32_t days = (epochSeconds64 < 0)
234 ? (epochSeconds64 + 1) / 86400 - 1
235 : epochSeconds64 / 86400;
250 if (strlen(dateString) < kDateStringLength) {
264 const char* s = dateString;
267 int16_t
year = (*s++ -
'0');
276 uint8_t
month = (*s++ -
'0');
283 uint8_t
day = (*s++ -
'0');
284 day = 10 *
day + (*s++ -
'0');
304 int16_t
year()
const {
return mYear; }
310 uint8_t
month()
const {
return mMonth; }
316 uint8_t
day()
const {
return mDay; }
329 int16_t y =
year() - (mMonth < 3);
333 int16_t d = y + y/4 - y/100 + y/400 + sDayOfWeek[mMonth-1] + mDay;
336 return (d < -1) ? (d + 1) % 7 + 8 : (d + 1) % 7 + 1;
342 || mDay < 1 || mDay > 31
343 || mMonth < 1 || mMonth > 12;
357 int32_t days = ACE_TIME_EPOCH_CONVERTER::toEpochDays(mYear, mMonth, mDay)
394 if (mYear < that.mYear)
return -1;
395 if (mYear > that.mYear)
return 1;
396 if (mMonth < that.mMonth)
return -1;
397 if (mMonth > that.mMonth)
return 1;
398 if (mDay < that.mDay)
return -1;
399 if (mDay > that.mDay)
return 1;
411 printer.print(F(
"<Invalid LocalDate>"));
416 using ace_common::printPad2To;
417 printer.print(
year());
419 printPad2To(printer, mMonth,
'0');
421 printPad2To(printer, mDay,
'0');
445 static const uint8_t kDateStringLength = 10;
452 static const uint8_t sDayOfWeek[12];
455 static const uint8_t sDaysInMonth[12];
464 return a.mDay == b.mDay
465 && a.mMonth == b.mMonth
466 && a.mYear == b.mYear;
Class that translates a numeric month (1-12) or dayOfWeek (1-7) into a human readable string.
const char * dayOfWeekLongString(uint8_t dayOfWeek)
Return the short dayOfWeek name.
static int32_t daysToCurrentEpochFromConverterEpoch()
Number of days from the converter epoch (2000-01-01) to the current epoch.
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.
The date (year, month, day) representing the date without regards to time zone.
friend bool operator==(const LocalDate &a, const LocalDate &b)
Return true if two LocalDate objects are equal in all components.
static const uint8_t kWednesday
Wednesday ISO 8601 number.
static LocalDate forComponents(int16_t year, uint8_t month, uint8_t day)
Factory method using separated year, month and day fields.
static const int16_t kMaxYear
The largest year that is expected to be handled by LocalDate.
static bool isLeapYear(int16_t year)
True if year is a leap year.
static const int32_t kInvalidEpochDays
Sentinel epochDays which indicates an error.
bool isError() const
Return true if any component indicates an error condition.
static const uint8_t kTuesday
Tuesday ISO 8601 number.
int32_t toUnixDays() const
Return the number of days since Unix epoch (1970-01-01 00:00:00).
static LocalDate forError()
Factory method that returns a LocalDate which represents an error condition.
static const acetime_t kMinEpochSeconds
Minimum valid epochSeconds.
static LocalDate forDateString(const char *dateString)
Factory method.
static LocalDate forUnixSeconds64(int64_t unixSeconds)
Factory method that takes the 64-bit number of seconds since Unix Epoch of 1970-01-01.
void day(uint8_t day)
Set the day of the month.
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).
static const uint8_t kFriday
Friday ISO 8601 number.
static const int16_t kMinYear
The smallest year that is expected to be handled by LocalDate.
int64_t toUnixSeconds64() const
Return the number of seconds since Unix epoch (1970-01-01 00:00:00).
void printTo(Print &printer) const
Print LocalDate to 'printer' in ISO 8601 format, along with the day of week.
int8_t compareTo(const LocalDate &that) const
Compare 'this' LocalDate to 'that' LocalDate, returning (<0, 0, >0) according to whether 'this' occur...
static uint8_t daysInMonth(int16_t year, uint8_t month)
Return the number of days in the given (year, month).
void month(uint8_t month)
Set the month.
static bool isYearValid(int16_t year)
Return true if year is within the range of [0,10000]
static const int32_t kInvalidEpochSeconds
Sentinel epochSeconds which indicates an error.
int16_t year() const
Return the year.
static const acetime_t kMaxEpochSeconds
Maximum valid epochSeconds.
static LocalDate forEpochSeconds(acetime_t epochSeconds)
Factory method using the number of seconds since the current epoch year given by currentEpochYear().
int32_t toEpochDays() const
Return number of days since the current epoch year sCurrentEpochYear.
static const uint8_t kThursday
Thursday ISO 8601 number.
static const uint8_t kSaturday
Saturday ISO 8601 number.
static const uint8_t kMonday
Monday ISO 8601 number.
static LocalDate forUnixDays(int32_t unixDays)
Factory method using the number of days since Unix epoch 1970-01-01.
LocalDate()=default
Default constructor does nothing.
static const int16_t kInvalidYear
Sentinel year which indicates one or more of the following conditions:
static LocalDate forEpochDays(int32_t epochDays)
Factory method using the number of days since the current epoch (usually 2000-01-01).
static LocalDate forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
uint8_t month() const
Return the month with January=1, December=12.
acetime_t toEpochSeconds() const
Return the number of seconds since the currentEpochYear().
static const uint8_t kSunday
Sunday ISO 8601 number.
void year(int16_t year)
Set the year.
uint8_t day() const
Return the day of the month.
Identifiers used by implementation code which need to be publically exported.
int32_t acetime_t
Type for the number of seconds from epoch.