Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajuste registros do JSON de DateTime para TZ UTC #213

Merged
merged 1 commit into from Sep 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -121,9 +121,13 @@ sub PrepareRequest {
$Param{Data}->{pipeline} = 'attachment' ;
$Param{Data}->{Index} = $Index;

my $ElasticHash = $Self->_recurse_hash(
Data => $Param{Data},
);

return {
Success => 1,
Data => $Param{Data},
Data => $ElasticHash,
};
}

Expand Down Expand Up @@ -189,6 +193,67 @@ sub HandleResponse {
};
}

sub _recurse_hash {
# Arguments are a hash ref and a list of keys to find
my ( $Self, %Param ) = @_;

my $hash_return;

my $OTRSTimeZone = Kernel::System::DateTime->OTRSTimeZoneGet();

## Loop over the keys in the hash
foreach my $ItemKey (sort keys %{$Param{Data}}) {

# Get the value for the current key
my $value = $Param{Data}->{$ItemKey};

# See if the value is a hash reference
if (ref($value) eq 'HASH') {
# If it is call this function for that hash
$hash_return->{$ItemKey} = $Self->_recurse_hash(
Data => $value,
);
}
elsif (ref($value) eq 'ARRAY'){
foreach ( @{ $value } ) {
if (ref($_) eq 'HASH') {
# If it is call this function for that hash
my $returnItemArrValue = $Self->_recurse_hash(
Data => $_,
);
push @{$hash_return->{$ItemKey}}, $returnItemArrValue;
}
}
}
else {
if ($value =~ /(\d\d\d\d)-(\d?\d)-(\d?\d) (\d?\d):(\d?\d):(\d?\d)/) {

my $CreatedDateTimeObject = $Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
TimeZone => $OTRSTimeZone,
String => $value,
},
);

$CreatedDateTimeObject->ToTimeZone( TimeZone => 'UTC' );

my $CreatedDateTimeString = $CreatedDateTimeObject->Format( Format => '%Y-%m-%d %H:%M:%S' );

$hash_return->{$ItemKey} = $CreatedDateTimeString;

}
else {
$hash_return->{$ItemKey} = $value;
}

}

}

return $hash_return;
}

1;

=back
Expand Down