Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Ruthven committed Nov 21, 2018
1 parent 3f4ee57 commit deba5fc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<%init>
RT->Logger->error("Adding ElapsedBusinessTime to COLUMN_MAP");
$COLUMN_MAP->{'ElapsedBusinessHours'} = {
title => 'Elapsed Business (Hr)', # loc
attribute => 'Elapsed Business (Hr)',
value => sub {
my $ticket = shift;

use RT::Extension::ElapsedBusinessTime;

return RT::Extension::ElapsedBusinessTime->calc(
Ticket => $ticket,
CurrentUser => $session{CurrentUser},
Units => 'Hour',
);
}
};
$COLUMN_MAP->{'ElapsedBusinessMinutes'} = {
title => 'Elapsed Business (Min)', # loc
attribute => 'Elapsed Business (Min)',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%INIT>
RT->Logger->error("Adding ElapsedBusinessTime to fields");
push @{$Fields}, 'ElapsedBusinessMinutes', 'ElapsedBusinessTime';
RT->Logger->error("Adding ElapsedBusiness options to fields");
push @{$Fields}, 'ElapsedBusinessHours', 'ElapsedBusinessMinutes', 'ElapsedBusinessTime';
</%INIT>
<%ARGS>
$Fields => undef
Expand Down
20 changes: 17 additions & 3 deletions lib/RT/Extension/ElapsedBusinessTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ try {
countrycode => $country,
);

$dh->is_holiday(2017, 1, 1);
$dh->is_holiday(year => 2017, month => 1, day => 1);
} catch {
RT->Logger->error("Unable to instantiate Date::Holidays: $_");
$dh = undef;
};

sub calc {
my $class = shift;
my %args = ( Ticket => undef, CurrentUser => undef, DurationAsString => 0, Show => 4, Short => 1, @_);
my %args = (
Ticket => undef,
CurrentUser => undef,
DurationAsString => 0,
Show => 4,
Short => 1,
Units => 'Minute',
@_
);

my $elapsed_business_time = 0;
my $last_state_change = $args{Ticket}->CreatedObj;
Expand Down Expand Up @@ -70,7 +78,13 @@ sub calc {
Short => $args{Short},
);
} else {
return sprintf("%d:%02d", int($elapsed_business_time / 60), $elapsed_business_time % 60);
if ($args{Units} eq 'Hour') {
return sprintf("%d:%02d", int($elapsed_business_time / 3600), $elapsed_business_time % 3600);
} elsif ($args{Units} eq 'Second') {
return $elapsed_business_time;
} else {
return sprintf("%d:%02d", int($elapsed_business_time / 60), $elapsed_business_time % 60);
}
}
}

Expand Down

0 comments on commit deba5fc

Please sign in to comment.