forked from Paremo/foo_bbookmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookmark_types.cpp
More file actions
77 lines (64 loc) · 1.47 KB
/
bookmark_types.cpp
File metadata and controls
77 lines (64 loc) · 1.47 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
#include "stdafx.h"
#include <map>
#include <sstream>
#include "bookmark_persistence.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);
}