semf
semf::Date Class Reference

The Date class provides date functions. More...

#include <date.h>

Inheritance diagram for semf::Date:
Inheritance graph
Collaboration diagram for semf::Date:
Collaboration graph

Public Types

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
}
 

Public Member Functions

 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...
 

Static Protected Member Functions

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...
 

Detailed Description

The Date class provides date functions.

A Date object represents a particular date, i.e. a calendar date with year, month, and day numbers.

A Date object is typically created by giving the year, month, and day numbers explicitly. An explicit date can also be set using setDate(). The year(), month(), and day() functions provide access to the year, month, and day numbers.

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

Note
Note that Date interprets year numbers less than 100 literally, i.e. as years 1 through 99, without adding any offset.

Definition at line 33 of file date.h.

Member Enumeration Documentation

◆ Month

Enumeration of months. Starting with January is 1, December is 12.

Enumerator
January 
February 
March 
April 
May 
June 
July 
August 
September 
October 
November 
December 

Definition at line 37 of file date.h.

◆ Weekday

Enumeration of days in a week. Starting with Sunday is 0, Saturday is 6.

Enumerator
Sunday 
Monday 
Tuesday 
Wednesday 
Thursday 
Friday 
Saturday 

Definition at line 53 of file date.h.

Constructor & Destructor Documentation

◆ Date() [1/2]

semf::Date::Date ( )
default

◆ Date() [2/2]

semf::Date::Date ( uint8_t  day,
Month  month,
uint16_t  year 
)

Constructor.

Parameters
dayDay to set.
monthMonth to set.
yearYear to set.

Definition at line 15 of file date.cpp.

Here is the call graph for this function:

◆ ~Date()

virtual semf::Date::~Date ( )
virtualdefault

Member Function Documentation

◆ addDays()

void semf::Date::addDays ( int32_t  days)

Adds days to this date.

Parameters
daysDays to add.

Definition at line 97 of file date.cpp.

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

◆ addMonths()

void semf::Date::addMonths ( int32_t  months)

Adds months to this date.

Parameters
monthsMonths to add.

Definition at line 138 of file date.cpp.

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

◆ addYears()

void semf::Date::addYears ( int32_t  years)

Adds years to this date.

Parameters
yearsYears to add.

Definition at line 162 of file date.cpp.

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

◆ day()

uint8_t semf::Date::day ( ) const

Returns the day.

Returns
Day setting.

Definition at line 37 of file date.cpp.

Here is the caller graph for this function:

◆ daysInMonth()

uint8_t semf::Date::daysInMonth ( Month  month,
uint16_t  year 
)
staticprotected

Returns the number of days in a specific month and year.

Returns "0" for invalid month and year setting.

Parameters
monthMonth to get the number of days from.
yearYear in which the month is in.
Returns
Number of days.

Definition at line 230 of file date.cpp.

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

◆ isLeapYear()

bool semf::Date::isLeapYear ( uint16_t  year)
staticprotected

Returns if a specific year is a leap year or not.

Parameters
yearYear to check leap lear.
Returns
true for is a leap year, false for is no leap year.

Definition at line 260 of file date.cpp.

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

◆ isValid()

bool semf::Date::isValid ( uint8_t  day,
Month  month,
uint16_t  year 
)
staticprotected

Returns if the given date is valid.

Parameters
dayDay to check.
monthMonth to check.
yearYear to check.
Returns
true for date setting is valid, false for not.

Definition at line 265 of file date.cpp.

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

◆ month()

Date::Month semf::Date::month ( ) const

Returns the month.

Returns
Month setting.

Definition at line 57 of file date.cpp.

Here is the caller graph for this function:

◆ operator!=()

bool semf::Date::operator!= ( const Date dateToCompareWith) const

Compares this date with other.

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

Definition at line 197 of file date.cpp.

◆ operator<()

bool semf::Date::operator< ( const Date dateToCompareWith) const

Compares this date with other.

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

Definition at line 202 of file date.cpp.

Here is the call graph for this function:

◆ operator<=()

bool semf::Date::operator<= ( const Date dateToCompareWith) const

Compares this date with other.

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

Definition at line 215 of file date.cpp.

◆ operator==()

bool semf::Date::operator== ( const Date dateToCompareWith) const

Compares this date with other.

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

Definition at line 185 of file date.cpp.

Here is the call graph for this function:

◆ operator>()

bool semf::Date::operator> ( const Date dateToCompareWith) const

Compares this date with other.

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

Definition at line 220 of file date.cpp.

◆ operator>=()

bool semf::Date::operator>= ( const Date dateToCompareWith) const

Compares this date with other.

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

Definition at line 225 of file date.cpp.

◆ setDate()

bool semf::Date::setDate ( uint8_t  day,
Month  month,
uint16_t  year 
)

Sets date information.

Parameters
dayDay to set.
monthMonth to set.
yearYear to set.
Returns
true for date setting is valid, false for not.

Definition at line 20 of file date.cpp.

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

◆ setDay()

bool semf::Date::setDay ( uint8_t  day)

Sets a day.

Parameters
dayDay setting.
Returns
true for day setting is valid, false for not.

Definition at line 42 of file date.cpp.

Here is the call graph for this function:

◆ setMonth()

bool semf::Date::setMonth ( Month  month)

Sets a month.

Parameters
monthMonth setting.
Returns
true for month setting is valid, false for not.

Definition at line 62 of file date.cpp.

Here is the call graph for this function:

◆ setYear()

bool semf::Date::setYear ( uint16_t  year)

Sets a year.

Parameters
yearYear setting.
Returns
true for year setting is valid, false for not.

Definition at line 82 of file date.cpp.

Here is the call graph for this function:

◆ weekday()

Date::Weekday semf::Date::weekday ( ) const

Returns the day in the week of the actual Date.

Returns
Day in week.
See also
Weekday

Definition at line 175 of file date.cpp.

◆ year()

uint16_t semf::Date::year ( ) const

Returns the year.

Returns
Year setting.

Definition at line 77 of file date.cpp.

Here is the caller graph for this function: