Fix sunrise/sunset times by adding timezone offsets when using OWM

This commit is contained in:
Samer Albahra
2015-09-23 22:53:45 -05:00
parent c8dab8e58c
commit cc94e4b26c

View File

@@ -229,8 +229,6 @@ function getOWMWeatherData( location, callback ) {
try { try {
data = JSON.parse( data ); data = JSON.parse( data );
var sunrise = new Date( data.sys.sunrise * 1000 ),
sunset = new Date( data.sys.sunset * 1000 );
timezoner.getTimeZone( timezoner.getTimeZone(
location[ 0 ], location[ 0 ],
@@ -239,10 +237,19 @@ function getOWMWeatherData( location, callback ) {
if ( err ) { if ( err ) {
callback( false ); callback( false );
} else { } else {
var timezone = ( timezone.rawOffset + timezone.dstOffset ) / 60,
tzOffset = getTimezone( timezone, "minutes" ),
// Calculate sunrise and sunset since Weather Underground does not provide it
sunData = SunCalc.getTimes( new Date(), location[ 0 ], location[ 1 ] );
sunData.sunrise.setUTCMinutes( sunData.sunrise.getUTCMinutes() + tzOffset );
sunData.sunset.setUTCMinutes( sunData.sunset.getUTCMinutes() + tzOffset );
var weather = { var weather = {
timezone: ( timezone.rawOffset + timezone.dstOffset ) / 60, timezone: timezone,
sunrise: ( sunrise.getHours() * 60 + sunrise.getMinutes() ), sunrise: ( sunData.sunrise.getUTCHours() * 60 + sunData.sunrise.getUTCMinutes() ),
sunset: ( sunset.getHours() * 60 + sunset.getMinutes() ), sunset: ( sunData.sunset.getUTCHours() * 60 + sunData.sunset.getUTCMinutes() ),
temp: parseInt( data.main.temp ), temp: parseInt( data.main.temp ),
humidity: parseInt( data.main.humidity ), humidity: parseInt( data.main.humidity ),
wind: parseInt( data.wind.speed ) wind: parseInt( data.wind.speed )