From eac460f03094a357c679c5dede7295aa8b2e1fb1 Mon Sep 17 00:00:00 2001 From: FintasticMan Date: Fri, 6 Oct 2023 19:54:20 +0200 Subject: [PATCH] weather: Fix GetCurrent* functions returning future events (#1879) --- src/components/ble/weather/WeatherService.cpp | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/components/ble/weather/WeatherService.cpp b/src/components/ble/weather/WeatherService.cpp index 513bb2a16b..b9a6af556c 100644 --- a/src/components/ble/weather/WeatherService.cpp +++ b/src/components/ble/weather/WeatherService.cpp @@ -404,7 +404,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentClouds() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Clouds && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::Clouds && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } } @@ -415,7 +416,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentObscuration() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Obscuration && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::Obscuration && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } } @@ -426,7 +428,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentPrecipitation() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Precipitation && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::Precipitation && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } } @@ -437,7 +440,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentWind() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Wind && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::Wind && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } } @@ -448,7 +452,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentTemperature() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Temperature && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::Temperature && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } } @@ -459,7 +464,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentHumidity() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Humidity && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::Humidity && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } } @@ -470,7 +476,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentPressure() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Pressure && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::Pressure && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } } @@ -481,7 +488,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentLocation() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::Location && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::Location && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } } @@ -492,7 +500,8 @@ namespace Pinetime { std::unique_ptr& WeatherService::GetCurrentQuality() { uint64_t currentTimestamp = GetCurrentUnixTimestamp(); for (auto&& header : this->timeline) { - if (header->eventType == WeatherData::eventtype::AirQuality && IsEventStillValid(header, currentTimestamp)) { + if (header->eventType == WeatherData::eventtype::AirQuality && currentTimestamp >= header->timestamp && + IsEventStillValid(header, currentTimestamp)) { return reinterpret_cast&>(header); } }