[Koha-bugs] [Bug 13601] Get rid of DateTime::Format::DateParse

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue Mar 10 10:14:34 CET 2015


http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13601

--- Comment #26 from Marc Véron <veron at veron.ch> ---
Created attachment 36756
  -->
http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=36756&action=edit
[Signed-off] Bug 13601: Fix special case in basket.pl

There is a badly managed date in acqui/basket.pl:
if the date is 15/01/2015 (metric format), it will become
2015-1-15 after the following line:
  $estimateddeliverydate = "$year-$month-$day";
Add_Delta_Days is used at several place, and the ouput is forced to
display date on 4 digits and month/day on 2 digits.
This patch does the same thing for $estimateddeliverydate.

Note that I previously developed a patch to take this format into account (with
missing 0)
in Koha::DateUtils::dt_from_string, but I don't think it's a good idea
to manage bad formated dates.
We will certainly find some issues after previous patches, but it will permit
to catch
them!
IMO it's preferable than to keep them hidden.

The patch was:
    diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm
    index 5fe2653..4434a67 100644
    --- a/Koha/DateUtils.pm
    +++ b/Koha/DateUtils.pm
    @@ -72,17 +72,17 @@ sub dt_from_string {
             my $fallback_re = qr|
                 (?<year>\d{4})
                 -
    -            (?<month>\d{2})
    +            (?<month>\d{1,2})
                 -
    -            (?<day>\d{2})
    +            (?<day>\d{1,2})
             |xms;

             if ( $date_format eq 'metric' ) {
                 # metric format is "dd/mm/yyyy[ hh:mm:ss]"
                 $regex = qr|
    -                (?<day>\d{2})
    +                (?<day>\d{1,2})
                     /
    -                (?<month>\d{2})
    +                (?<month>\d{1,2})
                     /
                     (?<year>\d{4})
                 |xms;
    @@ -90,9 +90,9 @@ sub dt_from_string {
             elsif ( $date_format eq 'us' ) {
                 # us format is "mm/dd/yyyy[ hh:mm:ss]"
                 $regex = qr|
    -                (?<month>\d{2})
    +                (?<month>\d{1,2})
                     /
    -                (?<day>\d{2})
    +                (?<day>\d{1,2})
                     /
                     (?<year>\d{4})
                 |xms;
    diff --git a/t/DateUtils.t b/t/DateUtils.t
    index 886e1d6..0877240 100755
    --- a/t/DateUtils.t
    +++ b/t/DateUtils.t
    @@ -189,3 +189,8 @@ is( output_pref( { dt => $dt } ), '31/01/2015 12:34',
'dt_from_string should mat
     # date before 1900
     $dt = dt_from_string('01/01/1900');
     is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900',
'dt_from_string should manage date < 1900' );
    +
    +# missing 0
    +$dt = dt_from_string('1/1/2015');
    +is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/2015',
'dt_from_string should generate a DT object even if 0 are missing' );

Works as expected.
Signed-off-by: Marc Véron <veron at veron.ch>

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list