-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_vars.h
51 lines (43 loc) · 1.42 KB
/
system_vars.h
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
using namespace std;
using namespace chrono;
namespace cli::system_vars {
/**
* returns the formatted date by given params
*
* @param param the parameters to format
* @return formatted date
*/
string base_command_show_date(const string ¶m) {
auto now = system_clock::now();
time_t time = system_clock::to_time_t(now);
struct tm t_struct;
localtime_s(&t_struct, &time);
char time_format[50];
char time_buffer[100];
if (param == "s" || param.empty()) strcpy_s(time_format, sizeof(time_format), "%F");
else if (param == "m") strcpy_s(time_format, sizeof(time_format), "%a - %F");
else if (param == "l") strcpy_s(time_format, sizeof(time_format), "%a - %b %d, %Y");
else if (param == "f") strcpy_s(time_format, sizeof(time_format), "%A - %d of %B, %Y");
else return "";
strftime(time_buffer, sizeof(time_buffer), time_format, &t_struct);
return time_buffer;
}
/**
* returns the formatted time by given params
*
* @param param the parameters to format
* @return formatted time
*/
string base_command_show_time(const string ¶m) {
auto now = system_clock::now();
time_t time = system_clock::to_time_t(now);
struct tm t_struct;
localtime_s(&t_struct, &time);
if (param == "s" || param.empty()) {
char time_buffer[50];
strftime(time_buffer, sizeof(time_buffer), "%X", &t_struct);
return time_buffer;
} else if (param == "l") return "echo";
else return "";
}
}