From 80b856fd5b9441f0937c8c95056386409c31e5c4 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 10 Jun 2013 10:50:50 +0200 Subject: [PATCH] Added docu. --- lib/time_calculation.rb | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/time_calculation.rb b/lib/time_calculation.rb index f3e4608fc..c09e0c9f4 100644 --- a/lib/time_calculation.rb +++ b/lib/time_calculation.rb @@ -1,4 +1,23 @@ module TimeCalculation + +=begin + +put working hours matrix and timezone in function, returns UTC working hours matrix + + working_hours_martix = TimeCalculation.working_hours('2013-10-27 20:00:15', working_hours_matrix, 'Europe/Berlin') + + working_hours_martix = { + :Mon => [nil,nil,nil,nil,nil,nil,nil,nil,true,true,true,true,true,true,true,true,true,true,true,nil,nil,nil,nil,nil], + :Tue => [nil,nil,nil,nil,nil,nil,nil,nil,true,true,true,true,true,true,true,true,true,true,true,nil,nil,nil,nil,nil], + :Wed => [nil,nil,nil,nil,nil,nil,nil,nil,true,true,true,true,true,true,true,true,true,true,true,nil,nil,nil,nil,nil], + :Thu => [nil,nil,nil,nil,nil,nil,nil,nil,true,true,true,true,true,true,true,true,true,true,true,nil,nil,nil,nil,nil], + :Fri => [nil,nil,nil,nil,nil,nil,nil,nil,true,true,true,true,true,true,true,true,true,true,true,nil,nil,nil,nil,nil], + :Sat => [], + :Sun => [], + } + +=end + def self.working_hours(start_time, config, timezone) time_diff = 0 if timezone @@ -77,6 +96,19 @@ module TimeCalculation return working_hours end +=begin + + returns business hours in minutes between to dates + + business_hours_in_min = Time.Calculation.business_time_diff( + '2013-10-27 14:00:15', + '2013-10-27 18:10:15', + working_hours_martix, + 'Europe/Berlin', + ) + +=end + def self.business_time_diff(start_time, end_time, config, timezone = '') if start_time.class == String start_time = Time.parse( start_time.to_s + 'UTC' ) @@ -180,6 +212,19 @@ module TimeCalculation diff.round end +=begin + + returns destination date of start time plus X minutes + + dest_time = Time.Calculation.dest_time( + '2013-10-27 14:00:15', + 120, + working_hours_martix, + 'Europe/Berlin', + ) + +=end + def self.dest_time(start_time, diff_in_min, config, timezone = '') if start_time.class == String start_time = Time.parse( start_time.to_s + ' UTC' )