Created
February 19, 2009 17:48
-
-
Save jubishop/67025 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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