Skip to content

Instantly share code, notes, and snippets.

@slhck slhck/time-diff.rb
Last active Sep 29, 2015

What would you like to do?
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.parse(time2_str) - Time.parse(time1_str) )
(t - t.gmt_offset).strftime("%H:%M:%S.%L")
ins ="ins.txt")
outs ="outs.txt")
diffs ="diffs.txt", "w")
inlines =
outlines =
ins.each { |l| inlines << l }
outs.each { |l| outlines << l } { |ins, outs| diffs.puts time_diff(ins, outs) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.