6 #ifndef ACE_TIME_LOCAL_DATE_H
7 #define ACE_TIME_LOCAL_DATE_H
129 return ((
year % 4 == 0) && (
year % 100 != 0)) || (
year % 400 == 0);
134 uint8_t days = sDaysInMonth[
month - 1];
177 ACE_TIME_EPOCH_CONVERTER::fromEpochDays(epochDays,
year,
month,
day);
211 int32_t days = (epochSeconds < 0)
212 ? (epochSeconds + 1) / 86400 - 1
213 : epochSeconds / 86400;
228 int64_t epochSeconds64 = unixSeconds
230 int32_t days = (epochSeconds64 < 0)
231 ? (epochSeconds64 + 1) / 86400 - 1
232 : epochSeconds64 / 86400;
247 if (strlen(dateString) < kDateStringLength) {
261 const char* s = dateString;
264 int16_t
year = (*s++ -
'0');
273 uint8_t
month = (*s++ -
'0');
280 uint8_t
day = (*s++ -
'0');
281 day = 10 *
day + (*s++ -
'0');
301 int16_t
year()
const {
return mYear; }
307 uint8_t
month()
const {
return mMonth; }
313 uint8_t
day()
const {
return mDay; }
326 int16_t y =
year() - (mMonth < 3);
330 int16_t d = y + y/4 - y/100 + y/400 + sDayOfWeek[mMonth-1] + mDay;
333 return (d < -1) ? (d + 1) % 7 + 8 : (d + 1) % 7 + 1;
339 || mDay < 1 || mDay > 31
340 || mMonth < 1 || mMonth > 12;
354 int32_t days = ACE_TIME_EPOCH_CONVERTER::toEpochDays(mYear, mMonth, mDay)
407 if (mYear < that.mYear)
return -1;
408 if (mYear > that.mYear)
return 1;
409 if (mMonth < that.mMonth)
return -1;
410 if (mMonth > that.mMonth)
return 1;
411 if (mDay < that.mDay)
return -1;
412 if (mDay > that.mDay)
return 1;
422 void printTo(Print& printer)
const;
440 static const uint8_t kDateStringLength = 10;
447 static const uint8_t sDayOfWeek[12];
450 static const uint8_t sDaysInMonth[12];
459 return a.mDay == b.mDay
460 && a.mMonth == b.mMonth
461 && a.mYear == b.mYear;
static int32_t daysToCurrentEpochFromInternalEpoch()
Number of days from the internal 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.
int16_t daysUntil(uint8_t month, uint8_t day) const
Calculate number of days from current LocalDate to the next target (month, day).
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.