diff options
author | kieranc <kieranc@gmail.com> | 2022-11-25 18:45:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-25 18:45:33 +0100 |
commit | f1d2a8ee50fe298357c5b2aebd5196d6f84805c7 (patch) | |
tree | 1117f14b09b9b17c76aea74562407c42008283e1 | |
parent | 7376c02bbfa53b41fab1c49562917d678c24848f (diff) |
WeatherService daily min/max temperature fixes (#1455)
* Min/Max function fixes
* Faster way to calculate day start
-rw-r--r-- | src/components/ble/weather/WeatherService.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/components/ble/weather/WeatherService.cpp b/src/components/ble/weather/WeatherService.cpp index 23f53b74..950b6dfd 100644 --- a/src/components/ble/weather/WeatherService.cpp +++ b/src/components/ble/weather/WeatherService.cpp @@ -552,11 +552,12 @@ namespace Pinetime { int16_t WeatherService::GetTodayMinTemp() const { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); - uint64_t currentDayEnd = currentTimestamp - ((24 - dateTimeController.Hours()) * 60 * 60) - - ((60 - dateTimeController.Minutes()) * 60) - (60 - dateTimeController.Seconds()); + uint64_t currentDayEnd = currentTimestamp + ((24 - dateTimeController.Hours()) * 60 * 60) + + ((60 - dateTimeController.Minutes()) * 60) + (60 - dateTimeController.Seconds()); + uint64_t currentDayStart = currentDayEnd - 86400; int16_t result = -32768; for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Temperature && IsEventStillValid(header, currentTimestamp) && + if (header->eventType == WeatherData::eventtype::Temperature && header->timestamp >= currentDayStart && header->timestamp < currentDayEnd && reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature != -32768) { int16_t temperature = reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature; @@ -575,11 +576,12 @@ namespace Pinetime { int16_t WeatherService::GetTodayMaxTemp() const { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); - uint64_t currentDayEnd = currentTimestamp - ((24 - dateTimeController.Hours()) * 60 * 60) - - ((60 - dateTimeController.Minutes()) * 60) - (60 - dateTimeController.Seconds()); + uint64_t currentDayEnd = currentTimestamp + ((24 - dateTimeController.Hours()) * 60 * 60) + + ((60 - dateTimeController.Minutes()) * 60) + (60 - dateTimeController.Seconds()); + uint64_t currentDayStart = currentDayEnd - 86400; int16_t result = -32768; for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Temperature && IsEventStillValid(header, currentTimestamp) && + if (header->eventType == WeatherData::eventtype::Temperature && header->timestamp >= currentDayStart && header->timestamp < currentDayEnd && reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature != -32768) { int16_t temperature = reinterpret_cast<const std::unique_ptr<WeatherData::Temperature>&>(header)->temperature; |