modified: widgets/weather.lua - fixed the OWM "feature" for icon day/night state calculated in accordance with current GMT time (it seems OWM knows nothing of local time and time zones)

This commit is contained in:
Aleksandr Beliaev 2016-05-27 13:01:58 +12:00
parent 6fd1eecd43
commit afd51e20bb
1 changed files with 11 additions and 2 deletions

View File

@ -117,11 +117,20 @@ local function worker(args)
function weather.update()
local cmd = string.format(current_call, city_id, units, lang, APPID)
async.request(cmd, function(f)
local pos, err
local pos, err, sunrise, sunset, current_dt, datetime, icon
weather_now, pos, err = json.decode(f, 1, nil)
if not err and weather_now and tonumber(weather_now["cod"]) == 200 then
weather.icon_path = icons_path .. weather_now["weather"][1]["icon"] .. ".png"
current_dt = os.time()
sunrise = weather_now["sys"]["sunrise"]
sunset = weather_now["sys"]["sunset"]
if current_dt > sunrise and current_dt < sunset then
datetime="d"
else
datetime="n"
end
icon = weather_now["weather"][1]["icon"]
weather.icon_path = icons_path .. icon:sub(1,2) .. datetime .. ".png"
widget = weather.widget
settings()
else