Skip to content

Commit

Permalink
Handle not being able to load Date::Holidays
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Ruthven committed Jun 12, 2018
1 parent a56ac15 commit 3f4ee57
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/RT/Extension/ElapsedBusinessTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use RT::Extension::ElapsedBusinessTime;
our $VERSION = '0.1';

use Set::Object;
use Try::Tiny;

our $start_time = '08:30';
our $end_time = '17:30';
Expand All @@ -14,10 +15,18 @@ our $country = 'NZ';
our $region = 'Wellington';
our $excluded_states = Set::Object->new('stalled', 'blocked', 'resolved', 'rejected', 'deleted');

use Date::Holidays;
our $dh = Date::Holidays->new(
countrycode => $country,
);
our $dh = undef;
try {
use Date::Holidays;
$dh = Date::Holidays->new(
countrycode => $country,
);

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

sub calc {
my $class = shift;
Expand Down Expand Up @@ -91,7 +100,7 @@ sub calc_elapsed {
}

my ($year, $month, $day) = split(/-/, $dt_working->ymd);
if ($dh->is_holiday(year => $year, month => $month, day => $day, region => $region)) {
if (defined $dh && $dh->is_holiday(year => $year, month => $month, day => $day, region => $region)) {
# RT->Logger->debug("holiday (", $dt_working->ymd, "), skip");
next;
}
Expand Down

0 comments on commit 3f4ee57

Please sign in to comment.