CHALLENGE DESCRIPTION:
You are given the pairs of time values. The values are in the HH:MM:SS format with leading zeros. Your task is to find out the time difference between the pairs.
INPUT SAMPLE:
14:01:57 12:47:11 13:09:42 22:16:15 08:08:06 08:38:28 23:35:07 02:49:59 14:31:45 14:46:56
OUTPUT SAMPLE:
Print to stdout the time difference for each pair, one per line. You must format the time values in HH:MM:SS with leading zeros.
For example:
01:14:46 09:06:33 00:30:22 20:45:08 00:15:11
My Code
#!/usr/bin/env ruby -w require 'time' def delta_time(strTime1, strTime2) time1 = Time.parse(strTime1) time2 = Time.parse(strTime2) delta_sec = (time1 - time2).abs (Time.new(0) + delta_sec).strftime('%H:%M:%S') end ARGF.each_line do |line| puts delta_time(*line.chomp.split) end