Skip to content

Instantly share code, notes, and snippets.

@mistrikushal
Created September 8, 2016 10:29
Show Gist options
  • Save mistrikushal/b342a4331c739dedcf00e009d48c138b to your computer and use it in GitHub Desktop.
Save mistrikushal/b342a4331c739dedcf00e009d48c138b to your computer and use it in GitHub Desktop.
Time difference test
require 'time'
require 'rubygems'
def calc_time_diff(current_time, end_time, end_time2=nil)
parsed_end_time = Time.parse(end_time)
parsed_current_time = Time.parse(current_time)
result = Hash.new
if parsed_end_time < parsed_current_time
secs_diff = (parsed_current_time - parsed_end_time).to_i.abs
minutes_diff = secs_diff/ 60
return result.merge!(success: '1', errorDescription: '', correctedEndTime: parsed_end_time, timeDifference: minutes_diff, thresholdCrossed: '0')
elsif parsed_end_time > parsed_current_time # for this work is in progress
p parsed_end_time - 1.day.ago
end
end
p calc_time_diff '07:00 PM', '10:00 AM'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment