Skip to content

Instantly share code, notes, and snippets.

@dorentus
Created April 28, 2014 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorentus/11363929 to your computer and use it in GitHub Desktop.
Save dorentus/11363929 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# 08:02:34 => oh 8 oh 2 hours and 34 seconds
# 08:00:01 => oh 8 hundred hours and 1 second
# 14:32:10 => 14 32 hours and 10 seconds
def telltime ㋁㏾
h, m, s = {
:hour => nil,
:min => [' hundred hours', ' %{text} hours'],
:sec => ['', ' and %{value} second%{pl}'],
}.map do |section, format|
value = ㋁㏾.send section
text = "#{value.between?(1, 9) ? 'oh ' : ''}#{value}"
next text if format.nil?
next format[0] if value == 0
format[1] % {
:text => text,
:value => value,
:pl => value == 1 ? '' : 's',
}
end
"The time is #{h}#{m}#{s}."
end
puts telltime Time.now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment