(22.09.2017, 10:24)admin Wrote: You can use rscalc function from common functions to get sunrise and sunset time in minutes. Then you can convert it to text (or use a day/time object instead):
Code:latitude = 11.11
longitude = 22.22
sunrise, sunset = rscalc(latitude, longitude)
sunrise_hour = math.floor(sunrise / 60)
sunrise_minute = sunrise % 60
sunset_hour = math.floor(sunset / 60)
sunset_minute = sunset % 60
sunrise_text = string.format('%02d:%02d', sunrise_hour, sunrise_minute)
sunset_text = string.format('%02d:%02d', sunset_hour, sunset_minute)
I've checked this script and probably is something wrong. E.g. for Lublin, PL google maps link:
https://www.google.pl/maps/place/Lublin/...4463?hl=pl
Based on this link I've filled the lat and lng:
Code:
lat = 22.4937308
lng = 51.2181956
sunrise, sunset = rscalc(lat, lng)
sunrise_hour = math.floor(sunrise / 60)
sunrise_minute = sunrise % 60
sunset_hour = math.floor(sunset / 60)
sunset_minute = sunset % 60
sunrise_text = string.format('%02d:%02d', sunrise_hour, sunrise_minute)
sunset_text = string.format('%02d:%02d', sunset_hour, sunset_minute)
log(sunrise_text, sunset_text)
The result is wrong:
Code:
* arg: 1
* string: 04:01
* arg: 2
* string: 15:35
It should be round about 6:23 for sunrise and 17:03 for sunset.