diff --git a/routes/weather.js b/routes/weather.js index c32d0ea..33a9ac1 100644 --- a/routes/weather.js +++ b/routes/weather.js @@ -68,7 +68,9 @@ function getWeatherUndergroundData( location, weatherUndergroundKey, callback ) var data = JSON.parse( data ); // Calculate sunrise and sunset since Weather Underground does not provide it - var sunData = SunCalc.getTimes( new Date(), data.current_observation.observation_location.latitude, data.current_observation.observation_location.longitude ), + var sunData = SunCalc.getTimes( new Date( data.current_observation.local_epoch * 1000 ), + data.current_observation.observation_location.latitude, + data.current_observation.observation_location.longitude ), weather = { icon: data.current_observation.icon, timezone: data.current_observation.local_tz_offset, @@ -84,6 +86,10 @@ function getWeatherUndergroundData( location, weatherUndergroundKey, callback ) elevation: data.current_observation.observation_location.elevation }; + if ( weather.sunrise > weather.sunset ) { + weather.sunset += 1440; + } + callback( weather ); } catch ( err ) {