Last active
February 17, 2021 18:59
-
-
Save slhck/1596753 to your computer and use it in GitHub Desktop.
Calculates calculates the difference between time as HH:MM:SS.msec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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