View Full Version : How to compare sunrise and sunsetuser data with actual time

April 24th, 2016, 06:39 AM
Hi, please for help - how to compare system
sunrise = scheduler.sunrise( latitude, longitude, [date], [timezone] )
with actual time

this works not
if (date.nowUtc() >= sunrise and date.nowUtc() <= sunset) then

and I cannot to find how to convert sunrise userdata to comparable form.
Thank you

April 24th, 2016, 10:07 AM
In general that should work, not sure if you should use nowUtc since sunrise is expressed in local time. Do some printing of the various things to see where it goes wrong

April 24th, 2016, 12:37 PM
At short interval running script sometimes i get night, sometimes day.
At attachment script and log from console, where I write actual time, sunrise, sunset, and day/night status.

April 24th, 2016, 01:10 PM
First use date.now, not date.nowUtc. sunrise/sunset times are in local time. Second What is your geo-lat-lng. The sunrise and sunset times seem off.

ne dub 24 19:24:50 2016 Time now: Sun Apr 24 17:24:49 2016 GMT
ne dub 24 19:24:50 2016 Sunrise: Sun Apr 24 03:43:55 2016 GMT
ne dub 24 19:24:50 2016 Sunset: Sun Apr 24 18:00:28 2016 GMT

April 24th, 2016, 01:52 PM
OK, I made changes. But the main troble is thant I trigger manually quickly the script, and I get 7x night and 1x day. And the same it is at normally starting, sometimes it get wrong.
Maybe the national daytime format, czech daytime format is not comparable format.

April 24th, 2016, 02:03 PM
I can test here if I have your latitude and longitude...


April 24th, 2016, 02:09 PM
Scratch that,... there is something wonky going on... checking...

April 24th, 2016, 02:18 PM
Confirmed bug,.. fixing now. Thanks for reporting!!

April 24th, 2016, 02:23 PM
New Girder release is building...

April 24th, 2016, 02:30 PM
Thank you too, perfect support!!!

April 24th, 2016, 06:31 PM
I've released build which contains the fix for Windows, Linux and RPI.

April 27th, 2016, 12:57 PM
I just installed and the date things you fixed are now working. I notice a few posts ago in this thread you mentioned that sunrise/sunset return local time however I'm not seeing this. Here's what I get:

local sunrise = scheduler.sunrise(gir.settings().latitude, gir.settings().longitude, date.now())
returns: Wed Apr 27 10:45:58 2016 GMT

local sunset = scheduler.sunset(gir.settings().latitude, gir.settings().longitude, date.now())
returns: Wed Apr 27 00:35:12 2016 GMT

Google reports:
6:45 AM
Thursday, April 28, 2016 (EDT)

8:36 PM
Wednesday, April 27, 2016 (EDT)

This is 4 hours off which would be the daylight saving time offset for the eastern timezone from UTC so it looks like it's returning UTC. If I plug in -14400 in the timezone area then I get the correct times (within a minute of what google reports). (4 * 60 seconds * 60 minutes = 14400)

I don't mind which time it returns, I'm just wondering what happens to sunrise/sunset when daylight saving time ends. If I have -14400 plugged in for summertime what happens when daylight saving time ends and and I'm now 5 hours behind UTC vs 4?

April 29th, 2016, 12:19 PM
We'll have to have a way to get the current TZ offset.... I'll have to think about that. I know I have it in the system.