Generate date using the local observation time instead of server
This commit is contained in:
@@ -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 ) {
|
||||
|
||||
Reference in New Issue
Block a user