Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "time"
- class Time
- def humanize
- time = to_est(self.round_off(900)).split(",")
- first = time[0].to_i
- time_to_word = {12=> "twelve",
- 11 => "eleven",
- 10 => "ten",
- 9 => "nine",
- 8 => "eight",
- 7 => "seven",
- 6 => "six",
- 5 => "five",
- 4 => "four",
- 3 => "three",
- 2 => "two",
- 1 => "one"}
- case time[1]
- when "00" then
- if first == 12
- "About Midnight"
- else
- "About #{time_to_word[first]}"
- end
- when "15" then "About a quarter past #{time_to_word[first]}"
- when "30" then
- if first == 12
- "About #{first}:30"
- else
- "About half past #{time_to_word[first]}"
- end
- when "45" then "About a quarter till #{time_to_word[first.next]}"
- end
- end
- def round_off(seconds = 60)
- Time.at((self.to_f / seconds).round * seconds)
- end
- def to_est(ist)
- ist.strftime("%I,%M")
- end
- end
- puts Time.parse("00:05").humanize
Advertisement
Add Comment
Please, Sign In to add comment