semf
semf::DateTime Class Reference

The DateTime class provides date and time functionality as a point of time. It combines features of the Date and Time classes (via inheritance). More...

#include <datetime.h>

Inheritance diagram for semf::DateTime:
Inheritance graph
Collaboration diagram for semf::DateTime:
Collaboration graph

Public Member Functions

 DateTime ()=default
 
 DateTime (uint16_t millisecond, uint8_t second, uint8_t minute, uint8_t hour, uint8_t day, Month month, uint16_t year)
 Copy Constructor. More...
 
 DateTime (uint64_t unixTimeInSeconds)
 Sets date time information. More...
 
virtual ~DateTime ()=default
 
bool setDateTime (uint16_t millisecond, uint8_t second, uint8_t minute, uint8_t hour, uint8_t day, Month month, uint16_t year)
 Sets date time information and system clock if Rtc is registered. More...
 
bool setDateTime (const Time &copyFromTime, const Date &copyFromDate)
 Sets date time information. More...
 
void setDateTime (uint64_t unixTimeInSeconds)
 Sets date time information. More...
 
uint64_t unixTimeInSeconds () const
 Returns the date time in seconds since the 1 January 1970. More...
 
void addHours (int32_t hours)
 Adds hours to this datetime. More...
 
bool operator== (const DateTime &other) const
 Compares this date time with other. More...
 
bool operator!= (const DateTime &other) const
 Compares this date time with other. More...
 
bool operator< (const DateTime &other) const
 Compares this date time with other. More...
 
bool operator<= (const DateTime &other) const
 Compares this date time with other. More...
 
bool operator> (const DateTime &other) const
 Compares this date time with other. More...
 
bool operator>= (const DateTime &other) const
 Compares this date time with other. More...
 
- Public Member Functions inherited from semf::Date
 Date ()=default
 
 Date (uint8_t day, Month month, uint16_t year)
 Constructor. More...
 
virtual ~Date ()=default
 
bool setDate (uint8_t day, Month month, uint16_t year)
 Sets date information. More...
 
uint8_t day () const
 Returns the day. More...
 
bool setDay (uint8_t day)
 Sets a day. More...
 
Month month () const
 Returns the month. More...
 
bool setMonth (Month month)
 Sets a month. More...
 
uint16_t year () const
 Returns the year. More...
 
bool setYear (uint16_t year)
 Sets a year. More...
 
void addDays (int32_t days)
 Adds days to this date. More...
 
Weekday weekday () const
 Returns the day in the week of the actual Date. More...
 
void addMonths (int32_t months)
 Adds months to this date. More...
 
void addYears (int32_t years)
 Adds years to this date. More...
 
bool operator== (const Date &dateToCompareWith) const
 Compares this date with other. More...
 
bool operator!= (const Date &dateToCompareWith) const
 Compares this date with other. More...
 
bool operator< (const Date &dateToCompareWith) const
 Compares this date with other. More...
 
bool operator<= (const Date &dateToCompareWith) const
 Compares this date with other. More...
 
bool operator> (const Date &dateToCompareWith) const
 Compares this date with other. More...
 
bool operator>= (const Date &dateToCompareWith) const
 Compares this date with other. More...
 
- Public Member Functions inherited from semf::Time
 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...
 

Additional Inherited Members

- Public Types inherited from semf::Date
enum  Month {
  January = 1 , February , March , April ,
  May , June , July , August ,
  September , October , November , December
}
 
enum  Weekday {
  Sunday = 0 , Monday , Tuesday , Wednesday ,
  Thursday , Friday , Saturday
}
 
- Static Protected Member Functions inherited from semf::Date
static uint8_t daysInMonth (Month month, uint16_t year)
 Returns the number of days in a specific month and year. More...
 
static bool isLeapYear (uint16_t year)
 Returns if a specific year is a leap year or not. More...
 
static bool isValid (uint8_t day, Month month, uint16_t year)
 Returns if the given date is valid. More...
 
- Static Protected Member Functions inherited from semf::Time
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 DateTime class provides date and time functionality as a point of time. It combines features of the Date and Time classes (via inheritance).

The date and time can be modified by

DateTime provides a full set of operators to compare two DateTime objects where smaller means earlier, and larger means later.

Definition at line 30 of file datetime.h.

Constructor & Destructor Documentation

◆ DateTime() [1/3]

semf::DateTime::DateTime ( )
default

◆ DateTime() [2/3]

semf::DateTime::DateTime ( uint16_t  millisecond,
uint8_t  second,
uint8_t  minute,
uint8_t  hour,
uint8_t  day,
Month  month,
uint16_t  year 
)

Copy Constructor.

Parameters
millisecondMilliseconds to set.
secondSeconds to set.
minuteMinutes to set.
hourHours to set.
dayDay to set.
monthMonth to set.
yearYear to set.

Definition at line 15 of file datetime.cpp.

Here is the call graph for this function:

◆ DateTime() [3/3]

semf::DateTime::DateTime ( uint64_t  unixTimeInSeconds)
explicit

Sets date time information.

Parameters
unixTimeInSecondsUnix time in seconds.

Definition at line 20 of file datetime.cpp.

Here is the call graph for this function:

◆ ~DateTime()

virtual semf::DateTime::~DateTime ( )
virtualdefault

Member Function Documentation

◆ addHours()

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

Adds hours to this datetime.

Parameters
hoursHours to add.

Definition at line 125 of file datetime.cpp.

Here is the call graph for this function:

◆ operator!=()

bool semf::DateTime::operator!= ( const DateTime other) const

Compares this date time with other.

Parameters
otherdate time to compare.
Returns
true if date times are different; false if date times are the same.

Definition at line 164 of file datetime.cpp.

◆ operator<()

bool semf::DateTime::operator< ( const DateTime other) const

Compares this date time with other.

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

Definition at line 169 of file datetime.cpp.

◆ operator<=()

bool semf::DateTime::operator<= ( const DateTime other) const

Compares this date time with other.

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

Definition at line 181 of file datetime.cpp.

◆ operator==()

bool semf::DateTime::operator== ( const DateTime other) const

Compares this date time with other.

Parameters
otherdate time to compare.
Returns
true if date times are the same; false if date times are different.

Definition at line 152 of file datetime.cpp.

◆ operator>()

bool semf::DateTime::operator> ( const DateTime other) const

Compares this date time with other.

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

Definition at line 186 of file datetime.cpp.

◆ operator>=()

bool semf::DateTime::operator>= ( const DateTime other) const

Compares this date time with other.

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

Definition at line 191 of file datetime.cpp.

◆ setDateTime() [1/3]

bool semf::DateTime::setDateTime ( const Time copyFromTime,
const Date copyFromDate 
)

Sets date time information.

Parameters
copyFromTimeTime to set.
copyFromDateDate to set.
Returns
true for DateTime is valid, false for not.

Definition at line 41 of file datetime.cpp.

Here is the call graph for this function:

◆ setDateTime() [2/3]

bool semf::DateTime::setDateTime ( uint16_t  millisecond,
uint8_t  second,
uint8_t  minute,
uint8_t  hour,
uint8_t  day,
Month  month,
uint16_t  year 
)

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

Parameters
millisecondMilliseconds to set.
secondSeconds to set.
minuteMinutes to set.
hourHours to set.
dayDay to set.
monthMonth to set.
yearYear to set.
Returns
true for DateTime is valid, false for not.

Definition at line 25 of file datetime.cpp.

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

◆ setDateTime() [3/3]

void semf::DateTime::setDateTime ( uint64_t  unixTimeInSeconds)

Sets date time information.

Parameters
unixTimeInSecondsUnix time in seconds.

Definition at line 47 of file datetime.cpp.

Here is the call graph for this function:

◆ unixTimeInSeconds()

uint64_t semf::DateTime::unixTimeInSeconds ( ) const

Returns the date time in seconds since the 1 January 1970.

Returns
unix time in seconds.

Definition at line 82 of file datetime.cpp.

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