require "time"
def extract_date(str)
str.scan(/^(\d+)\/(\d+)\/(\d+)\s*(\d+)\:(\d+)\:(\d+)/) do |mon,day,year,hour,min,sec|
return Time.utc(year, mon,day,hour,min, sec)
end
end
def split_seconds(s)
hours = s / 3600
minutes = (s % 3600) / 60
seconds = (s % 3600) % 60
return sprintf("%02d:%02d:%02d", hours.floor, minutes.floor, seconds)
end
start = nil
second = nil
File.open("subtract-time.txt").each do |record|
if record =~ /starting/ then
start = extract_date(record)
second = nil
elsif record =~ /completed/
second = extract_date(record)
end
unless second.nil? then
puts start
puts second
difference = second - start
puts split_seconds(difference)
puts "---"
end
end
|