HomeWaterLeaksDetection
DateTime Class Reference

#include <DateTime.h>

Public Member Functions

String getDateTimeStr () const
 Returns the current datatime in a string format. More...
 
String getDateStr () const
 Returns the current day in a string format. More...
 
String getTimeStr () const
 Returns the current time in a string format. More...
 
RTCDateTime getDateTime () const
 Returns the current datatime. More...
 
const String getHTMLData (const int id) const
 Since this class is registered as a source of data for the HTML content, it needs return the appropriate value according to the id given as a parameter. More...
 

Static Public Member Functions

static DateTimegetInstance ()
 Returns the instance of the class. More...
 

Private Member Functions

 DateTime ()
 Constructor of the class. More...
 
 ~DateTime ()
 Destructor of the class. More...
 
 DateTime (DateTime const &)
 Copy constructor of the class. More...
 
DateTimeoperator= (DateTime const &)
 Assignment operator of the class. More...
 

Private Attributes

DS3231 rtc
 real-time module More...
 
String startDate
 start day of the system More...
 
String startTime
 start time of the system More...
 
std::map< int, String(*)(const DateTime &dateTime)> htmlData
 A map of different values (keys) and their associated functions which returns the appropriate values. More...
 

Static Private Attributes

static DateTimeinstance = NULL
 the instance of the class (Singleton) More...
 

Friends

String HTML_startDate (const DateTime &dateTime)
 Associated function for returing the start day of the device. More...
 
String HTML_startTime (const DateTime &dateTime)
 Associated function for returing the start time of the device. More...
 

Additional Inherited Members

- Static Public Attributes inherited from HTMLDataSource
static const String UNDEFINED_DATA = String("UNDEFINED")
 string "UNDEFINED" More...
 

Detailed Description

Author
silhavyj A17B0362P

This class holds information about datetimes. This includes values such as the system start time, current datatime, etc. If the webserver is enabled, this class also works a source of data for the HTML content.

Definition at line 158 of file DateTime.h.

Constructor & Destructor Documentation

◆ DateTime() [1/2]

DateTime::DateTime ( )
private

Constructor of the class.

Definition at line 10 of file DateTime.cpp.

10  {
11  rtc.begin();
12 
13  // SETTING THE DATE TIME for the first time
14  // rtc.setDateTime(__DATE__, __TIME__);
15 
16  startTime = getTimeStr(); // time when the device started
17  startDate = getDateStr(); // date when the device started
18 
19  #ifdef WEB_SERVER
20  // functions providing data to the webserver
21  htmlData[130] = &HTML_startDate;
22  htmlData[190] = &HTML_startTime;
23  #endif
24 }

References getDateStr(), getTimeStr(), HTML_startDate, HTML_startTime, htmlData, rtc, startDate, and startTime.

Referenced by getInstance().

◆ ~DateTime()

DateTime::~DateTime ( )
private

Destructor of the class.

◆ DateTime() [2/2]

DateTime::DateTime ( DateTime const &  )
inlineprivate

Copy constructor of the class.

Definition at line 179 of file DateTime.h.

179 {};

Member Function Documentation

◆ getDateStr()

String DateTime::getDateStr ( ) const

Returns the current day in a string format.

Returns
the current day as a string

Definition at line 39 of file DateTime.cpp.

39  {
40  RTCDateTime dateTime = rtc.getDateTime();
41  String date = String(dateTime.day) + "." +
42  String(dateTime.month) + "." +
43  String(dateTime.year);
44  return date;
45 }

References rtc.

Referenced by DateTime(), and getDateTimeStr().

◆ getDateTime()

RTCDateTime DateTime::getDateTime ( ) const

Returns the current datatime.

Returns
the current datetime

Definition at line 51 of file DateTime.cpp.

51  {
52  return rtc.getDateTime();
53 }

References rtc.

Referenced by Consumption::Consumption(), DailyOverview::DailyOverview(), Consumption::update(), and DailyOverview::update().

◆ getDateTimeStr()

String DateTime::getDateTimeStr ( ) const

Returns the current datatime in a string format.

Returns
the current datatime as a string

Definition at line 47 of file DateTime.cpp.

47  {
48  return getDateStr() + " | " + getTimeStr();
49 }

References getDateStr(), and getTimeStr().

Referenced by LowLeakDetection::testActiveLeak(), HighLeakDetection::testActiveLeak(), and TotalLeakDetection::testActiveLeak().

◆ getHTMLData()

