blob: 209ed2e6a228a7e5f586c2b4d9373ec3ddae35b8 (
plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/**
* FIXME:
*
*
*/
#include "calendar.h"
/**
* @brief constructor
* @param static names Static array of calendar names.
*
* Insert the names into the dynamic array.
*/
calendar_t::calendar_t(const char *const *const static_names, const size_t names_count, const unsigned icon_id) //:
//country
//icon_id
//names
{
names.resize(names_count);
// The first element of the static array is the country name.
country = static_names[0];
for (size_t i = 0; i < names_count - 1; ++i) {
names[i] = static_names[i + 1];
}
this->icon_id = icon_id;
}
/**
* @brief destructor
*
*/
calendar_t::~calendar_t(void)
{
names.clear();
}
/**
* @brief get_name
* @param day_in_year
*
*/
const string &calendar_t::get_name(const unsigned day_in_year) const
{
return names[day_in_year];
}
/**
* @brief get the day in the year.
* @return index
* @param month
* @param day
*
*/
unsigned calendar_t::get_day_in_year(const unsigned month, const unsigned day) const
{
// NOTE: it's too late for me to come with some clever
// alg. for this... :)
unsigned index = day + 29 * (month - 1) - 1;
if (month == 1) {
return index;
}
// January
index += 2;
// Jan & Feb end.
if (month == 2 || month == 3) {
return index;
}
index += 2;
if (month == 4) {
return index;
}
index += 1;
if (month == 5) {
return index;
}
index += 2;
if (month == 6) {
return index;
}
index += 1;
if (month == 7) {
return index;
}
index += 2;
if (month == 8) {
return index;
}
index += 2;
if (month == 9) {
return index;
}
index += 1;
if (month == 10) {
return index;
}
index += 2;
if (month == 11) {
return index;
}
index += 1;
return index;
}
/**
* @brief get the name
* @param day Day in month
* @param month Month in year
*
*/
const string &calendar_t::get_name(const unsigned day, const unsigned month) const
{
const unsigned day_in_year = get_day_in_year(day, month);
return get_name(day_in_year);
}
/**
* @brief get name count
* @return name_count
*
*/
unsigned calendar_t::get_name_count(void) const
{
return names.size();
}
|