Added some fixes to support TimeCalculation without config and timezone.

This commit is contained in:
Martin Edenhofer 2013-06-13 12:00:03 +02:00
parent e127028f1d
commit c6e32501f6
4 changed files with 60 additions and 12 deletions

View file

@ -610,8 +610,8 @@ class Ticket < ApplicationModel
# first response
if sla_selected.first_response_time
self.first_response_escal_date = TimeCalculation.dest_time( created_at, sla_selected.first_response_time, sla_selected.data, sla_selected.timezone )
extended_escalation = escalation_suspend( self.first_response_escal_date, 'relative', sla_selected.timezone)
self.first_response_escal_date = TimeCalculation.dest_time( self.first_response_escal_date, extended_escalation.to_i, sla_selected.timezone)
extended_escalation = escalation_suspend( self.first_response_escal_date, 'relative', sla_selected )
self.first_response_escal_date = TimeCalculation.dest_time( self.first_response_escal_date, extended_escalation.to_i, sla_selected.data, sla_selected.timezone )
# set ticket escalation
self.escalation_time = self._escalation_calculation_higher_time( self.escalation_time, self.first_response_escal_date, self.first_response )
@ -737,7 +737,11 @@ def escalation_suspend (end_time, type, sla_selected)
# use time if ticket got from e. g. open to pending
if history_item['value_from'] != 'pending' && history_item['value_to'] == 'pending'
if sla_selected
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'],sla_selected.data, sla_selected.timezone)
else
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'] )
end
puts 'Diff count !=pending -> ==pending ' + diff.to_s
sum_temp = sum_temp + diff
total_time = total_time + diff
@ -745,13 +749,21 @@ def escalation_suspend (end_time, type, sla_selected)
# use time if ticket got from e. g. open to open
elsif history_item['value_from'] != 'pending' && history_item['value_to'] != 'pending'
if sla_selected
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'], sla_selected.data, sla_selected.timezone)
else
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'] )
end
puts 'Diff count !=pending -> !=pending ' + diff.to_s
sum_temp = sum_temp + diff
total_time = total_time + diff
last_state_is_pending = false
elsif history_item['value_from'] == 'pending' && history_item['value_to'] != 'pending'
if sla_selected
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'], sla_selected.data, sla_selected.timezone)
else
diff = TimeCalculation.business_time_diff( last_state_change, history_item['created_at'] )
end
puts 'Diff count !=pending -> !=pending ' + diff.to_s
total_time = total_time + diff
last_state_is_pending = false
@ -768,14 +780,22 @@ def escalation_suspend (end_time, type, sla_selected)
# if last state isnt pending, count rest
if !last_state_is_pending && last_state_change && last_state_change < end_time
if sla_selected
diff = TimeCalculation.business_time_diff( last_state_change, end_time, sla_selected.data, sla_selected.timezone)
else
diff = TimeCalculation.business_time_diff( last_state_change, end_time )
end
sum_temp = sum_temp + diff
total_time = total_time + diff
end
# if we have not had any state change
if !last_state_change
if sla_selected
diff = TimeCalculation.business_time_diff( self.created_at, end_time, sla_selected.data, sla_selected.timezone)
else
diff = TimeCalculation.business_time_diff( self.created_at, end_time )
end
sum_temp = sum_temp + diff
total_time = total_time + diff
end
@ -788,7 +808,6 @@ def escalation_suspend (end_time, type, sla_selected)
else
return nil
end
end
class Number

View file

@ -109,7 +109,7 @@ put working hours matrix and timezone in function, returns UTC working hours mat
=end
def self.business_time_diff(start_time, end_time, config, timezone = '')
def self.business_time_diff(start_time, end_time, config = nil, timezone = '')
if start_time.class == String
start_time = Time.parse( start_time.to_s + 'UTC' )
end
@ -117,6 +117,12 @@ put working hours matrix and timezone in function, returns UTC working hours mat
end_time = Time.parse( end_time.to_s + 'UTC' )
end
# if no config is given, just return calculation directly
if !config
return ((end_time - start_time) / 60 ).round
end
working_hours = self.working_hours(start_time, config, timezone)
week_day_map = {
@ -225,11 +231,16 @@ put working hours matrix and timezone in function, returns UTC working hours mat
=end
def self.dest_time(start_time, diff_in_min, config, timezone = '')
def self.dest_time(start_time, diff_in_min, config = nil, timezone = '')
if start_time.class == String
start_time = Time.parse( start_time.to_s + ' UTC' )
end
# if no config is given, just return calculation directly
if !config
return start_time + (diff_in_min * 60)
end
# loop
working_hours = self.working_hours(start_time, config, timezone)

View file

@ -569,6 +569,10 @@ class TicketTest < ActiveSupport::TestCase
delete = ticket.destroy
assert( delete, "ticket destroy" )
end
test 'ticket escalation suspend' do
ticket = Ticket.create(
:title => 'some title äöüß3',

View file

@ -238,6 +238,13 @@ class WorkingTimeTest < ActiveSupport::TestCase
'end_of_workday' => '6:00 pm',
},
},
# test 15
{
:start => '2013-08-29 16:01:00',
:end => '2013-08-29 16:10:59',
:diff => 10,
},
]
tests.each { |test|
diff = TimeCalculation.business_time_diff( test[:start], test[:end], test[:config], test[:timezone] )
@ -495,6 +502,13 @@ class WorkingTimeTest < ActiveSupport::TestCase
},
},
# test 17
{
:start => '2013-10-21 04:01:00',
:dest_time => '2013-10-21 06:00:00',
:diff => 119,
},
]
tests.each { |test|
dest_time = TimeCalculation.dest_time( test[:start] + ' UTC', test[:diff], test[:config], test[:timezone] )