Add timezone offset to Date object so overflow is handled
This commit is contained in:
@@ -72,12 +72,16 @@ function getWeatherUndergroundData( location, weatherUndergroundKey, callback )
|
|||||||
// Calculate sunrise and sunset since Weather Underground does not provide it
|
// Calculate sunrise and sunset since Weather Underground does not provide it
|
||||||
sunData = SunCalc.getTimes( data.current_observation.local_epoch * 1000,
|
sunData = SunCalc.getTimes( data.current_observation.local_epoch * 1000,
|
||||||
data.current_observation.observation_location.latitude,
|
data.current_observation.observation_location.latitude,
|
||||||
data.current_observation.observation_location.longitude ),
|
data.current_observation.observation_location.longitude );
|
||||||
weather = {
|
|
||||||
|
sunData.sunrise.setUTCMinutes( sunData.sunrise.getUTCMinutes() + tzOffset );
|
||||||
|
sunData.sunset.setUTCMinutes( sunData.sunset.getUTCMinutes() + tzOffset );
|
||||||
|
|
||||||
|
var weather = {
|
||||||
icon: data.current_observation.icon,
|
icon: data.current_observation.icon,
|
||||||
timezone: data.current_observation.local_tz_offset,
|
timezone: data.current_observation.local_tz_offset,
|
||||||
sunrise: ( sunData.sunrise.getUTCHours() * 60 + sunData.sunrise.getUTCMinutes() ) + tzOffset,
|
sunrise: ( sunData.sunrise.getUTCHours() * 60 + sunData.sunrise.getUTCMinutes() ),
|
||||||
sunset: ( sunData.sunset.getUTCHours() * 60 + sunData.sunset.getUTCMinutes() ) + tzOffset,
|
sunset: ( sunData.sunset.getUTCHours() * 60 + sunData.sunset.getUTCMinutes() ),
|
||||||
maxTemp: parseInt( data.history.dailysummary[0].maxtempi ),
|
maxTemp: parseInt( data.history.dailysummary[0].maxtempi ),
|
||||||
minTemp: parseInt( data.history.dailysummary[0].mintempi ),
|
minTemp: parseInt( data.history.dailysummary[0].mintempi ),
|
||||||
temp: parseInt( data.current_observation.temp_f ),
|
temp: parseInt( data.current_observation.temp_f ),
|
||||||
@@ -88,10 +92,6 @@ function getWeatherUndergroundData( location, weatherUndergroundKey, callback )
|
|||||||
elevation: parseInt( data.current_observation.observation_location.elevation )
|
elevation: parseInt( data.current_observation.observation_location.elevation )
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( weather.sunrise > weather.sunset ) {
|
|
||||||
weather.sunset += 1440;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback( weather );
|
callback( weather );
|
||||||
|
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user