module BBS::Season::Clock
The class methods of a Season for the clock and the sky: the offset of a time zone (Season.offset), EU summer time (Season.eu_summer?) and the sunrise and sunset of a day (Season.sun).
Constants
- DECLINATION
-
The sun’s declination in radians as a NOAA series over the fractional year: the constant and the [cos, sin] of each harmonic.
- EQUATION_OF_TIME
-
The equation of time (over 229.18 minutes) as a NOAA series.
Public Instance Methods
Source
# File lib/bbs/season/clock.rb, line 30 def eu_summer?(utc) year = utc.year utc >= Time.utc(year, 3, last_sunday(year, 3), 1) && utc < Time.utc(year, 10, last_sunday(year, 10), 1) end
Whether EU summer time is in force at utc: from 01:00 UTC on the last Sunday of March to 01:00 UTC on the last Sunday of October.
Source
# File lib/bbs/season/clock.rb, line 36 def last_sunday(year, month) last = Date.new(year, month, -1) last.day - last.wday end
The day of the month of the last Sunday of month in year.
Source
# File lib/bbs/season/clock.rb, line 17 def offset(tz, utc) return tz.utc_offset_at(utc) if tz.respond_to?(:utc_offset_at) return tz.period_for_utc(utc).utc_total_offset if tz.respond_to?(:period_for_utc) name = tz.to_s return fixed_offset(name) if OFFSET_RE.match?(name) return zone_offset(name, utc) if ZONES.key?(name) tzinfo(name).period_for_utc(utc).utc_total_offset end
The offset from UTC in seconds of time zone tz (see Season.now) at utc, a Time. Raises ArgumentError for a zone it does not know.
# File lib/bbs/season/clock.rb, line 44 def sun(date, latitude, longitude) g = 2 * Math::PI / 365 * (date.yday - 1) ha = hour_angle(latitude * Math::PI / 180, series(DECLINATION, g)) return [nil, nil] unless ha [ha, -ha].map { |h| 720 - (4 * (longitude + h)) - (229.18 * series(EQUATION_OF_TIME, g)) } end
Sunrise and sunset on date (a Date) at latitude, longitude, in minutes after midnight UTC (Floats): [rise, set], or [nil, nil] for polar day or night. The NOAA approximation.