-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhour_field.cpp
More file actions
37 lines (33 loc) · 929 Bytes
/
hour_field.cpp
File metadata and controls
37 lines (33 loc) · 929 Bytes
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
#include <algorithm>
#include "hour_field.h"
namespace geheb {
hour_field::hour_field() {
_allowBackwardRange = true;
}
date_time hour_field::increment(const std::string &value, const date_time &time) const {
date_time nextTime(time);
nextTime -= minutes(nextTime.minute()); // reset minutes to 0
if (value == "*") {
nextTime += hours(1);
return nextTime;
}
size_t pos = 0;
auto list = create_list(value);
for (size_t i = 0; i < list.size() - 1; i++) {
int currentVal = list[i];
int nextVal = list[i + 1];
if (time.hour() >= currentVal && time.hour() < nextVal) {
pos = i + 1;
break;
}
}
nextTime -= hours(nextTime.hour()); // reset hour to 0
if (time.hour() >= list[pos]) {
nextTime += days(1);
}
else {
nextTime += hours(list[pos]);
}
return nextTime;
}
} // namespace geheb