How to compute Sunrise / Sunset ?

J

Joe Joe

I need to compute sunrise/set times in ruby for a given long lat. Does
anyone know any way to do this? Are there any modules or helper classes
out there??

thanks!
 
M

Marcin Raczkowski

Joe said:
I need to compute sunrise/set times in ruby for a given long lat. Does
anyone know any way to do this? Are there any modules or helper classes
out there??

thanks!
sunrise/sunset differ based on location and time, i think there are very
complicated equations for this but since it's so specific i doubt
anyone done this already, you probably should find webservice or page
that does that and use SOAP or mechanize to get it from there
 
J

Joe Petrini

M

Marcin Raczkowski

Szymon said:
Joe Joe wrote:

sunrise/sunset differ based on location and time,
i think there are very complicated equations [...]

Moderately complicated, I would say ;)

http://en.wikipedia.org/wiki/Sunrise_equation
did you actually read article, to use that "moderately" complicated
equation you have to calculate local noon, calculate declinations,
convert hours to hours angles, also take into consideration such things
as day-saving time, time zones etc.

anway here's page that calculates sunrise and sunset
http://aa.usno.navy.mil/data/docs/RS_OneDay.html
 
M

Marcin Raczkowski

Joe said:
Szymon said:
Joe Joe wrote:
[...]
sunrise/sunset differ based on location and time,
i think there are very complicated equations [...]
Moderately complicated, I would say ;)

http://en.wikipedia.org/wiki/Sunrise_equation

I found some python code to do it. It's pretty complicated and before I
tackle writing it in ruby, I figured I'd ask to see if anyone else has
tackled it.

http://kortis.to/radix/python/code/

well looks like 3/4 of the code is simple unit exchange, anyway if you
succeed please share ;)
 
J

Joe Petrini

Ken said:

I just came across that and had a little trouble getting it working but
realized I was passing a datetime instead of a Date.

For anyone else interested put the code above in a file sunrise.rb:
require 'Sunrise'
include Sunrise
#Create the location
loc = Sunrise::Location.new(39.2,-75.1)
Create the date
d = Date.new(2007,9,19)
sunrisetime = sunrise(d,p)


Thanks for the code, it's a lifesaver!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top