Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
TimeOfDay Struct Reference

A simple value type representing a time of day (hour, minute, second). More...

#include <TimeOfDay.h>

+ Collaboration diagram for TimeOfDay:

Public Member Functions

bool operator== (const TimeOfDay &other) const
 
bool operator!= (const TimeOfDay &other) const
 
bool operator< (const TimeOfDay &other) const
 
bool operator<= (const TimeOfDay &other) const
 
bool operator> (const TimeOfDay &other) const
 
bool operator>= (const TimeOfDay &other) const
 

Static Public Member Functions

static TimeOfDay fromString (const char *hhmm)
 Parse a string in the form "HH:MM" or "HH:MM:SS".
 
static std::string toString (const TimeOfDay &time)
 Format the time as a string.
 

Public Attributes

uint8_t hour = 0
 
uint8_t minute = 0
 
uint8_t second = 0
 

Detailed Description

Definition at line 21 of file TimeOfDay.h.

Member Function Documentation

◆ fromString()

static TimeOfDay TimeOfDay::fromString ( const char *  hhmm)
inlinestatic
Parameters
hhmmInput time string.
Returns
Parsed TimeOfDay (defaults to 00:00:00 on error).

Definition at line 32 of file TimeOfDay.h.

32 {
33 TimeOfDay t;
34 if (sscanf(hhmm, "%2hhu:%2hhu:%2hhu", &t.hour, &t.minute, &t.second) == 3) {
35 return t;
36 } else if (sscanf(hhmm, "%2hhu:%2hhu", &t.hour, &t.minute) == 2) {
37 t.second = 0;
38 return t;
39 }
40 return {0, 0, 0};
41 }
A simple value type representing a time of day (hour, minute, second).
Definition TimeOfDay.h:22
uint8_t hour
Definition TimeOfDay.h:23
uint8_t minute
Definition TimeOfDay.h:24
uint8_t second
Definition TimeOfDay.h:25

References hour, minute, and second.

Referenced by from_json().

+ Here is the caller graph for this function:

◆ operator!=()

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

Definition at line 64 of file TimeOfDay.h.

64 {
65 return !(*this == other);
66 }

◆ operator<()

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

Definition at line 68 of file TimeOfDay.h.

68 {
69 if (hour != other.hour) return hour < other.hour;
70 if (minute != other.minute) return minute < other.minute;
71 return second < other.second;
72 }

References hour, minute, and second.

◆ operator<=()

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

Definition at line 74 of file TimeOfDay.h.

74 {
75 return !(*this > other);
76 }

◆ operator==()

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

Definition at line 60 of file TimeOfDay.h.

60 {
61 return hour == other.hour && minute == other.minute && second == other.second;
62 }

References hour, minute, and second.

◆ operator>()

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

Definition at line 78 of file TimeOfDay.h.

78 {
79 return other < *this;
80 }

◆ operator>=()

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

Definition at line 82 of file TimeOfDay.h.

82 {
83 return !(*this < other);
84 }

◆ toString()

static std::string TimeOfDay::toString ( const TimeOfDay time)
inlinestatic
Parameters
timeInput time.
Returns
Formatted string, either "HH:MM" or "HH:MM:SS" depending on seconds.

Definition at line 48 of file TimeOfDay.h.

48 {
49 char buf[9];
50 if (time.second > 0) {
51 snprintf(buf, sizeof(buf), "%02u:%02u:%02u", time.hour, time.minute, time.second);
52 } else {
53 snprintf(buf, sizeof(buf), "%02u:%02u", time.hour, time.minute);
54 }
55 return std::string(buf);
56 }

References hour, minute, and second.

Referenced by to_json().

+ Here is the caller graph for this function:

Member Data Documentation

◆ hour

uint8_t TimeOfDay::hour = 0

Definition at line 23 of file TimeOfDay.h.

Referenced by fromString(), operator<(), operator==(), toSeconds(), and toString().

◆ minute

uint8_t TimeOfDay::minute = 0

Definition at line 24 of file TimeOfDay.h.

Referenced by fromString(), operator<(), operator==(), toSeconds(), and toString().

◆ second

uint8_t TimeOfDay::second = 0

Definition at line 25 of file TimeOfDay.h.

Referenced by fromString(), operator<(), operator==(), toSeconds(), and toString().


The documentation for this struct was generated from the following file: