semf
semf::Time Class Reference

The Time class provides clock time functions. More...

#include <time.h>

Inheritance diagram for semf::Time:
Inheritance graph
Collaboration diagram for semf::Time:
Collaboration graph

Public Member Functions

 Time ()=default
 
 Time (const Time &timeToSet)
 Copy constructor. More...
 
 Time (uint16_t millisecond, uint8_t second, uint8_t minute, uint8_t hour)
 Constructor for static time. More...
 
virtual ~Time ()=default
 
bool setTime (uint16_t millisecond, uint8_t second, uint8_t minute, uint8_t hour)
 Sets date time information and system clock if Rtc is registered. More...
 
uint16_t millisecond () const
 Returns the milliseconds from system clock or static value. More...
 
bool setMillisecond (uint16_t millisecond)
 Sets the milliseconds. More...
 
uint8_t second () const
 Returns the seconds from system clock or static value. More...
 
bool setSecond (uint8_t second)
 Sets the seconds. More...
 
uint8_t minute () const
 Returns the minutes. More...
 
bool setMinute (uint8_t minute)
 Sets the minutes. More...
 
uint8_t hour () const
 Returns the hours. More...
 
bool setHour (uint8_t hour)
 Sets the hours. More...
 
void addMilliseconds (int32_t milliseconds)
 Adds milliseconds to this time. More...
 
void addSeconds (int32_t seconds)
 Adds seconds to this time. More...
 
void addMinutes (int32_t minutes)
 Adds minutes to this time. More...
 
void addHours (int32_t hours)
 Adds hours to this time. More...
 
uint32_t secondsSinceStartOfDay () const
 Returns the seconds since start of the day. More...
 
uint32_t millisecondsSinceStartOfDay () const
 Returns the milliseconds since start of the day. More...
 
int32_t timeSpan (const Time &subtract) const
 Returns a time difference between this time and subtract. More...
 
Timeoperator= (const Time &timeToSet)
 Copies the time. More...
 
bool operator== (const Time &timeToCompareWith) const
 Compares this time with other. More...
 
bool operator!= (const Time &timeToCompareWith) const
 Compares this time with other. More...
 
bool operator< (const Time &timeToCompareWith) const
 Compares this time with other. More...
 
bool operator<= (const Time &timeToCompareWith) const
 Compares this time with other. More...
 
bool operator> (const Time &timeToCompareWith) const
 Compares this time with other. More...
 
bool operator>= (const Time &timeToCompareWith) const
 Compares this time with other. More...
 

Static Protected Member Functions

static bool isValid (uint16_t millisecond, uint8_t second, uint8_t minute, uint8_t hour)
 Returns if the given time is valid. More...
 

Detailed Description

The Time class provides clock time functions.

A Time object contains a time expressed as the numbers of hours, minutes, seconds, and milliseconds since midnight. It provides functions for comparing two Time objects and for altering a Time object by adding a number of milliseconds.

Time uses the 24-hour clock format; it has no concept of AM/PM. Unlike DateTime, Time knows nothing about time zones or daylight-saving time (DST).

A Time object is typically created either by giving the number of hours, minutes, seconds, and milliseconds explicitly.

The hours(), minutes(), seconds(), and milliseconds() functions provide access to the number of hours, minutes, seconds, and milliseconds of the time.

Definition at line 36 of file time.h.

Constructor & Destructor Documentation

◆ Time() [1/3]

semf::Time::Time ( )
default

◆ Time() [2/3]

semf::Time::Time ( const Time timeToSet)

Copy constructor.

Parameters
timeToSetCopy time information into this object.
Note
The Rtc interface will not be copied.

Definition at line 15 of file time.cpp.

Here is the call graph for this function:

◆ Time() [3/3]

semf::Time::Time ( uint16_t  millisecond,
uint8_t  second,
uint8_t  minute,
uint8_t  hour 
)

Constructor for static time.

Parameters
millisecondMilliseconds for static time.
secondSeconds for static time.
minuteMinutes for static time.
hourHours for static time.

Definition at line 20 of file time.cpp.

Here is the call graph for this function:

◆ ~Time()

virtual semf::Time::~Time ( )
virtualdefault

Member Function Documentation

◆ addHours()

void semf::Time::addHours ( int32_t  hours)

Adds hours to this time.

Parameters
hoursHours to add.

Definition at line 204 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMilliseconds()

void semf::Time::addMilliseconds ( int32_t  milliseconds)

Adds milliseconds to this time.

Parameters
millisecondsMilliseconds to add.

Definition at line 123 of file time.cpp.

Here is the call graph for this function:

◆ addMinutes()

void semf::Time::addMinutes ( int32_t  minutes)

Adds minutes to this time.

Parameters
minutesMinutes to add.

Definition at line 177 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addSeconds()

void semf::Time::addSeconds ( int32_t  seconds)

Adds seconds to this time.

Parameters
secondsSeconds to add.

Definition at line 150 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hour()

uint8_t semf::Time::hour ( ) const

Returns the hours.

Returns
Hour setting.

