How to compute Sunrise / Sunset?

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!

Joe Joe wrote:

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

and it changes during the year too…

On Sep 19, 3:30 pm, Marcin R. re[email protected] wrote:

Joe Joe wrote:

[…]

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

Moderately complicated, I would say :wink:

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

Szymon ‘tichy’ wrote:

On Sep 19, 3:30 pm, Marcin R. [email protected] wrote:

Joe Joe wrote:

[…]

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

Moderately complicated, I would say :wink:

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/

Joe Petrini wrote:

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 :wink:

Szymon ‘tichy’ wrote:

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

I found solutions in basic, common lisp and java. No Ruby :frowning:

http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/fun/sunset.cl

http://smallbasic.sourceforge.net/scode/vsrc.php?show=103

HTH…

On Wed, 19 Sep 2007 22:23:47 +0900, Joe Joe wrote:

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!

I have previously posted code for this at
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/264573

I overlooked straight solution…
Emacs editor has a calendar.
I think code in solar.el file is accurate.

http://cvs.savannah.gnu.org/viewvc/emacs/emacs/lisp/calendar/solar.el?view=markup

On Sep 19, 2007, at 7:23 AM, Joe Joe wrote:

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??

http://codeforpeople.com/lib/ruby/solpos/

this is a c extension to nrel’s c code: which is about as accurate as
it gets.

have fun.

a @ http://drawohara.com/

Ken B. wrote:

On Wed, 19 Sep 2007 22:23:47 +0900, Joe Joe wrote:

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!

I have previously posted code for this at
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/264573

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!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs