my $dt = dt_from_string();
$dt->add( days => C4::Context->preference('ReservesMaxPickUpDelay') );
- $values->{'expirationdate'} = output_pref( $dt, undef, 1 );
+ $values->{'expirationdate'} = output_pref({ dt => $dt, dateonly => 1 });
- $values->{'waitingdate'} = output_pref( dt_from_string( $values->{'waitingdate'} ), undef, 1 );
+ $values->{'waitingdate'} = output_pref({ dt => dt_from_string( $values->{'waitingdate'} ), dateonly => 1 });
}
sub ToggleSuspend {
my ( $reserve_id, $suspend_until ) = @_;
- $suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until );
+ $suspend_until = output_pref({ dt => dt_from_string( $suspend_until ), dateformat => 'iso' }) if ( $suspend_until );
my $do_until = ( $suspend_until ) ? '?' : 'NULL';
=head2 output_pref
-$date_string = output_pref($dt, [$date_format], [$time_format] );
+$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] });
+$date_string = output_pref( $dt );
Returns a string containing the time & date formatted as per the C4::Context setting,
or C<undef> if C<undef> was provided.
=cut
sub output_pref {
- my $dt = shift;
- my $force_pref = shift; # if testing we want to override Context
- my $force_time = shift;
- my $dateonly = shift || 0; # if you don't want the hours and minutes
+ my $params = shift;
+ my ( $dt, $force_pref, $force_time, $dateonly );
+ if ( ref $params eq 'HASH' ) {
+ $dt = $params->{dt};
+ $force_pref = $params->{dateformat}; # if testing we want to override Context
+ $force_time = $params->{timeformat};
+ $dateonly = $params->{dateonly} || 0; # if you don't want the hours and minutes
+ } else {
+ $dt = $params;
+ }
return unless defined $dt;
=head2 output_pref_due
-$date_string = output_pref_due($dt, [$format] );
+$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] });
Returns a string containing the time & date formatted as per the C4::Context setting
my $dt = dt_from_string( $str, 'sql' );
return q{} unless $dt;
$dt->truncate( to => 'minute' );
- return output_pref( $dt, $force_pref, $force_time, $dateonly );
+ return output_pref({
+ dt => $dt,
+ dateformat => $force_pref,
+ timeformat => $force_time,
+ dateonly => $dateonly
+ });
}
return q{};
}
if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
my $dt = dt_from_string( $str, 'sql' );
$dt->truncate( to => 'minute' );
- return output_pref_due( $dt, $force_pref, $force_time, $dateonly );
+ return output_pref_due({
+ dt => $dt,
+ dateformat => $force_pref,
+ timeformat => $force_time,
+ dateonly => $dateonly
+ });
}
return q{};
}
return "" unless $text;
$config->{with_hours} //= 0;
my $dt = dt_from_string( $text, 'iso' );
- return output_pref( $dt, undef, undef, !$config->{with_hours} );
+ return output_pref({ dt => $dt, dateonly => !$config->{with_hours} });
}
1;
# Format the output of "date from" and "date to"
if ($estimateddeliverydatefrom_dt) {
- $estimateddeliverydatefrom = output_pref($estimateddeliverydatefrom_dt, undef, undef, 1);
+ $estimateddeliverydatefrom = output_pref({dt => $estimateddeliverydatefrom_dt, dateonly => 1});
}
if ($estimateddeliverydateto_dt) {
- $estimateddeliverydateto = output_pref($estimateddeliverydateto_dt, undef, undef, 1);
+ $estimateddeliverydateto = output_pref({dt => $estimateddeliverydateto_dt, dateonly => 1});
}
my $branch = $input->param('branch');
my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
if ( $searchfields eq "dateofbirth" ) {
- $member = output_pref(dt_from_string($member), 'iso', undef, 1);
+ $member = output_pref({dt => dt_from_string($member), dateformat => 'iso', dateonly => 1});
}
my $searchtype = $input->param('searchtype');
use DateTime::TimeZone;
use C4::Context;
-use Test::More tests => 30;
+use Test::More tests => 31;
BEGIN { use_ok('Koha::DateUtils'); }
$dt->set_hour(12);
$dt->set_minute(0);
-my $date_string = output_pref( $dt, 'iso', '24hr' );
+my $date_string;
+
+my $dateformat = C4::Context->preference('dateformat');
+cmp_ok output_pref({ dt => $dt, dateformat => $dateformat }),
+ 'eq',
+ output_pref($dt),
+ 'output_pref gives an hashref or a dt';
+
+$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '24hr' });
cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output';
-$date_string = output_pref( $dt, 'iso', '12hr' );
+$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '12hr' });
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr';
# "notime" doesn't actually mean anything in this context, but we
# can't pass undef or output_pref will try to access the database
-$date_string = output_pref( $dt, 'iso', 'notime', 1 );
+$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => 'notime', dateonly => 1 });
cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)';
-$date_string = output_pref( $dt, 'us', '24hr' );
+$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '24hr' });
cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output';
-$date_string = output_pref( $dt, 'us', '12hr' );
+$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '12hr' });
cmp_ok $date_string, 'eq', '06/16/2011 12:00 PM', 'us output 12hr';
-$date_string = output_pref( $dt, 'us', 'notime', 1 );
+$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => 'notime', dateonly => 1 });
cmp_ok $date_string, 'eq', '06/16/2011', 'us output (date only)';
# metric should return the French Revolutionary Calendar Really
-$date_string = output_pref( $dt, 'metric', '24hr' );
+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' });
cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output';
-$date_string = output_pref( $dt, 'metric', 'notime', 1 );
+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => 'notime', dateonly => 1 });
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)';
-$date_string = output_pref_due( $dt, 'metric', '24hr' );
+$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' });
cmp_ok $date_string, 'eq', '16/06/2011 12:00',
'output_pref_due preserves non midnight HH:SS';
$dt->set_hour(23);
$dt->set_minute(59);
-$date_string = output_pref_due( $dt, 'metric', '24hr' );
+$date_string = output_pref_due({ dt => $dt, dateformat => 'metric', timeformat => '24hr' });
cmp_ok $date_string, 'eq', '16/06/2011',
'output_pref_due truncates HH:SS at midnight';