:
(?<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},
minute => $+{minute},
second => $+{second},
);
+ $ampm = $+{ampm};
} elsif ( $date_string =~ $fallback_re ) {
%dt_params = (
year => $+{year},
minute => $+{minute},
second => $+{second},
);
+ $ampm = $+{ampm};
}
else {
die "The given date ($date_string) does not match the date format ($date_format)";
$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,
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" ) {
use C4::Context;
-use Test::More tests => 72;
+use Test::More tests => 76;
use Test::MockModule;
use Test::Warn;
$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 {