Page 1 of 1
Sunrise - Sunset Calculator (Ruby)
Posted: Mon Apr 03, 2017 11:56 am
by DaveyBoy
So I found this Sunrise - Sunset formula on-line and thought it would be interesting to put it into Ruby, so I did, and it worked (eventually)
Here it is for anyone who's interested:
Re: Sunrise - Sunset Calculator (Ruby)
Posted: Mon Apr 03, 2017 6:19 pm
by RJHollins
that is cool !

Re: Sunrise - Sunset Calculator (Ruby)
Posted: Mon Apr 03, 2017 7:30 pm
by DaveyBoy
Yeah I thought so too. It seems very accurate when compared to on-line calculators. Not too sure about the altitude though . . . I added that myself after a little googling, hope I got it right

Sunrise Sunset Calculator Ruby
Posted: Wed Apr 05, 2017 8:30 am
by PrDavid
The calculated times for sunset/sunrise are 4 hours later than they actually are. I checked the longitude/latitude coordinates for my zip code and they are correct. Any ideas?
Re: Sunrise - Sunset Calculator (Ruby)
Posted: Wed Apr 05, 2017 9:04 am
by DaveyBoy
Hi PrDavid
I think it may be something to do with this line here:
# 10. convert UT value to local time zone of latitude/longitude
# localT = UT + localOffset + dst
localtr = utr + 0 + dst
localts = uts + 0 + dst
I may be wrong but I think the local offset is the difference between your time zone and 0 deg longitude. this would be 1 hour for every 15 deg. Mine is set to 0 because I'm in the UK. I'll dig out the original formula I found when I get home from work and post it up.
