Skip to content

Commit

Permalink
Issue #2251: Fix value handling for date(time) dynamic fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaerter authored and svenoe committed Sep 18, 2023
1 parent 4b2800e commit a8d0ea6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
16 changes: 10 additions & 6 deletions Kernel/System/DynamicField/Driver/BaseDateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -425,23 +425,27 @@ sub EditFieldValueGet {
for my $Type (qw(Used Year Month Day Hour Minute)) {
my @ValueColumn = $Param{ParamObject}->GetArray( Param => $Prefix . $Type );

# pop not necessary because for loop limits to used data
# omit template values
if ( $Type ne 'Used' ) {
pop @ValueColumn;
}
$Data{$Type} = \@ValueColumn;
}

# NOTE used data in multivalue case come as value index (e.g. 0, 1, 2, ...)
# this is for the purpose to identify unchecked values (e.g. 0, 2, 4, ...)
# so, every index arriving here means that the corresponding value was checked and is therefor set to Used => 1
my @Used;
for my $Index ( $Data{Used}->@* ) {
$Used[$Index] = 1;
}
$Data{Used} = \@Used;

# transform value arrays into rows
for my $Index ( 0 .. $#{ $Data{Used} } ) {
for my $Index ( 0 .. $#{ $Data{Year} } ) {
my %ValueRow = ();
if ( $Data{Used}->[$Index] ) {
for my $Type (qw(Used Year Month Day Hour Minute)) {
$ValueRow{ $Prefix . $Type } = $Data{$Type}[$Index];
}
for my $Type (qw(Used Year Month Day Hour Minute)) {
$ValueRow{ $Prefix . $Type } = $Data{$Type}[$Index];
}
push $Value->@*, \%ValueRow;
}
Expand Down
20 changes: 13 additions & 7 deletions Kernel/System/DynamicField/Driver/Date.pm
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,27 @@ sub EditFieldValueGet {
for my $Type (qw(Used Year Month Day)) {
my @ValueColumn = $Param{ParamObject}->GetArray( Param => $Prefix . $Type );

# pop not necessary because for loop limits to used data
# omit template data
if ( $Type ne 'Used' ) {
pop @ValueColumn;
}
$Data{$Type} = \@ValueColumn;
}

# NOTE used data in multivalue case come as value index (e.g. 0, 1, 2, ...)
# this is for the purpose to identify unchecked values (e.g. 0, 2, 4, ...)
# so, every index arriving here means that the corresponding value was checked and is therefor set to Used => 1
my @Used;
for my $Index ( $Data{Used}->@* ) {
$Used[$Index] = 1;
}
$Data{Used} = \@Used;

# transform value arrays into rows
for my $Index ( 0 .. $#{ $Data{Used} } ) {
for my $Index ( 0 .. $#{ $Data{Year} } ) {
my %ValueRow = ();
if ( $Data{Used}->[$Index] ) {
for my $Type (qw(Used Year Month Day)) {
$ValueRow{ $Prefix . $Type } = $Data{$Type}[$Index];
}
for my $Type (qw(Used Year Month Day)) {
$ValueRow{ $Prefix . $Type } = $Data{$Type}[$Index] // 0;
}
push $Value->@*, \%ValueRow;
}
Expand Down Expand Up @@ -815,7 +819,9 @@ sub ReadableValueRender {

# only keep date part, loose time part of time-stamp
for my $ValueItem (@Values) {
$ValueItem =~ s{ \A (\d{4} - \d{2} - \d{2}) .+?\z }{$1}xms;
if ($ValueItem) {
$ValueItem =~ s{ \A (\d{4} - \d{2} - \d{2}) .+?\z }{$1}xms;
}
}

my $ItemSeparator = ',';
Expand Down

0 comments on commit a8d0ea6

Please sign in to comment.