6 #ifndef ACE_TIME_TIME_OFFSET_H
7 #define ACE_TIME_TIME_OFFSET_H
19 namespace time_offset_mutation {
75 int32_t minutes = (hour * int32_t(60) + minute) * 60;
85 int8_t hour, int8_t minute, int8_t second) {
86 int32_t seconds = (hour * int32_t(60) + minute) * 60 + second;
139 int32_t minutes = mSeconds / 60;
141 minute = minutes % 60;
150 int8_t& hour, int8_t& minute, int8_t& second)
const {
151 int32_t minutes = mSeconds / 60;
152 second = mSeconds % 60;
154 minute = minutes % 60;
162 bool isZero()
const {
return mSeconds == 0; }
166 return mSeconds == kErrorSeconds;
175 void printTo(Print& printer)
const;
185 friend void time_offset_mutation::incrementHour(
TimeOffset& offset);
186 friend void time_offset_mutation::increment15Minutes(
TimeOffset& offset);
193 void setMinutes(int16_t minutes) {
194 mSeconds = minutes * int32_t(60);
198 void setSeconds(int32_t seconds) {
204 static const int32_t kErrorSeconds = INT32_MIN;
210 int32_t mSeconds = 0;
213 inline bool operator==(
const TimeOffset& a,
const TimeOffset& b) {
214 return a.mSeconds == b.mSeconds;
217 inline bool operator!=(
const TimeOffset& a,
const TimeOffset& b) {
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
void toHourMinuteSecond(int8_t &hour, int8_t &minute, int8_t &second) const
Extract hour, minute, second from the offset.
int16_t toMinutes() const
Return the time offset as minutes.
void toHourMinute(int8_t &hour, int8_t &minute) const
Extract hour and minute representation of the offset.
static TimeOffset forOffsetString(const char *offsetString)
Create from an offset string (e.g.
bool isZero() const
Returns true if offset is 00:00.
static TimeOffset forError()
Return an error indicator.
int32_t toSeconds() const
Return the time offset as seconds.
static TimeOffset forSeconds(int32_t seconds)
Create TimeOffset from seconds from 00:00.
static TimeOffset forHourMinuteSecond(int8_t hour, int8_t minute, int8_t second)
Create a TimeOffset fro (hour, minute, second) offset.
static TimeOffset forHours(int8_t hours)
Create TimeOffset with the corresponding hour offset.
static TimeOffset forHourMinute(int8_t hour, int8_t minute)
Create TimeOffset from (hour, minute) offset.
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
void printTo(Print &printer) const
Print the human readable string, including a "-" or "+" prefix, in the form of "+/-hh:mm" or "+/-hh:m...
static TimeOffset forOffsetStringChainable(const char *&offsetString)
Variant of forOffsetString() that updates the string pointer to the next unprocessed character.
bool isError() const
Return true if this TimeOffset represents an error.
void incrementHour(OffsetDateTime &dateTime)
Increment the hour by one within the interval [0, 23].
void increment15Minutes(TimeOffset &offset)
Increment the TimeOffset by 15 minute interval.