Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created February 19, 2009 17:48
Show Gist options
  • Save jubishop/67025 to your computer and use it in GitHub Desktop.
Save jubishop/67025 to your computer and use it in GitHub Desktop.
raise 'Usage: ruby blist.rb "[H]H:MM AM|PM" "[H]H:MM AM|PM"' unless ARGV.length == 2
def parse_date(date_str)
time, meridiem = date_str.split(/\s+/)
hour, minute = time.split(/:/).map{|i| i.to_i}
hour += 12 if meridiem == "PM"
hour = 0 if meridiem == "AM" && hour == 12
{:time => "#{hour}:#{minute}", :hour => hour, :minute => minute}
end
one, two = parse_date(ARGV[0]), parse_date(ARGV[1])
degrees = (two[:time] > one[:time] ?
two[:hour] - one[:hour] :
24 - one[:hour] + two[:hour]) * 360
degrees += (two[:minute] - one[:minute]) / 60 * 360
puts degrees
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment