public
Last active

Calculates calculates the difference between time as HH:MM:SS.msec

  • Download Gist
time-diff.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/usr/bin/env ruby
# calculates the difference between time as
# "HH:MM:SS.msec" and "HH:MM:SS.msec"
# into a file called diffs.txt
 
require "Time"
 
def time_diff(time1_str, time2_str)
t = Time.at( Time.parse(time2_str) - Time.parse(time1_str) )
(t - t.gmt_offset).strftime("%H:%M:%S.%L")
end
 
 
ins = File.open("ins.txt")
outs = File.open("outs.txt")
diffs = File.new("diffs.txt", "w")
 
inlines = Array.new
outlines = Array.new
 
ins.each { |l| inlines << l }
outs.each { |l| outlines << l }
 
inlines.zip(outlines).each { |ins, outs| diffs.puts time_diff(ins, outs) }
 
diffs.close

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.