-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDateTime.class.cpp
52 lines (39 loc) · 923 Bytes
/
DateTime.class.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "DateTime.class.hpp"
DateTime::DateTime(void) {
}
DateTime::DateTime(const DateTime& copy) {
*this = copy;
}
DateTime::~DateTime(void) {
return;
}
DateTime& DateTime::operator=(const DateTime&) {
return *this;
}
void DateTime::update(void) {
this->_date = this->_getCurrentDate();
this->_time = this->_getCurrentTime();
}
const std::string DateTime::_getCurrentDate(void) {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d", &tstruct);
return std::string(buf);
}
const std::string DateTime::_getCurrentTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%X", &tstruct);
return std::string(buf);
}
/* Getters */
std::string DateTime::getDate(void) const {
return this->_date;
}
std::string DateTime::getTime(void) const {
return this->_time;
}