Generate date using the local observation time instead of server

This commit is contained in:
Samer Albahra
2015-07-03 10:29:05 -05:00
parent 859bce73dd
commit c096106738

View File

@@ -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 ) {