Skip to content

Instantly share code, notes, and snippets.

@slhck
Last active February 17, 2021 18:59
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 slhck/1596753 to your computer and use it in GitHub Desktop.
Save slhck/1596753 to your computer and use it in GitHub Desktop.
Calculates calculates the difference between time as HH:MM:SS.msec
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment