ruby-sun-times icon indicating copy to clipboard operation
ruby-sun-times copied to clipboard

Calculate sunrise and sunset times for a given time and place

trafficstars

ruby-sun-times Build Status

Calculates sunrise and sunset times

The algorithm comes from the Almanac for computers.

Usage

Requiring

In a Gemfile/Gemspec:

gem 'ruby-sun-times', require: 'sun_times'

Directly:

require 'sun_times'

Methods

The two methods rise and set each return a Time.

day = Date.new(2010, 3, 8)
latitude = 43.779
longitude = 11.432
sun_times = SunTimes.new
sun_times.rise(day, latitude, longitude) # => 2010-03-08 05:39:53 UTC
sun_times.set(day, latitude, longitude) # => 2010-03-08 17:11:16 UTC

References

  • http://www.astro.uu.nl/~strous/AA/en/reken/zonpositie.html - Calculations
  • http://williams.best.vwh.net/sunrise_sunset_algorithm.htm - Algorithm
  • http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/264573 - Ken Bloom's implementation