const String DateTime::getHTMLData ( const int  id) const
virtual

Since this class is registered as a source of data for the HTML content, it needs return the appropriate value according to the id given as a parameter.

Parameters
id- the id of the piece of data
Returns
If the class holds this piece of information, it will return it. Otherwise, "UNDEFINED" will be returned.

Implements HTMLDataSource.

◆ getInstance()

DateTime * DateTime::getInstance ( )
static

Returns the instance of the class.

If the instance has not been created, it will create it and then return it.

Returns
the instance of the class

Definition at line 26 of file DateTime.cpp.

26  {
27  if (instance == NULL)
28  instance = new DateTime;
29  return instance;
30 }

References DateTime(), and instance.

Referenced by Consumption::Consumption(), DailyOverview::DailyOverview(), setup(), LowLeakDetection::testActiveLeak(), HighLeakDetection::testActiveLeak(), TotalLeakDetection::testActiveLeak(), Consumption::update(), DailyOverview::update(), and LeaksController::update().

◆ getTimeStr()

String DateTime::getTimeStr ( ) const

Returns the current time in a string format.

Returns
the current time as a string

Definition at line 32 of file DateTime.cpp.

32  {
33  RTCDateTime dateTime = rtc.getDateTime();
34  String time = String(FORMAT_2_DIGITS(dateTime.hour)) + ":" +
35  String(FORMAT_2_DIGITS(dateTime.minute));
36  return time;
37 }

References FORMAT_2_DIGITS, and rtc.

Referenced by DateTime(), and getDateTimeStr().

◆ operator=()

DateTime& DateTime::operator= ( DateTime const &  )
inlineprivate

Assignment operator of the class.

Definition at line 182 of file DateTime.h.

182 { return *this; }

Friends And Related Function Documentation

◆ HTML_startDate

String HTML_startDate ( const DateTime dateTime)
friend

Associated function for returing the start day of the device.

Parameters
dateTime- the instance of the DateTime class
Returns
the device start day

Referenced by DateTime().

◆ HTML_startTime

String HTML_startTime ( const DateTime dateTime)
friend

Associated function for returing the start time of the device.

Parameters
dateTime- the instance of the DateTime class
Returns
the device start time

Referenced by DateTime().

Member Data Documentation

◆ htmlData

std::map<int, String (*)(const DateTime& dateTime)> DateTime::htmlData
private

A map of different values (keys) and their associated functions which returns the appropriate values.

Definition at line 215 of file DateTime.h.

Referenced by DateTime().

◆ instance

DateTime * DateTime::instance = NULL
staticprivate

the instance of the class (Singleton)

Definition at line 165 of file DateTime.h.

Referenced by getInstance().

◆ rtc

DS3231 DateTime::rtc
private

real-time module

Definition at line 166 of file DateTime.h.

Referenced by DateTime(), getDateStr(), getDateTime(), and getTimeStr().

◆ startDate

String DateTime::startDate
private

start day of the system

Definition at line 167 of file DateTime.h.

Referenced by DateTime().

◆ startTime

String DateTime::startTime
private

start time of the system

Definition at line 168 of file DateTime.h.

Referenced by DateTime().


The documentation for this class was generated from the following files:
DateTime::instance
static DateTime * instance
the instance of the class (Singleton)
Definition: DateTime.h:165
FORMAT_2_DIGITS
#define FORMAT_2_DIGITS(x)
Converts the number given as a parameter into a 2 digit string.
Definition: DateTime.h:122
DateTime::getDateStr
String getDateStr() const
Returns the current day in a string format.
Definition: DateTime.cpp:39
DateTime::HTML_startDate
friend String HTML_startDate(const DateTime &dateTime)
Associated function for returing the start day of the device.
DateTime::startTime
String startTime
start time of the system
Definition: DateTime.h:168
DateTime::DateTime
DateTime()
Constructor of the class.
Definition: DateTime.cpp:10
DateTime::htmlData
std::map< int, String(*)(const DateTime &dateTime)> htmlData
A map of different values (keys) and their associated functions which returns the appropriate values.
Definition: DateTime.h:215
DateTime::HTML_startTime
friend String HTML_startTime(const DateTime &dateTime)
Associated function for returing the start time of the device.
DateTime::rtc
DS3231 rtc
real-time module
Definition: DateTime.h:166
DateTime::startDate
String startDate
start day of the system
Definition: DateTime.h:167
DateTime::getTimeStr
String getTimeStr() const
Returns the current time in a string format.
Definition: DateTime.cpp:32