1 #ifndef ACE_TIME_LOCAL_TIME_H 2 #define ACE_TIME_LOCAL_TIME_H 5 #include "common/common.h" 51 if (seconds == kInvalidSeconds) {
52 second = minute = hour = kInvalidValue;
54 second = seconds % 60;
55 uint16_t minutes = seconds / 60;
56 minute = minutes % 60;
77 return LocalTime(kInvalidValue, kInvalidValue, kInvalidValue);
90 if (mSecond >= 60)
return true;
91 if (mMinute >= 60)
return true;
93 return mSecond != 0 || mMinute != 0;
99 uint8_t
hour()
const {
return mHour; }
105 uint8_t
minute()
const {
return mMinute; }
108 void minute(uint8_t month) { mMinute = month; }
111 uint8_t
second()
const {
return mSecond; }
124 return ((mHour * (int16_t) 60) + mMinute)
125 * (int32_t) 60 + mSecond;
135 if (mHour < that.mHour)
return -1;
136 if (mHour > that.mHour)
return 1;
137 if (mMinute < that.mMinute)
return -1;
138 if (mMinute > that.mMinute)
return 1;
139 if (mSecond < that.mSecond)
return -1;
140 if (mSecond > that.mSecond)
return 1;
148 void printTo(Print& printer)
const;
160 static const uint8_t kTimeStringLength = 8;
163 static const uint8_t kInvalidValue = UINT8_MAX;
172 static LocalTime forTimeStringChainable(
const char*& timeString);
186 return a.mSecond == b.mSecond
187 && a.mMinute == b.mMinute
188 && a.mHour == b.mHour;
void second(uint8_t second)
Set the second.
void minute(uint8_t month)
Set the minute.
void hour(uint8_t hour)
Set the hour.
static const acetime_t kInvalidSeconds
An invalid seconds marker that indicates isError() true.
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
acetime_t toSeconds() const
Return the number of seconds since midnight.
The date (year, month, day) and time (hour, minute, second) fields representing the time with an offs...
void printTo(Print &printer) const
Print LocalTime to 'printer' in ISO 8601 format.
static LocalTime forError()
Factory method that returns an instance which indicates an error condition.
static LocalTime forComponents(uint8_t hour, uint8_t minute, uint8_t second)
Factory method using separated date, time, and time zone fields.
static LocalTime forTimeString(const char *timeString)
Factory method.
uint8_t hour() const
Return the hour.
uint8_t second() const
Return the second.
bool isError() const
Return true if any component is outside the normal time range of 00:00:00 to 23:59:59.
uint8_t minute() const
Return the minute.
LocalTime()
Default constructor does nothing.
friend bool operator==(const LocalTime &a, const LocalTime &b)
Return true if two LocalTime objects are equal.
static LocalTime forSeconds(acetime_t seconds)
Factory method.
int8_t compareTo(const LocalTime &that) const
Compare this LocalTime with that LocalTime, and return (<0, 0, >0) according to whether (this<that...