2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/time_presenter.rb', line 2
def present_hours_as_string(time)
hours = time.floor
fraction = time - hours
minutes = (60.0 * fraction)
minutes_string = minutes.floor.to_s
minutes_string = "0#{minutes_string}" if minutes < 10.0 && hours > 0.0
fraction = minutes - minutes.floor
seconds = (60.0 * fraction)
seconds_string = seconds.round.to_s
seconds_string = "0#{seconds_string}" if seconds < 10.0
if hours > 0.0
"#{hours}:#{minutes_string}:#{seconds_string}"
elsif minutes > 0.0
"#{minutes_string}:#{seconds_string}"
else
"0:#{seconds_string}"
end
end
|