HomeWaterLeaksDetection
DateTime.cpp
Go to the documentation of this file.
1 #include "DateTime.h"
2 
4 
5 #ifdef WEB_SERVER
6  String HTML_startDate(const DateTime& dateTime);
7  String HTML_startTime(const DateTime& dateTime);
8 #endif
9 
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 }
25 
27  if (instance == NULL)
28  instance = new DateTime;
29  return instance;
30 }
31 
32 String DateTime::getTimeStr() const {
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 }
38 
39 String DateTime::getDateStr() const {
40  RTCDateTime dateTime = rtc.getDateTime();
41  String date = String(dateTime.day) + "." +
42  String(dateTime.month) + "." +
43  String(dateTime.year);
44  return date;
45 }
46 
47 String DateTime::getDateTimeStr() const {
48  return getDateStr() + " | " + getTimeStr();
49 }
50 
51 RTCDateTime DateTime::getDateTime() const {
52  return rtc.getDateTime();
53 }
54 
55 #ifdef WEB_SERVER
56  const String DateTime::getHTMLData(const int id) const {
57  auto fce = htmlData.find(id);
58  if (fce == htmlData.end())
60  return fce->second(*this);
61  }
62 
63  String HTML_startDate(const DateTime& dateTime) {
64  return dateTime.startDate;
65  }
66 
67  String HTML_startTime(const DateTime& dateTime) {
68  return dateTime.startTime;
69  }
70 #endif
DateTime::instance
static DateTime * instance
the instance of the class (Singleton)
Definition: DateTime.h:165
DateTime.h
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::getHTMLData
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 appropri...
DateTime::HTML_startDate
friend String HTML_startDate(const DateTime &dateTime)
Associated function for returing the start day of the device.
DateTime::getInstance
static DateTime * getInstance()
Returns the instance of the class.
Definition: DateTime.cpp:26
HTMLDataSource::UNDEFINED_DATA
static const String UNDEFINED_DATA
string "UNDEFINED"
Definition: HTMLDataSource.h:17
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::getDateTimeStr
String getDateTimeStr() const
Returns the current datatime in a string format.
Definition: DateTime.cpp:47
DateTime::startDate
String startDate
start day of the system
Definition: DateTime.h:167
DateTime
Definition: DateTime.h:162
DateTime::getDateTime
RTCDateTime getDateTime() const
Returns the current datatime.
Definition: DateTime.cpp:51
DateTime::getTimeStr
String getTimeStr() const
Returns the current time in a string format.
Definition: DateTime.cpp:32