From 601f6130d77b377b6908d621556318b7c9651270 Mon Sep 17 00:00:00 2001 From: Matthew Oslan Date: Mon, 9 Mar 2020 16:56:13 -0400 Subject: [PATCH] Fix daylight saving time bug --- routes/weatherProviders/DarkSky.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/routes/weatherProviders/DarkSky.ts b/routes/weatherProviders/DarkSky.ts index f8133b7..100fcd4 100644 --- a/routes/weatherProviders/DarkSky.ts +++ b/routes/weatherProviders/DarkSky.ts @@ -41,7 +41,8 @@ export default class DarkSkyWeatherProvider extends WeatherProvider { ]; // Fail if not enough data is available. - if ( samples.length !== 24 ) { + // There will only be 23 samples on the day that daylight saving time begins. + if ( samples.length !== 24 && samples.length !== 23 ) { throw new CodedError( ErrorCode.InsufficientWeatherData ); } @@ -61,8 +62,8 @@ export default class DarkSkyWeatherProvider extends WeatherProvider { return { weatherProvider: "DarkSky", - temp: totals.temp / 24, - humidity: totals.humidity / 24 * 100, + temp: totals.temp / samples.length, + humidity: totals.humidity / samples.length * 100, precip: totals.precip, raining: samples[ samples.length - 1 ].precipIntensity > 0 };