rhannequin / astronoby

Ruby library based on astronomy and astrometry books
https://dev.to/rhannequin/series/17782
MIT License
59 stars 2 forks source link

Provide sunrise and sunset times #35

Closed rhannequin closed 8 months ago

rhannequin commented 8 months ago

This implements #rising_time and #setting_time on Astronoby::Sun. As they are named, they return times (Time) of sunrise and sunset in UTC.

From my tests, the closest I can get from times computes by the IMCCE are within 30 seconds to 2 minutes of precision.

date = Date.new(1991, 3, 14)
epoch = Astronoby::Epoch.from_time(date)
observer = Astronoby::Observer.new(
  latitude: Astronoby::Angle.as_degrees(48.8566),
  longitude: Astronoby::Angle.as_degrees(2.3522)
)
sun = Astronoby::Sun.new(epoch: epoch)

sun.rising_time(observer: observer)
# => 1991-03-14 06:08:16 UTC

sun.setting_time(observer: observer)
# => 1991-03-14 17:50:37 UTC