Bug 2131834

Summary: call to convert_month with a substr() parameter does not recognize the result as a string
Product: Red Hat Enterprise Linux 8 Reporter: william.nardone
Component: perl-Date-CalcAssignee: Perl Maintainers <perl-maint-list>
Status: NEW --- QA Contact: RHEL CS Apps Subsystem QE <rhel-cs-apps-subsystem-qe>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.5CC: jplesnik
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description william.nardone 2022-10-03 21:07:35 UTC
Description of problem:
We have a block of code that processes a hash with a date key in "01/Jul/2022" format.  When we try to loop through the sorted keys with a sort procedure, we get  an error indicating that the parameter passed to the convert_month routine is not a string.  See the code below for a complete description.

hits hash
"01/Jul/2022"   Title1    4
"03/Jul/2022"   Title2    7
. . .

foreach $date (sort sortdate keys %hits){
 . . .
}

sub sortdate(){
    #parse the date format  DD/MMM/YYYY - i.e. 07/Feb/2019
    # into sortable key YYYY##DD - i.e. 20190207

    { substr($a,7,4) <=> substr($b,7,4) ||
      Decode_Month(substr($a,3,3)) <=>  Decode_Month(substr($b,3,3)) ||
      substr($a,0,2) <=> substr($b,0,2)
    }
}

When we run this, we get the following error:
Date::Calc::Decode_Month(): argument is not a string at ./xxx.pl line ###.  Which points to the line with the Decode_Month(substr($a,3,3)) 

I can work around the error by forcing the result of the substr() call to be a string.  Decode_Month("".substr($a,3,3)), but the type should have been set correctly without that, since substr returns the 3 character month string: Jan, Feb, ...

I put in extra debug prints and all of the keys in the hits array are valid date strings with a valid 3 char month abbreviation.

This code was ported over from Solaris and it is working fine there.

Version-Release number of selected component (if applicable): Date::Calc (6.4)


How reproducible:
Every time

Steps to Reproduce:
1.  See above code
2.
3.

Actual results:
Error message: Date::Calc::Decode_Month(): argument is not a string at ./xxx.pl line ###.

Expected results:
process sorted list of hash elements

Additional info:

Comment 1 Jitka Plesnikova 2022-10-04 09:41:06 UTC
Thank you for the report. However, if you want Red Hat to fix it, you have to file an official support request at <https://access.redhat.com/support/>.
Bugzilla is not a support tool.

Could you please provide a small script that can be used as a reproducer?

I am not able to reproduce it with this script:
https://jplesnik.fedorapeople.org/bugzillas/bz2131834.pl

Comment 2 william.nardone 2022-10-11 14:43:32 UTC
OK, Let me review and I'll work it with the red hat folks.  You can close.