Skip to content

Commit

Permalink
Issue #374: declare $CPANDateTimeObject in a more limited scope
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed Aug 19, 2020
1 parent 28c1243 commit c47863b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Kernel/System/DateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ Creates a DateTime object. Do not use new() directly, instead use the object man
=cut

sub new {
my ( $Type, %Param ) = @_;
my ( $Class, %Param ) = @_;

# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
my $Self = bless {}, $Class;

# CPAN DateTime: only use English descriptions and abbreviations internally.
# This has nothing to do with the user's locale settings in OTOBO.
Expand All @@ -162,6 +161,7 @@ sub new {
# by the Clone() method).
if ( $Param{_CPANDateTimeObject} ) {
$Self->{CPANDateTimeObject} = $Param{_CPANDateTimeObject};

return $Self;
}

Expand Down Expand Up @@ -1834,7 +1834,6 @@ sub _CPANDateTimeObjectCreate {
);
}

my $CPANDateTimeObject;
my $TimeZone = $Param{TimeZone} || $Self->OTOBOTimeZoneGet();

if ( !$Self->IsTimeZoneValid( TimeZone => $TimeZone ) ) {
Expand All @@ -1858,8 +1857,8 @@ sub _CPANDateTimeObjectCreate {
return;
}

eval {
$CPANDateTimeObject = DateTime->from_epoch(
my $CPANDateTimeObject = eval {
DateTime->from_epoch(
epoch => $Param{Epoch},
time_zone => $TimeZone,
locale => $Self->{Locale},
Expand Down Expand Up @@ -1891,8 +1890,8 @@ sub _CPANDateTimeObjectCreate {
# Create DateTime object
my $DateTimeParams = $Self->_ToCPANDateTimeParamNames(%Param);

eval {
$CPANDateTimeObject = DateTime->new(
my $CPANDateTimeObject = eval {
DateTime->new(
%{$DateTimeParams},
locale => $Self->{Locale},
);
Expand All @@ -1902,8 +1901,8 @@ sub _CPANDateTimeObjectCreate {
}

# Create object with current date/time.
eval {
$CPANDateTimeObject = DateTime->now(
my $CPANDateTimeObject = eval {
DateTime->now(
time_zone => $TimeZone,
locale => $Self->{Locale},
);
Expand Down

0 comments on commit c47863b

Please sign in to comment.