This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateModule.cpp
58 lines (51 loc) · 1.97 KB
/
DateModule.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
53
54
55
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* DateModule.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: omiroshn <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/14 15:10:35 by omiroshn #+# #+# */
/* Updated: 2018/04/14 15:10:35 by omiroshn ### ########.fr */
/* */
/* ************************************************************************** */
#include "DateModule.hpp"
DateModule::DateModule() {
this->update();
}
DateModule::DateModule(const DateModule &cpy) {
*this = cpy;
}
DateModule& DateModule::operator=(const DateModule &cpy) {
this->date = cpy.getData("data");
this->ttime = cpy.getData("time");
return (*this);
}
DateModule::~DateModule() { }
void DateModule::update() {
std::stringstream ss;
time_t t = time(0);
struct tm *now = localtime(&t);
ss << "Date: " << std::to_string(now->tm_mday) << "/"
<< std::to_string(now->tm_mon + 1) << "/"
<< std::to_string(now->tm_year + 1900);
this->date = ss.str();
ss.str(std::string());
ss << "Time: " << std::to_string(now->tm_hour) + ":";
if (now->tm_min <= 9)
ss << "0" << std::to_string(now->tm_min) + ":";
else
ss << std::to_string(now->tm_min) + ":";
if (now->tm_sec <= 9)
ss << "0" << std::to_string(now->tm_sec);
else
ss << std::to_string(now->tm_sec);
this->ttime = ss.str();
}
std::string DateModule::getData(const std::string &type) const {
if (type == "data")
return this->date;
else if (type == "time")
return this->ttime;
return ("No data to show. :(");
}