From 1a1a744dd7191741768878fb9ee1f38897555b7e Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Fri, 3 Jul 2015 13:22:45 -0500 Subject: [PATCH] Add timezone offset to Date object so overflow is handled --- routes/weather.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index 507b1a9..5c2f4ec 100644 --- a/routes/weather.js +++ b/routes/weather.js @@ -72,12 +72,16 @@ function getWeatherUndergroundData( location, weatherUndergroundKey, callback ) // Calculate sunrise and sunset since Weather Underground does not provide it sunData = SunCalc.getTimes( data.current_observation.local_epoch * 1000, data.current_observation.observation_location.latitude, - data.current_observation.observation_location.longitude ), - weather = { + data.current_observation.observation_location.longitude ); + + sunData.sunrise.setUTCMinutes( sunData.sunrise.getUTCMinutes() + tzOffset ); + sunData.sunset.setUTCMinutes( sunData.sunset.getUTCMinutes() + tzOffset ); + + var weather = { icon: data.current_observation.icon, timezone: data.current_observation.local_tz_offset, - sunrise: ( sunData.sunrise.getUTCHours() * 60 + sunData.sunrise.getUTCMinutes() ) + tzOffset, - sunset: ( sunData.sunset.getUTCHours() * 60 + sunData.sunset.getUTCMinutes() ) + tzOffset, + sunrise: ( sunData.sunrise.getUTCHours() * 60 + sunData.sunrise.getUTCMinutes() ), + sunset: ( sunData.sunset.getUTCHours() * 60 + sunData.sunset.getUTCMinutes() ), maxTemp: parseInt( data.history.dailysummary[0].maxtempi ), minTemp: parseInt( data.history.dailysummary[0].mintempi ), temp: parseInt( data.current_observation.temp_f ), @@ -88,10 +92,6 @@ function getWeatherUndergroundData( location, weatherUndergroundKey, callback ) elevation: parseInt( data.current_observation.observation_location.elevation ) }; - if ( weather.sunrise > weather.sunset ) { - weather.sunset += 1440; - } - callback( weather ); } catch ( err ) {