3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/saw/util.rb', line 3
def self.time_diff dt1, dt2
diff = nil
diff ||= dt2 - dt1
return '00:00:00' if diff==1
str = ''
hours_diff = (diff/1.hour).round
if hours_diff > 0
str << "#{format('%02d', hours_diff)}"
diff = diff - hours_diff.hours
else
str << "00"
end
minutes_diff = (diff/1.minute).round
if minutes_diff > 0
str << ":#{format('%02d', minutes_diff)}"
diff = diff - minutes_diff.minutes
else
str << ":00"
end
seconds_diff = (diff/1.second).round
if seconds_diff > 0
str << ":#{format('%02d', seconds_diff)}"
else
str << ":00"
end
str
end
|