-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateTimeModule.cpp
73 lines (57 loc) · 2.07 KB
/
DateTimeModule.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* DateTimeModule.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kdenisov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/03 16:04:15 by kdenisov #+# #+# */
/* Updated: 2019/11/14 11:12:25 by kdenisov ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <string>
#include <sys/sysctl.h>
#include "includes/DateTimeModule.hpp"
DateTimeModule::DateTimeModule() {
}
DateTimeModule::DateTimeModule(int pos, int gpos) : _pos(pos), _gpos(gpos) {
this->_module = "DATE/TIME";
refresh();
}
DateTimeModule::~DateTimeModule() {
}
DateTimeModule::DateTimeModule(DateTimeModule const & src) {
*this = src;
}
DateTimeModule & DateTimeModule::operator=(DateTimeModule const & rfs) {
this->_module = rfs._module;
this->_date = rfs._date;
this->_pos = rfs._pos;
this->_gpos = rfs._gpos;
return (*this);
}
void DateTimeModule::render(IMonitorDisplay *d) {
d->render(this);
}
void DateTimeModule::refresh() {
char buf[29];
std::time_t time = std::time(nullptr);
std::strftime(buf, sizeof(buf), "%a %b %e %T %Z %Y", std::localtime(&time));
this->_date = buf;
}
std::string DateTimeModule::getName() const {
return (this->_module);
}
int DateTimeModule::getPos() const {
return (this->_pos);
}
int DateTimeModule::getGPos() const {
return (this->_gpos);
}
std::string DateTimeModule::getDate() const {
return (this->_date);
}
int DateTimeModule::getSize(std::string const name) const {
return (name.length());
}