class BritishSuntimesAgent

Public Instance Methods

longest_day() click to toggle source
Calls superclass method
# File lib/british_suntimes.rb, line 100
def longest_day()
      
  d = super()
  days = (Date.parse(d) - Date.today).to_i
  sunrise, sunset = to_dx().to_h[d]

  t1 = Time.parse(d + ' ' + sunrise)
  t2 = Time.parse(d + ' ' + sunset)

  su = Subunit.new(units={minutes:60, hours:60}, seconds: (t2 - t1).to_i)
  duration = su.to_s omit: [:seconds]

  d2 = Date.parse(d)
  day = d2.strftime("#{d2.day.ordinal} %B")

  s = d2.humanize
  msg =  s[0].upcase + s[1..-1] + " (%s), is the longest day of the year when #%s will enjoy %s of sunshine. The sun will rise at %sam and set at %spm." % [day, @location, duration, t1.strftime("%-I:%M"), t2.strftime("%-I:%M")]
      
end