DST added
This commit is contained in:
parent
2bc80a960a
commit
b8d6b4112a
2 changed files with 32 additions and 3 deletions
|
@ -76,7 +76,12 @@ int main() {
|
||||||
return date.date == tomorrowYMD;
|
return date.date == tomorrowYMD;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (it != dates.end() && dt.hour >= 18) {
|
int8_t hour = dt.hour + 1; // MEZ
|
||||||
|
if (isDST(dt.day, dt.month, dt.dotw))
|
||||||
|
++hour; // MESZ
|
||||||
|
|
||||||
|
// If there was a waste bin pickup found AND we are in the evening (>= 18:00) …
|
||||||
|
if (it != dates.end() && hour >= 14) {
|
||||||
auto wasteDate = *it;
|
auto wasteDate = *it;
|
||||||
size_t count{0};
|
size_t count{0};
|
||||||
auto currentTime = time_us_64();
|
auto currentTime = time_us_64();
|
||||||
|
|
|
@ -8,9 +8,32 @@ using std::istringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
bool isDST(int8_t day, int8_t month, int8_t dow) {
|
||||||
|
// January, february, november and december are out.
|
||||||
|
if (month < 3 || month > 10) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// April to September are in
|
||||||
|
if (month > 3 && month < 10) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int previousSunday = day - dow;
|
||||||
|
|
||||||
|
// In march, we are DST if our previous sunday was on or after the 25th.
|
||||||
|
if (month == 3) {
|
||||||
|
return previousSunday >= 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In October we must be before the last sunday to be DST.
|
||||||
|
// That means the previous sunday must be before the 25st.
|
||||||
|
return previousSunday < 25;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<WasteDate> parseCsv(const std::string &csv) {
|
std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||||
istringstream stream(csv);
|
istringstream stream(csv);
|
||||||
string line;
|
string line{""};
|
||||||
std::vector<WasteDate> dates;
|
std::vector<WasteDate> dates;
|
||||||
|
|
||||||
// Get rid of the first line (header)
|
// Get rid of the first line (header)
|
||||||
|
@ -21,7 +44,7 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
string token;
|
string token;
|
||||||
uint tokenPos = 0;
|
uint tokenPos = 0;
|
||||||
while ((pos = line.find(delimiter)) != std::string::npos) {
|
while ((pos = line.find_first_of(delimiter)) != std::string::npos) {
|
||||||
token = line.substr(0, pos);
|
token = line.substr(0, pos);
|
||||||
|
|
||||||
if (token.length() > 0) {
|
if (token.length() > 0) {
|
||||||
|
@ -74,6 +97,7 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||||
line.erase(0, pos + delimiter.length());
|
line.erase(0, pos + delimiter.length());
|
||||||
++tokenPos;
|
++tokenPos;
|
||||||
}
|
}
|
||||||
|
// std::cout << "Size left: " << line.size() << " - " << line << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dates;
|
return dates;
|
||||||
|
|
Loading…
Reference in a new issue