Repository navigation
Expand file tree
/
Copy pathbookmark_types.cpp
More file actions
102 lines (85 loc) · 1.95 KB
/
Copy pathbookmark_types.cpp
File metadata and controls
102 lines (85 loc) · 1.95 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "stdafx.h"
#include <map>
#include <sstream>
#include "bookmark_persistence.h"
#include "utils.h"
#include "bookmark_types.h"
int get_wday_index(std::string name)
{
std::map<std::string, int> wdays
{
{ "Mon", 0 },
{ "Tue", 1 },
{ "Wed", 2 },
{ "Thu", 3 },
{ "Fri", 4 },
{ "Sat", 5 },
{ "Sun", 6 },
};
const auto iter = wdays.find(name);
if (iter != wdays.cend())
return iter->second;
return 1/*SIZE_MAX*/;
}
int get_month_index(std::string name)
{
std::map<std::string, int> months
{
{ "Jan", 0 },
{ "Feb", 1 },
{ "Mar", 2 },
{ "Apr", 3 },
{ "May", 4 },
{ "Jun", 5 },
{ "Jul", 6 },
{ "Aug", 7 },
{ "Sep", 8 },
{ "Oct", 9 },
{ "Nov", 10 },
{ "Dec", 11 }
};
const auto iter = months.find(name);
if (iter != months.cend())
return iter->second;
return 1/*SIZE_MAX*/;
}
inline void unix_str_date_to_time(pfc::string8 unix_date, time_t& out_rawtime, tm& out_tm) {
int Year, Day, Hour, Minute, Second;
std::string StrAmPm;
std::string StrWeekDay;
std::string StrMonth;
char ThrowAway;
std::stringstream Stream(unix_date.c_str());
Stream >> StrWeekDay >> StrMonth >> Day;
Stream >> Hour >> ThrowAway >> Minute >> ThrowAway >> Second;
Stream >> Year;
out_tm.tm_year = Year - 1900;
out_tm.tm_mon = get_month_index(StrMonth);
out_tm.tm_mday = Day;
out_tm.tm_wday = get_wday_index(StrWeekDay);
out_tm.tm_hour = Hour;
out_tm.tm_min = Minute;
out_tm.tm_sec = Second;
out_tm.tm_isdst = -1;
out_rawtime = mktime(&out_tm);
}
void bookmark_t::set_name(pfc::string8 p_name) {
name = p_name;
}
void bookmark_t::set_desc(pfc::string8 p_desc) {
desc = p_desc;
}
void bookmark_t::set_comment(pfc::string8 p_comment) {
comment = p_comment;
}
void bookmark_t::assign_desc(pfc::string8 p_desc) {
name = "";
desc = p_desc;
}
void bookmark_t::set_fdn(pfc::string8 p_fdn) {
fdn = p_fdn;
}
void bookmark_t::set_current_date() {
currentUnixDate(date);
currentFmtDate(runtime_date, cfg_date_format.get());
}