Page 1 of 1

Sunrise - Sunset Calculator (Ruby)

PostPosted: 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) :lol:

Here it is for anyone who's interested:

Sunset Algorithm with Altitude.fsm
(2.04 KiB) Downloaded 1036 times

Re: Sunrise - Sunset Calculator (Ruby)

PostPosted: Mon Apr 03, 2017 6:19 pm
by RJHollins
that is cool !
8-)

Re: Sunrise - Sunset Calculator (Ruby)

PostPosted: 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 :oops:

Sunrise Sunset Calculator Ruby

PostPosted: 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)

PostPosted: 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. :)