Definition at line 103 of file time.cpp.

Here is the caller graph for this function:

◆ isValid()

bool semf::Time::isValid ( uint16_t  millisecond,
uint8_t  second,
uint8_t  minute,
uint8_t  hour 
)
staticprotected

Returns if the given time is valid.

Parameters
millisecondMillisecond to check.
secondSecond to check.
minuteMinute to check.
hourHour to check.
Returns
true for time setting is valid, false for not.

Definition at line 300 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ millisecond()

uint16_t semf::Time::millisecond ( ) const

Returns the milliseconds from system clock or static value.

Returns
Millisecond setting.

Definition at line 43 of file time.cpp.

Here is the caller graph for this function:

◆ millisecondsSinceStartOfDay()

uint32_t semf::Time::millisecondsSinceStartOfDay ( ) const

Returns the milliseconds since start of the day.

Returns
Milliseconds since start of the day.

Definition at line 229 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ minute()

uint8_t semf::Time::minute ( ) const

Returns the minutes.

Returns
Minute setting.

Definition at line 83 of file time.cpp.

Here is the caller graph for this function:

◆ operator!=()

bool semf::Time::operator!= ( const Time timeToCompareWith) const

Compares this time with other.

Parameters
timeToCompareWithtime to compare.
Returns
true if times are different; false if dates are the same.

Definition at line 258 of file time.cpp.

◆ operator<()

bool semf::Time::operator< ( const Time timeToCompareWith) const

Compares this time with other.

Parameters
timeToCompareWithtime to compare.
Returns
true if this time is smaller; false if not.

Definition at line 263 of file time.cpp.

Here is the call graph for this function:

◆ operator<=()

bool semf::Time::operator<= ( const Time timeToCompareWith) const

Compares this time with other.

Parameters
timeToCompareWithtime to compare.
Returns
true if this time is smaller or equal; false if not.

Definition at line 278 of file time.cpp.

◆ operator=()

Time & semf::Time::operator= ( const Time timeToSet)

Copies the time.

Parameters
timeToSetSource to copy the time information from.
Note
The Rtc interface will not be copied.
Returns
time object itself.

Definition at line 239 of file time.cpp.

Here is the call graph for this function:

◆ operator==()

bool semf::Time::operator== ( const Time timeToCompareWith) const

Compares this time with other.

Parameters
timeToCompareWithtime to compare.
Returns
true if times are the same; false if dates are different.

Definition at line 245 of file time.cpp.

Here is the call graph for this function:

◆ operator>()

bool semf::Time::operator> ( const Time timeToCompareWith) const

Compares this time with other.

Parameters
timeToCompareWithtime to compare.
Returns
true if this time is larger; false if not.

Definition at line 290 of file time.cpp.

◆ operator>=()

bool semf::Time::operator>= ( const Time timeToCompareWith) const

Compares this time with other.

Parameters
timeToCompareWithtime to compare.
Returns
true if this time is larger or equal; false if not.

Definition at line 295 of file time.cpp.

◆ second()

uint8_t semf::Time::second ( ) const

Returns the seconds from system clock or static value.

Returns
Second setting.

Definition at line 63 of file time.cpp.

Here is the caller graph for this function:

◆ secondsSinceStartOfDay()

uint32_t semf::Time::secondsSinceStartOfDay ( ) const

Returns the seconds since start of the day.

Returns
Seconds since start of the day.

Definition at line 224 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHour()

bool semf::Time::setHour ( uint8_t  hour)

Sets the hours.

Parameters
hourHours setting.
Returns
true for time is valid, false for not.

Definition at line 108 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMillisecond()

bool semf::Time::setMillisecond ( uint16_t  millisecond)

Sets the milliseconds.

Parameters
millisecondMillisecond setting.
Returns
true for time is valid, false for not.

Definition at line 48 of file time.cpp.

Here is the call graph for this function:

◆ setMinute()

bool semf::Time::setMinute ( uint8_t  minute)

Sets the minutes.

Parameters
minuteMinutes setting.
Returns
true for time is valid, false for not.

Definition at line 88 of file time.cpp.

Here is the call graph for this function:

◆ setSecond()

bool semf::Time::setSecond ( uint8_t  second)

Sets the seconds.

Parameters
secondSecond setting.
Returns
true for time is valid, false for not.

Definition at line 68 of file time.cpp.

Here is the call graph for this function:

◆ setTime()

bool semf::Time::setTime ( uint16_t  millisecond,
uint8_t  second,
uint8_t  minute,
uint8_t  hour 
)

Sets date time information and system clock if Rtc is registered.

Parameters
millisecondMilliseconds to set.
secondSeconds to set.
minuteMinutes to set.
hourHours to set.
Returns
true for time is valid, false for not.

Definition at line 25 of file time.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeSpan()

int32_t semf::Time::timeSpan ( const Time subtract) const

Returns a time difference between this time and subtract.

Parameters
subtractTime to be subtracted.
Returns
time difference in milliseconds.

Definition at line 234 of file time.cpp.

Here is the call graph for this function: