DST added

This commit is contained in:
Martin Brodbeck 2023-01-03 17:03:51 +01:00
parent 2bc80a960a
commit b8d6b4112a
2 changed files with 32 additions and 3 deletions

View file

@ -76,7 +76,12 @@ int main() {
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;
size_t count{0};
auto currentTime = time_us_64();

View file

@ -8,9 +8,32 @@ using std::istringstream;
using std::string;
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) {
istringstream stream(csv);
string line;
string line{""};
std::vector<WasteDate> dates;
// Get rid of the first line (header)
@ -21,7 +44,7 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
size_t pos = 0;
string token;
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);
if (token.length() > 0) {
@ -74,6 +97,7 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
line.erase(0, pos + delimiter.length());
++tokenPos;
}
// std::cout << "Size left: " << line.size() << " - " << line << std::endl;
}
return dates;