Sunrise - Sunset Calculator (Ruby)

Post any examples or modules that you want to share here
Post Reply
User avatar
DaveyBoy
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Sunrise - Sunset Calculator (Ruby)

Post 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 1155 times
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Sunrise - Sunset Calculator (Ruby)

Post by RJHollins »

that is cool !
8-)
User avatar
DaveyBoy
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Sunrise - Sunset Calculator (Ruby)

Post 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:
User avatar
PrDavid
Posts: 1
Joined: Mon Feb 20, 2017 3:03 am
Contact:

Sunrise Sunset Calculator Ruby

Post 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?
User avatar
DaveyBoy
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Sunrise - Sunset Calculator (Ruby)

Post 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. :)
Post Reply