@@ -26,11 +26,6 @@ local function factory(args)
26
26
local current_call = args .current_call or " curl -s 'http://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'"
27
27
local forecast_call = args .forecast_call or " curl -s 'http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'"
28
28
local city_id = args .city_id or 0 -- placeholder
29
- local utc_offset = args .utc_offset or
30
- function ()
31
- local now = os.time ()
32
- return os.difftime (now , os.time (os.date (" !*t" , now ))) + ((os.date (" *t" ).isdst and 1 or 0 ) * 3600 )
33
- end
34
29
local units = args .units or " metric"
35
30
local lang = args .lang or " en"
36
31
local cnt = args .cnt or 5
@@ -119,19 +114,26 @@ local function factory(args)
119
114
local sunrise = tonumber (weather_now [" sys" ][" sunrise" ])
120
115
local sunset = tonumber (weather_now [" sys" ][" sunset" ])
121
116
local icon = weather_now [" weather" ][1 ][" icon" ]
122
- local now = os.time ()
117
+ local loc_now = os.time ()
123
118
local loc_m = os.time { year = os.date (" %Y" ), month = os.date (" %m" ), day = os.date (" %d" ), hour = 0 }
124
- local offset = utc_offset ()
125
- local utc_m = loc_m - offset
126
-
127
- -- if we are 1 day after the GMT, return 1 day back, and viceversa
128
- if offset > 0 and (now - utc_m ) >= 86400 then
129
- utc_m = utc_m + 86400
130
- elseif offset < 0 and (utc_m - now ) >= 86400 then
131
- utc_m = utc_m - 86400
119
+ local loc_t = os.difftime (loc_now , loc_m )
120
+ local loc_d = os.date (" *t" , loc_now )
121
+ local utc_d = os.date (" !*t" , loc_now )
122
+ local utc_now = os.time (utc_d )
123
+ local offdt = (loc_d .isdst and 1 or 0 ) * 3600 + 100 * (loc_d .min - utc_d .min ) / 60
124
+ local offset = os.difftime (loc_now , utc_now ) + offdt
125
+ local offday = (offset < 0 and - 86400 ) or 86400
126
+
127
+ if math.abs (loc_now - utc_now - offdt + loc_t ) >= 86400 then
128
+ utc_now = utc_now + offday
129
+ end
130
+
131
+ if offday * (loc_now - utc_now - offdt ) > 0 then
132
+ sunrise = sunrise + offday
133
+ sunset = sunset + offday
132
134
end
133
135
134
- if sunrise <= now and now <= sunset then
136
+ if sunrise <= loc_now and loc_now <= sunset then
135
137
icon = string.gsub (icon , " n" , " d" )
136
138
else
137
139
icon = string.gsub (icon , " d" , " n" )
0 commit comments