LocalTimeRK
Public Member Functions | Data Fields
LocalTimeHMS Class Reference

Container for holding an hour minute second time value. More...

#include <LocalTimeRK.h>

Inheritance diagram for LocalTimeHMS:
LocalTimeHMSRestricted LocalTimeIgnoreHMS

Public Member Functions

 LocalTimeHMS ()
 Default constructor. Sets time to 00:00:00.
 
virtual ~LocalTimeHMS ()
 Destructor.
 
 LocalTimeHMS (const char *str)
 Constructs the object from a time string. More...
 
 LocalTimeHMS (const LocalTimeValue &value)
 Construct this HMS from a LocalTimeValue (which contains YMD and HMS) More...
 
void clear ()
 Sets the hour, minute, and second to 0.
 
void parse (const char *str)
 Parse a "H:MM:SS" string. More...
 
String toString () const
 Turns the parsed data into a normalized string of the form: "HH:MM:SS" (24-hour clock, with leading zeroes)
 
int toSeconds () const
 Convert hour minute second into a number of seconds (simple multiplication and addition)
 
void fromTimeInfo (const struct tm *pTimeInfo)
 Sets the hour, minute, and second fields from a struct tm.
 
void fromLocalTimeValue (const LocalTimeValue &value)
 Sets the HMS from a LocalTimeValue. More...
 
void toTimeInfo (struct tm *pTimeInfo) const
 Fill in the tm_hour, tm_min, and tm_sec fields of a struct tm from the values in this object. More...
 
void adjustTimeInfo (struct tm *pTimeInfo) const
 Adjust the values in a struct tm from the values in this object. More...
 
void fromJson (JSONValue jsonObj)
 Parses a JSON value of type string in HH:MM:SS format. More...
 
LocalTimeHMSwithHour (int hour)
 Sets this object to be the specified hour, with minute and second set to 0. More...
 
LocalTimeHMSwithHourMinute (int hour, int minute)
 Sets this object to be the specified hour and minute, with second set to 0. More...
 
int compareTo (const LocalTimeHMS &other) const
 Compare two LocalTimeHMS objects. More...
 
bool operator== (const LocalTimeHMS &other) const
 Returns true if this item is equal to other. Compares hour, minute, and second. More...
 
bool operator!= (const LocalTimeHMS &other) const
 Returns true if this item is not equal to other. More...
 
bool operator< (const LocalTimeHMS &other) const
 Returns true if this item is < other. More...
 
bool operator> (const LocalTimeHMS &other) const
 Returns true if this item is > other. More...
 
bool operator<= (const LocalTimeHMS &other) const
 Returns true if this item <= other. More...
 
bool operator>= (const LocalTimeHMS &other) const
 Returns true if this item is >= other. More...
 

Data Fields

int8_t hour = 0
 0-23 hour (could also be negative)
 
int8_t minute = 0
 0-59 minute
 
int8_t second = 0
 0-59 second
 
int8_t ignore = 0
 Special case.
 

Detailed Description

Container for holding an hour minute second time value.

Constructor & Destructor Documentation

◆ LocalTimeHMS() [1/2]

LocalTimeHMS::LocalTimeHMS ( const char *  str)

Constructs the object from a time string.

Parameters
strThe time string

The time string is normally of the form HH:MM:SS, such as "04:00:00" for 4:00 AM. The hour is in 24-hour format. Other formats are supported as well, including omitting the seconds (04:00), or including only the hour "04", or omitting the leadings zeros (4:0:0).

Additionally, the hour could be negative, used in UTC DST offsets. The minute and second are always positive (0-59). The hour could also be > 24 when used as a timezone offset.

◆ LocalTimeHMS() [2/2]

LocalTimeHMS::LocalTimeHMS ( const LocalTimeValue value)

Construct this HMS from a LocalTimeValue (which contains YMD and HMS)

Parameters
value

Member Function Documentation

◆ adjustTimeInfo()

void LocalTimeHMS::adjustTimeInfo ( struct tm *  pTimeInfo) const

Adjust the values in a struct tm from the values in this object.

Parameters
pTimeInfoThe struct tm to modify

After calling this, the values in the struct tm may be out of range, for example tm_hour > 23. This is fine, as calling mktime/gmtime normalizes this case and carries out-of-range values into the other fields as necessary.

◆ compareTo()

int LocalTimeHMS::compareTo ( const LocalTimeHMS other) const
inline

Compare two LocalTimeHMS objects.

Parameters
otherThe item to compare to
Returns
int -1 if this item is < other; 0 if this = other, or +1 if this > other

◆ fromJson()

void LocalTimeHMS::fromJson ( JSONValue  jsonObj)

Parses a JSON value of type string in HH:MM:SS format.

Parameters
jsonObj

◆ fromLocalTimeValue()

void LocalTimeHMS::fromLocalTimeValue ( const LocalTimeValue value)

Sets the HMS from a LocalTimeValue.

Parameters
value

◆ operator!=()

bool LocalTimeHMS::operator!= ( const LocalTimeHMS other) const
inline

Returns true if this item is not equal to other.

Parameters
other
Returns
true
false

◆ operator<()

bool LocalTimeHMS::operator< ( const LocalTimeHMS other) const
inline

Returns true if this item is < other.

Parameters
other
Returns
true
false

◆ operator<=()

bool LocalTimeHMS::operator<= ( const LocalTimeHMS other) const
inline

Returns true if this item <= other.

Parameters
other
Returns
true
false

◆ operator==()

bool LocalTimeHMS::operator== ( const LocalTimeHMS other) const
inline

Returns true if this item is equal to other. Compares hour, minute, and second.

Parameters
other
Returns
true
false

◆ operator>()

bool LocalTimeHMS::operator> ( const LocalTimeHMS other) const
inline

Returns true if this item is > other.

Parameters
other
Returns
true
false

◆ operator>=()

bool LocalTimeHMS::operator>= ( const LocalTimeHMS other) const
inline

Returns true if this item is >= other.

Parameters
other
Returns
true
false

◆ parse()

void LocalTimeHMS::parse ( const char *  str)

Parse a "H:MM:SS" string.

Parameters
strInput string

Multiple formats are supported, and parts are optional:

  • H:MM:SS (examples: "2:00:00" or "2:0:0")
  • H:MM (examples: "2:00" or "2:0")
  • H (examples: "2")

Hours are always 0 - 23 (24-hour clock). Can also be a negative hour -1 to -23.

◆ toTimeInfo()

void LocalTimeHMS::toTimeInfo ( struct tm *  pTimeInfo) const

Fill in the tm_hour, tm_min, and tm_sec fields of a struct tm from the values in this object.

Parameters
pTimeInfoThe struct tm to modify

◆ withHour()

LocalTimeHMS & LocalTimeHMS::withHour ( int  hour)
inline

Sets this object to be the specified hour, with minute and second set to 0.

Parameters
hour0 <= hour < 24
Returns
LocalTimeHMS&

◆ withHourMinute()

LocalTimeHMS & LocalTimeHMS::withHourMinute ( int  hour,
int  minute 
)
inline

Sets this object to be the specified hour and minute, with second set to 0.

Parameters
hour0 <= hour < 24
minute0 <= minute < 60
Returns
LocalTimeHMS&

The documentation for this class was generated from the following files: