Browse Source

Bug 25133: Handle 12hr format for dt_from_string

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Jonathan Druart 3 years ago
committed by Martin Renvoize
parent
commit
0610dbd6fc
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 9
      Koha/DateUtils.pm
  2. 2
      circ/circulation.pl
  3. 13
      t/DateUtils.t

9
Koha/DateUtils.pm

@ -139,12 +139,17 @@ sub dt_from_string {
:
(?<second>\d{2})
)?
(
\s
(?<ampm>\w{2})
)?
)?
|xms;
$regex .= $time_re;
$fallback_re .= $time_re;
my %dt_params;
my $ampm;
if ( $date_string =~ $regex ) {
%dt_params = (
year => $+{year},
@ -154,6 +159,7 @@ sub dt_from_string {
minute => $+{minute},
second => $+{second},
);
$ampm = $+{ampm};
} elsif ( $date_string =~ $fallback_re ) {
%dt_params = (
year => $+{year},
@ -163,6 +169,7 @@ sub dt_from_string {
minute => $+{minute},
second => $+{second},
);
$ampm = $+{ampm};
}
else {
die "The given date ($date_string) does not match the date format ($date_format)";
@ -176,6 +183,8 @@ sub dt_from_string {
$dt_params{minute} = 00 unless defined $dt_params{minute};
$dt_params{second} = 00 unless defined $dt_params{second};
$dt_params{hour} += 12 if $ampm && $ampm eq 'PM';
my $dt = eval {
DateTime->new(
%dt_params,

2
circ/circulation.pl

@ -170,7 +170,7 @@ for my $barcode ( @$barcodes ) {
my $stickyduedate = $query->param('stickyduedate') || $session->param('stickyduedate');
my $duedatespec = $query->param('duedatespec') || $session->param('stickyduedate');
$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso', timeformat => '24hr' }); }
$duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso' }); }
if ( $duedatespec );
my $restoreduedatespec = $query->param('restoreduedatespec') || $duedatespec || $session->param('stickyduedate');
if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {

13
t/DateUtils.t

@ -4,7 +4,7 @@ use DateTime::TimeZone;
use C4::Context;
use Test::More tests => 72;
use Test::More tests => 76;
use Test::MockModule;
use Test::Warn;
@ -249,6 +249,17 @@ is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string s
$dt = dt_from_string('2015-01-31 01:02:03');
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' );
# 12hr format
$dt = dt_from_string('2015-01-31 01:02 AM');
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string ' );
$dt = dt_from_string('2015-01-31 01:02:03 AM');
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string ' );
$dt = dt_from_string('2015-01-31 01:02 PM');
is( output_pref( {dt => $dt} ), '31/01/2015 13:02', 'dt_from_string ' );
$dt = dt_from_string('2015-01-31 01:02:03 PM');
is( output_pref( {dt => $dt} ), '31/01/2015 13:02', 'dt_from_string ' );
# output_pref with no parameters, single parameter (no hash)
is( output_pref(), undef, 'Call output_pref without parameters' );
try {

Loading…
Cancel
Save