Quick way to check for sunrise/sunset


(Ford Prefect) #1

Well,

Going to ask if there was a quick way to check for sunrise/sunset times without having to code for zip code and all…

Found the answer before posting and thought this might help some other newbies like me!

Turns out

getSunriseAndSunset().sunrise.time and getSunriseAndSunset().sunset.time will return the sunrise and sunset times at the hub location… so now all I had to do was

private isItNight(){
           if(getSunriseAndSunset().sunrise.time < now() || 
                 getSunriseAndSunset().sunset.time > now()){
            	return true
            }
            else {
            	return false
            }
      }

Hope this helps someone!


(Edward Pope) #2

Thank you for the help.


(TAG) #3

Thanks - code snippets like this are really useful!

Hopefully someone has the time to find/organize them all and make a nice wiki page.