@ -284,8 +284,12 @@ const WeatherMenuButton = new Lang.Class({
this . _settings = Convenience . getSettings ( WEATHER _SETTINGS _SCHEMA ) ;
this . _settingsC = this . _settings . connect ( "changed" , function ( ) {
that . rebuildFutureWeatherUi ( ) ;
that . refreshWeatherCurrent ( false ) ;
that . refreshWeatherForecast ( false ) ;
if ( that . locationChanged ( ) ) {
that . currentWeatherCache = 'undefined' ;
that . forecastWeatherCache = 'undefined' ;
}
that . parseWeatherCurrent ( ) ;
that . parseWeatherForecast ( ) ;
} ) ;
} ,
@ -298,11 +302,23 @@ const WeatherMenuButton = new Lang.Class({
schema : schemaInterface
} ) ;
this . _settingsInterfaceC = this . _settingsInterface . connect ( "changed" , function ( ) {
that . refreshWeatherCurrent ( false ) ;
that . refreshWeatherForecast ( false ) ;
if ( that . locationChanged ( ) ) {
that . currentWeatherCache = 'undefined' ;
that . forecastWeatherCache = 'undefined' ;
}
that . parseWeatherCurrent ( ) ;
that . parseWeatherForecast ( ) ;
} ) ;
} ,
locationChanged : function ( ) {
let location = this . extractCity ( this . _city ) ;
if ( this . oldLocation != location ) {
return true ;
}
return false ;
} ,
get _clockFormat ( ) {
if ( ! this . _settingsInterface )
this . loadConfigInterface ( ) ;
@ -1088,253 +1104,268 @@ weather-storm.png = weather-storm-symbolic.svg
return 0 ;
} ,
refresh WeatherCurrent: function ( recurse ) {
if ( ! this . extractId ( this . _city ) ) {
this . updateCities ( ) ;
return 0 ;
parse WeatherCurrent: function ( ) {
if ( this . currentWeatherCache == 'undefined' ) {
this . refreshWeatherCurrent ( ) ;
return ;
}
let params = {
q : this . extractCity ( this . _city ) ,
units : 'metric'
} ;
if ( this . _appid )
params [ 'APPID' ] = this . _appid ;
this . load _json _async ( WEATHER _URL _CURRENT , params , function ( json ) {
if ( ! json )
return 0 ;
if ( this . _old _position _in _panel != this . _position _in _panel ) {
switch ( this . _old _position _in _panel ) {
case WeatherPosition . LEFT :
Main . panel . _leftBox . remove _actor ( this . actor ) ;
break ;
case WeatherPosition . CENTER :
Main . panel . _centerBox . remove _actor ( this . actor ) ;
break ;
case WeatherPosition . RIGHT :
Main . panel . _rightBox . remove _actor ( this . actor ) ;
break ;
}
if ( Number ( json . cod ) != 200 )
return 0 ;
let children = null ;
switch ( this . _position _in _panel ) {
case WeatherPosition . LEFT :
children = Main . panel . _leftBox . get _children ( ) ;
Main . panel . _leftBox . insert _child _at _index ( this . actor , children . length ) ;
break ;
case WeatherPosition . CENTER :
children = Main . panel . _centerBox . get _children ( ) ;
Main . panel . _centerBox . insert _child _at _index ( this . actor , children . length ) ;
break ;
case WeatherPosition . RIGHT :
children = Main . panel . _rightBox . get _children ( ) ;
Main . panel . _rightBox . insert _child _at _index ( this . actor , 0 ) ;
break ;
}
this . _old _position _in _panel = this . _position _in _panel ;
}
this . rebuildSelectCityItem ( ) ;
let json = this . currentWeatherCache ;
// Refresh current weather
let location = this . extractLocation ( this . _city ) ;
let comment = json . weather [ 0 ] . description ;
if ( this . _translate _condition )
comment = this . get _weather _condition ( json . weather [ 0 ] . id ) ;
if ( this . _old _position _in _panel != this . _position _in _panel ) {
switch ( this . _old _position _in _panel ) {
case WeatherPosition . LEFT :
Main . panel . _leftBox . remove _actor ( this . actor ) ;
break ;
case WeatherPosition . CENTER :
Main . panel . _centerBox . remove _actor ( this . actor ) ;
break ;
case WeatherPosition . RIGHT :
Main . panel . _rightBox . remove _actor ( this . actor ) ;
break ;
}
let children = null ;
switch ( this . _position _in _panel ) {
case WeatherPosition . LEFT :
children = Main . panel . _leftBox . get _children ( ) ;
Main . panel . _leftBox . insert _child _at _index ( this . actor , children . length ) ;
break ;
case WeatherPosition . CENTER :
children = Main . panel . _centerBox . get _children ( ) ;
Main . panel . _centerBox . insert _child _at _index ( this . actor , children . length ) ;
break ;
case WeatherPosition . RIGHT :
children = Main . panel . _rightBox . get _children ( ) ;
Main . panel . _rightBox . insert _child _at _index ( this . actor , 0 ) ;
break ;
}
this . _old _position _in _panel = this . _position _in _panel ;
}
let temperature = json . main . temp ;
let cloudiness = json . clouds . all ;
let humidity = json . main . humidity + ' %' ;
let pressure = json . main . pressure ;
let pressure _unit = 'hPa' ;
let location = this . extractLocation ( this . _city ) ;
let wind _direction = this . get _wind _direction ( json . wind . deg ) ;
let wind = json . wind . speed ;
let wind _unit = 'm/s' ;
let iconname = this . get _weather _icon _safely ( json . weather [ 0 ] . id ) ;
// Refresh current weather
let comment = json . weather [ 0 ] . description ;
if ( this . _translate _condition )
comment = this . get _weather _condition ( json . weather [ 0 ] . id ) ;
let sunrise = json . sys . sunrise ;
let sunset = json . sys . sunset ;
let temperature = json . main . temp ;
let cloudiness = json . clouds . all ;
let humidity = json . main . humidity + ' %' ;
let pressure = json . main . pressure ;
let pressure _unit = 'hPa' ;
if ( typeof this . lastBuildId == 'undefined' )
this . lastBuildId = 0 ;
let wind _direction = this . get _wind _direction ( json . wind . deg ) ;
let wind = json . wind . speed ;
let wind _unit = 'm/s' ;
let iconname = this . get _weather _icon _safely ( json . weather [ 0 ] . id ) ;
if ( typeof this . lastBuildDate == 'undefined' )
this . lastBuildDate = 0 ;
let sunrise = json . sys . sunrise ;
let sunset = json . sys . sunset ;
if ( this . lastBuildId != json . dt || ! this . lastBuildDate ) {
this . lastBuildId = json . dt ;
this . lastBuildDate = new Date ( this . lastBuildId * 1000 ) ;
}
if ( typeof this . lastBuildId == "undefined" )
this . lastBuildId = 0 ;
switch ( this . _pressure _units ) {
case WeatherPressureUnits . inHg :
pressure = this . toInHg ( pressure ) ;
pressure _unit = "inHg" ;
break ;
if ( typeof this . lastBuildDate == "undefined" )
this . lastBuildDate = 0 ;
case WeatherPressureUnits . hPa :
pressure = Math . round ( pressure * 10 ) / 10 ;
pressure _unit = "hPa" ;
break ;
if ( this . lastBuildId != json . dt || ! this . lastBuildDate ) {
this . lastBuildId = json . dt ;
this . lastBuildDate = new Date ( ) ;
}
let actualDate = new Date ( ) ;
let d = Math . floor ( ( actualDate . getTime ( ) - this . lastBuildDate . getTime ( ) ) / 86400000 ) ;
case WeatherPressureUnits . bar :
pressure = Math . round ( ( pressure / 1000 ) * 10 ) / 10 ;
pressure _unit = "bar" ;
break ;
switch ( this . _pressure _units ) {
case WeatherPressureUnits . inHg :
pressure = this . toInHg ( pressure ) ;
pressure _unit = "inHg" ;
break ;
case WeatherPressureUnits . Pa :
pressure = Math . round ( ( pressure * 100 ) * 10 ) / 10 ;
pressure _unit = "Pa" ;
break ;
case WeatherPressureUnits . h Pa:
pressure = Math . round ( pressure * 10 ) / 10 ;
pressure _unit = "h Pa" ;
break ;
case WeatherPressureUnits . k Pa:
pressure = Math . round ( ( pressure / 10 ) * 10 ) / 10 ;
pressure _unit = "k Pa" ;
break ;
case WeatherPressureUnits . bar :
pressure = Math . round ( ( pressure / 1000 ) * 10 ) / 10 ;
pressure _unit = "bar " ;
break ;
case WeatherPressureUnits . atm :
pressure = Math . round ( ( pressure * 0.000986923267 ) * 10 ) / 10 ;
pressure _unit = "atm " ;
break ;
case WeatherPressureUnits . P a:
pressure = Math . round ( ( pressure * 100 ) * 10 ) / 10 ;
pressure _unit = "P a" ;
break ;
case WeatherPressureUnits . at :
pressure = Math . round ( ( pressure * 0.00101971621298 ) * 10 ) / 10 ;
pressure _unit = "at " ;
break ;
case WeatherPressureUnits . kPa :
pressure = Math . round ( ( pressure / 10 ) * 10 ) / 10 ;
pressure _unit = "kPa " ;
break ;
case WeatherPressureUnits . Torr :
pressure = Math . round ( ( pressure * 0.750061683 ) * 10 ) / 10 ;
pressure _unit = "Torr " ;
break ;
case WeatherPressureUnits . atm :
pressure = Math . round ( ( pressure * 0.000986923267 ) * 10 ) / 10 ;
pressure _unit = "atm" ;
break ;
case WeatherPressureUnits . psi :
pressure = Math . round ( ( pressure * 0.0145037738 ) * 10 ) / 10 ;
pressure _unit = "psi" ;
break ;
}
case WeatherPressureUnits . at :
pressure = Math . round ( ( pressure * 0.00101971621298 ) * 10 ) / 10 ;
pressure _unit = "at" ;
break ;
switch ( this . _units ) {
case WeatherUnits . FAHRENHEIT :
temperature = this . toFahrenheit ( temperature ) ;
break ;
case WeatherPressureUnits . Torr :
pressure = Math . round ( ( pressure * 0.750061683 ) * 10 ) / 10 ;
pressure _unit = "Torr" ;
break ;
case WeatherUnits . CELSIUS :
temperature = Math . round ( temperature * 10 ) / 10 ;
break ;
case WeatherPressureUnits . psi :
pressure = Math . round ( ( pressure * 0.0145037738 ) * 10 ) / 10 ;
pressure _unit = "psi" ;
break ;
}
case WeatherUnits . KELVIN :
temperature = this . toKelvin ( temperature ) ;
break ;
switch ( this . _units ) {
case WeatherUnits . FAHRENHEIT :
temperature = this . toFahrenheit ( temperature ) ;
break ;
case WeatherUnits . RANKINE :
temperature = this . toRankine ( temperature ) ;
break ;
case WeatherUnits . CELSIUS :
temperature = Math . round ( temperature * 10 ) / 10 ;
break ;
case WeatherUnits . REAUMUR :
temperature = this . toReaumur ( temperature ) ;
break ;
case WeatherUnits . KELVIN :
temperature = this . toKelvin ( temperature ) ;
break ;
case WeatherUnits . ROEMER :
temperature = this . toRoemer ( temperature ) ;
break ;
case WeatherUnits . RANKIN E:
temperature = this . toRankin e ( temperature ) ;
break ;
case WeatherUnits . DELISL E:
temperature = this . toDelisl e ( temperature ) ;
break ;
case WeatherUnits . REAUMUR :
temperature = this . toReaumur ( temperature ) ;
break ;
case WeatherUnits . NEWTON :
temperature = this . toNewton ( temperature ) ;
break ;
}
case WeatherUnits . ROEMER :
temperature = this . toRoemer ( temperature ) ;
break ;
let lastBuild = '-' ;
case WeatherUnits . DELISLE :
temperature = this . toDelisle ( temperature ) ;
break ;
if ( this . _clockFormat == "24h" ) {
sunrise = new Date ( sunrise * 1000 ) . toLocaleFormat ( "%R" ) ;
sunset = new Date ( sunset * 1000 ) . toLocaleFormat ( "%R" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%R" ) ;
} else {
sunrise = new Date ( sunrise * 1000 ) . toLocaleFormat ( "%I:%M %p" ) ;
sunset = new Date ( sunset * 1000 ) . toLocaleFormat ( "%I:%M %p" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%I:%M %p" ) ;
}
case WeatherUnits . NEWTON :
temperature = this . toNewton ( temperature ) ;
break ;
}
let beginOfDay = new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ;
let d = Math . floor ( ( beginOfDay . getTime ( ) - this . lastBuildDate . getTime ( ) ) / 86400000 ) ;
if ( d < 0 ) {
lastBuild = _ ( "Yesterday" ) ;
if ( d < - 1 )
lastBuild = _ ( "%s days ago" ) . replace ( "%s" , - 1 * d ) ;
}
let lastBuild = '-' ;
this . _currentWeatherIcon . icon _name = this . _weatherIcon . icon _name = iconname ;
if ( this . _clockFormat == "24h" ) {
sunrise = new Date ( sunrise * 1000 ) . toLocaleFormat ( "%R" ) ;
sunset = new Date ( sunset * 1000 ) . toLocaleFormat ( "%R" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%R" ) ;
} else {
sunrise = new Date ( sunrise * 1000 ) . toLocaleFormat ( "%I:%M %p" ) ;
sunset = new Date ( sunset * 1000 ) . toLocaleFormat ( "%I:%M %p" ) ;
lastBuild = this . lastBuildDate . toLocaleFormat ( "%I:%M %p" ) ;
}
let weatherInfoC = "" ;
let weatherInfoT = "" ;
if ( d >= 1 ) {
lastBuild = _ ( "Yesterday" ) ;
if ( d > 1 )
lastBuild = _ ( "%s days ago" ) . replace ( "%s" , d ) ;
}
if ( this . _comment _in _panel )
weatherInfoC = comment ;
this . _currentWeatherIcon . icon _name = this . _weatherIcon . icon _name = iconname ;
if ( this . _text _in _panel )
weatherInfoT = parseFloat ( temperature ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
let weatherInfoC = "" ;
let weatherInfoT = "" ;
this . _weatherInfo . text = weatherInfoC + ( ( weatherInfoC && weatherInfoT ) ? ", " : "" ) + weatherInfoT ;
if ( this . _comment _in _panel )
weatherInfoC = comment ;
this . _currentWeatherSummary . text = comment + ", " + parseFloat ( temperature ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
this . _currentWeatherLocation . text = location ;
this . _currentWeatherTemperature . text = cloudiness + ' %' ;
this . _currentWeatherHumidity . text = parseFloat ( humidity ) . toLocaleString ( ) + ' %' ;
this . _currentWeatherPressure . text = parseFloat ( pressure ) . toLocaleString ( ) + ' ' + pressure _unit ;
this . _currentWeatherSunrise . text = sunrise ;
this . _currentWeatherSunset . text = sunset ;
this . _currentWeatherBuild . text = lastBuild ;
if ( this . _text _in _panel )
weatherInfoT = parseFloat ( temperature ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
// Override wind units with our preference
switch ( this . _wind _speed _units ) {
case WeatherWindSpeedUnits . MPH :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _MPH ) * 10 ) / 10 ;
wind _unit = 'mph' ;
break ;
this . _weatherInfo . text = weatherInfoC + ( ( weatherInfoC && weatherInfoT ) ? ", " : "" ) + weatherInfoT ;
case WeatherWindSpeedUnits . KPH :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _KPH ) * 10 ) / 10 ;
wind _unit = 'km/h' ;
break ;
this . _currentWeatherSummary . text = comment + ", " + parseFloat ( temperature ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
this . _currentWeatherLocation . text = location ;
this . _currentWeatherTemperature . text = cloudiness + ' %' ;
this . _currentWeatherHumidity . text = parseFloat ( humidity ) . toLocaleString ( ) + ' %' ;
this . _currentWeatherPressure . text = parseFloat ( pressure ) . toLocaleString ( ) + ' ' + pressure _unit ;
this . _currentWeatherSunrise . text = sunrise ;
this . _currentWeatherSunset . text = sunset ;
this . _currentWeatherBuild . text = lastBuild ;
case WeatherWindSpeedUnits . MPS :
wind = Math . round ( wind * 10 ) / 10 ;
break ;
// Override wind units with our preference
switch ( this . _wind _speed _units ) {
case WeatherWindSpeedUnits . MPH :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _MPH ) * 10 ) / 10 ;
wind _unit = 'mph' ;
break ;
case WeatherWindSpeedUnits . KNOTS :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _KNOTS ) * 10 ) / 10 ;
wind _unit = 'kn' ;
break ;
case WeatherWindSpeedUnits . KPH :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _KPH ) * 10 ) / 10 ;
wind _unit = 'km/h ' ;
break ;
case WeatherWindSpeedUnits . FPS :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _FPS ) * 10 ) / 10 ;
wind _unit = 'ft/s ' ;
break ;
case WeatherWindSpeedUnits . MPS :
wind = Math . round ( wind * 10 ) / 10 ;
break ;
case WeatherWindSpeedUnits . BEAUFORT :
wind _unit = this . toBeaufort ( wind , true ) ;
wind = this . toBeaufort ( wind ) ;
}
case WeatherWindSpeedUnits . KNOTS :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _KNOTS ) * 10 ) / 10 ;
wind _unit = 'kn' ;
break ;
if ( ! wind )
this . _currentWeatherWind . text = '\u2013' ;
else if ( wind == 0 || ! wind _direction )
this . _currentWeatherWind . text = parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
else // i.e. wind > 0 && wind_direction
this . _currentWeatherWind . text = wind _direction + ' ' + parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
case WeatherWindSpeedUnits . FPS :
wind = Math . round ( ( wind * WEATHER _CONV _MPS _IN _FPS ) * 10 ) / 10 ;
wind _unit = 'ft/s' ;
break ;
} ,
case WeatherWindSpeedUnits . BEAUFORT :
wind _unit = this . toBeaufort ( wind , true ) ;
wind = this . toBeaufort ( wind ) ;
}
refreshWeatherCurrent : function ( recurse ) {
if ( ! this . extractId ( this . _city ) ) {
this . updateCities ( ) ;
return ;
}
this . oldLocation = this . extractCity ( this . _city ) ;
if ( ! wind )
this . _currentWeatherWind . text = '\u2013' ;
else if ( wind == 0 || ! wind _direction )
this . _currentWeatherWind . text = parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
else // i.e. wind > 0 && wind_direction
this . _currentWeatherWind . text = wind _direction + ' ' + parseFloat ( wind ) . toLocaleString ( ) + ' ' + wind _unit ;
let params = {
q : this . oldLocation ,
units : 'metric'
} ;
if ( this . _appid )
params [ 'APPID' ] = this . _appid ;
this . load _json _async ( WEATHER _URL _CURRENT , params , function ( json ) {
if ( ! json )
return ;
if ( Number ( json . cod ) != 200 )
return ;
if ( this . currentWeatherCache != json )
this . currentWeatherCache = json ;
this . rebuildSelectCityItem ( ) ;
this . parseWeatherCurrent ( ) ;
this . parseWeatherForecast ( ) ;
return 0 ;
} ) ;
// Repeatedly refresh weather if recurse is set
@ -1343,7 +1374,91 @@ weather-storm.png = weather-storm-symbolic.svg
this . refreshWeatherCurrent ( true ) ;
} ) ) ;
}
return 0 ;
} ,
parseWeatherForecast : function ( ) {
if ( this . forecastWeatherCache == 'undefined' ) {
this . refreshWeatherForecast ( ) ;
return ;
}
let forecast = this . forecastWeatherCache ;
let beginOfDay = new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ;
// Refresh forecast
for ( let i = 0 ; i < this . _days _forecast ; i ++ ) {
let forecastUi = this . _forecast [ i ] ;
let forecastData = forecast [ i ] ;
if ( forecastData == 'undefined' )
continue ;
let t _low = forecastData . temp . min ;
let t _high = forecastData . temp . max ;
switch ( this . _units ) {
case WeatherUnits . FAHRENHEIT :
t _low = this . toFahrenheit ( t _low ) ;
t _high = this . toFahrenheit ( t _high ) ;
break ;
case WeatherUnits . CELSIUS :
t _low = Math . round ( t _low * 10 ) / 10 ;
t _high = Math . round ( t _high * 10 ) / 10 ;
break ;
case WeatherUnits . KELVIN :
t _low = this . toKelvin ( t _low ) ;
t _high = this . toKelvin ( t _high ) ;
break ;
case WeatherUnits . RANKINE :
t _low = this . toRankine ( t _low ) ;
t _high = this . toRankine ( t _high ) ;
break ;
case WeatherUnits . REAUMUR :
t _low = this . toReaumur ( t _low ) ;
t _high = this . toReaumur ( t _high ) ;
break ;
case WeatherUnits . ROEMER :
t _low = this . toRoemer ( t _low ) ;
t _high = this . toRoemer ( t _high ) ;
break ;
case WeatherUnits . DELISLE :
t _low = this . toDelisle ( t _low ) ;
t _high = this . toDelisle ( t _high ) ;
break ;
case WeatherUnits . NEWTON :
t _low = this . toNewton ( t _low ) ;
t _high = this . toNewton ( t _high ) ;
break ;
}
let comment = forecastData . weather [ 0 ] . description ;
if ( this . _translate _condition )
comment = this . get _weather _condition ( forecastData . weather [ 0 ] . id ) ;
let forecastDate = new Date ( forecastData . dt * 1000 ) ;
let dayLeft = Math . floor ( ( forecastDate . getTime ( ) - beginOfDay . getTime ( ) ) / 86400000 ) ;
let date _string = _ ( "Today" ) ;
if ( dayLeft == 1 )
date _string = _ ( "Tomorrow" ) ;
else if ( dayLeft > 1 )
date _string = _ ( "In %s days" ) . replace ( "%s" , dayLeft ) ;
else if ( dayLeft == - 1 )
date _string = _ ( "Yesterday" ) ;
else if ( dayLeft < - 1 )
date _string = _ ( "%s days ago" ) . replace ( "%s" , - 1 * dayLeft ) ;
forecastUi . Day . text = date _string + ' (' + this . get _locale _day ( forecastDate . getDay ( ) ) + ')' ;
forecastUi . Temperature . text = '\u2193 ' + parseFloat ( t _low ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) + ' \u2191 ' + parseFloat ( t _high ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
forecastUi . Summary . text = comment ;
forecastUi . Icon . icon _name = this . get _weather _icon _safely ( forecastData . weather [ 0 ] . id ) ;
}
} ,
refreshWeatherForecast : function ( recurse ) {
@ -1352,97 +1467,27 @@ weather-storm.png = weather-storm-symbolic.svg
return 0 ;
}
this . oldLocation = this . extractCity ( this . _city ) ;
let params = {
q : this . extractCity ( this . _city ) ,
q : this . oldLocation ,
units : 'metric' ,
cnt : '10 '
cnt : '13 '
} ;
if ( this . _appid )
params [ 'APPID' ] = this . _appid ;
this . load _json _async ( WEATHER _URL _FORECAST , params , function ( json ) {
if ( ! json )
return 0 ;
return ;
if ( Number ( json . cod ) != 200 )
return 0 ;
let forecast = json . list ;
// Refresh forecast
for ( let i = 0 ; i < this . _days _forecast ; i ++ ) {
let forecastUi = this . _forecast [ i ] ;
let forecastData = forecast [ i ] ;
let t _low = forecastData . temp . min ;
let t _high = forecastData . temp . max ;
switch ( this . _units ) {
case WeatherUnits . FAHRENHEIT :
t _low = this . toFahrenheit ( t _low ) ;
t _high = this . toFahrenheit ( t _high ) ;
break ;
case WeatherUnits . CELSIUS :
t _low = Math . round ( t _low * 10 ) / 10 ;
t _high = Math . round ( t _high * 10 ) / 10 ;
break ;
case WeatherUnits . KELVIN :
t _low = this . toKelvin ( t _low ) ;
t _high = this . toKelvin ( t _high ) ;
break ;
case WeatherUnits . RANKINE :
t _low = this . toRankine ( t _low ) ;
t _high = this . toRankine ( t _high ) ;
break ;
case WeatherUnits . REAUMUR :
t _low = this . toReaumur ( t _low ) ;
t _high = this . toReaumur ( t _high ) ;
break ;
case WeatherUnits . ROEMER :
t _low = this . toRoemer ( t _low ) ;
t _high = this . toRoemer ( t _high ) ;
break ;
case WeatherUnits . DELISLE :
t _low = this . toDelisle ( t _low ) ;
t _high = this . toDelisle ( t _high ) ;
break ;
case WeatherUnits . NEWTON :
t _low = this . toNewton ( t _low ) ;
t _high = this . toNewton ( t _high ) ;
break ;
}
let comment = forecastData . weather [ 0 ] . description ;
if ( this . _translate _condition )
comment = this . get _weather _condition ( forecastData . weather [ 0 ] . id ) ;
let forecastDate = new Date ( forecastData . dt * 1000 ) ;
let actualDate = new Date ( ) ;
let dayLeft = Math . floor ( ( actualDate . getTime ( ) - forecastDate . getTime ( ) ) / 1000 / 60 / 60 / 24 ) ;
let date _string = _ ( "Today" ) ;
if ( dayLeft == - 1 )
date _string = _ ( "Tomorrow" ) ;
else if ( dayLeft < - 1 )
date _string = _ ( "In %s days" ) . replace ( "%s" , - 1 * dayLeft ) ;
else if ( dayLeft == 1 )
date _string = _ ( "Yesterday" ) ;
else if ( dayLeft > 1 )
date _string = _ ( "%s days ago" ) . replace ( "%s" , dayLeft ) ;
forecastUi . Day . text = date _string + ' (' + this . get _locale _day ( forecastDate . getDay ( ) ) + ')' ;
forecastUi . Temperature . text = '\u2193 ' + parseFloat ( t _low ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) + ' \u2191 ' + parseFloat ( t _high ) . toLocaleString ( ) + ' ' + this . unit _to _unicode ( ) ;
forecastUi . Summary . text = comment ;
forecastUi . Icon . icon _name = this . get _weather _icon _safely ( forecastData . weather [ 0 ] . id ) ;
}
return 0 ;
return ;
if ( this . forecastWeatherCache != json . list )
this . forecastWeatherCache = json . list ;
this . parseWeatherForecast ( ) ;
} ) ;
// Repeatedly refresh weather if recurse is set