View | Details | Raw Unified | Return to bug 10380
Collapse All | Expand All

(-)a/C4/Letters.pm (-2 / +2 lines)
Lines 612-620 sub _parseletter { Link Here
612
612
613
        my $dt = dt_from_string();
613
        my $dt = dt_from_string();
614
        $dt->add( days => C4::Context->preference('ReservesMaxPickUpDelay') );
614
        $dt->add( days => C4::Context->preference('ReservesMaxPickUpDelay') );
615
        $values->{'expirationdate'} = output_pref( $dt, undef, 1 );
615
        $values->{'expirationdate'} = output_pref({ dt => $dt, dateonly => 1 });
616
616
617
        $values->{'waitingdate'} = output_pref( dt_from_string( $values->{'waitingdate'} ), undef, 1 );
617
        $values->{'waitingdate'} = output_pref({ dt => dt_from_string( $values->{'waitingdate'} ), dateonly => 1 });
618
618
619
    }
619
    }
620
620
(-)a/C4/Reserves.pm (-1 / +1 lines)
Lines 1546-1552 be cleared when it is unsuspended. Link Here
1546
sub ToggleSuspend {
1546
sub ToggleSuspend {
1547
    my ( $borrowernumber, $biblionumber, $suspend_until ) = @_;
1547
    my ( $borrowernumber, $biblionumber, $suspend_until ) = @_;
1548
1548
1549
    $suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until );
1549
    $suspend_until = output_pref({ dt => dt_from_string( $suspend_until ), dateformat => 'iso' }) if ( $suspend_until );
1550
1550
1551
    my $do_until = ( $suspend_until ) ? '?' : 'NULL';
1551
    my $do_until = ( $suspend_until ) ? '?' : 'NULL';
1552
1552
(-)a/Koha/DateUtils.pm (-8 / +25 lines)
Lines 93-99 s/(\d{4})(\d{2})(\d{2})\s+(\d{2})(\d{2})(\d{2})/$1-$2-$3T$4:$5:$6/; Link Here
93
93
94
=head2 output_pref
94
=head2 output_pref
95
95
96
$date_string = output_pref($dt, [$date_format], [$time_format] );
96
$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] });
97
$date_string = output_pref( $dt );
97
98
98
Returns a string containing the time & date formatted as per the C4::Context setting,
99
Returns a string containing the time & date formatted as per the C4::Context setting,
99
or C<undef> if C<undef> was provided.
100
or C<undef> if C<undef> was provided.
Lines 109-118 If it is not defined, the default value is 0; Link Here
109
=cut
110
=cut
110
111
111
sub output_pref {
112
sub output_pref {
112
    my $dt         = shift;
113
    my $params = shift;
113
    my $force_pref = shift;         # if testing we want to override Context
114
    my ( $dt, $force_pref, $force_time, $dateonly );
114
    my $force_time = shift;
115
    if ( ref $params eq 'HASH' ) {
115
    my $dateonly   = shift || 0;    # if you don't want the hours and minutes
116
        $dt         = $params->{dt};
117
        $force_pref = $params->{dateformat};         # if testing we want to override Context
118
        $force_time = $params->{timeformat};
119
        $dateonly   = $params->{dateonly} || 0;    # if you don't want the hours and minutes
120
    } else {
121
        $dt = $params;
122
    }
116
123
117
    return unless defined $dt;
124
    return unless defined $dt;
118
125
Lines 153-159 sub output_pref { Link Here
153
160
154
=head2 output_pref_due
161
=head2 output_pref_due
155
162
156
$date_string = output_pref_due($dt, [$format] );
163
$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] });
157
164
158
Returns a string containing the time & date formatted as per the C4::Context setting
165
Returns a string containing the time & date formatted as per the C4::Context setting
159
166
Lines 190-196 sub format_sqldatetime { Link Here
190
        my $dt = dt_from_string( $str, 'sql' );
197
        my $dt = dt_from_string( $str, 'sql' );
191
        return q{} unless $dt;
198
        return q{} unless $dt;
192
        $dt->truncate( to => 'minute' );
199
        $dt->truncate( to => 'minute' );
193
        return output_pref( $dt, $force_pref, $force_time, $dateonly );
200
        return output_pref({
201
            dt => $dt,
202
            dateformat => $force_pref,
203
            timeformat => $force_time,
204
            dateonly => $dateonly
205
        });
194
    }
206
    }
195
    return q{};
207
    return q{};
196
}
208
}
Lines 213-219 sub format_sqlduedatetime { Link Here
213
    if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
225
    if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
214
        my $dt = dt_from_string( $str, 'sql' );
226
        my $dt = dt_from_string( $str, 'sql' );
215
        $dt->truncate( to => 'minute' );
227
        $dt->truncate( to => 'minute' );
216
        return output_pref_due( $dt, $force_pref, $force_time, $dateonly );
228
        return output_pref_due({
229
            dt => $dt,
230
            dateformat => $force_pref,
231
            timeformat => $force_time,
232
            dateonly => $dateonly
233
        });
217
    }
234
    }
218
    return q{};
235
    return q{};
219
}
236
}
(-)a/Koha/Template/Plugin/KohaDates.pm (-1 / +1 lines)
Lines 30-36 sub filter { Link Here
30
    return "" unless $text;
30
    return "" unless $text;
31
    $config->{with_hours} //= 0;
31
    $config->{with_hours} //= 0;
32
    my $dt = dt_from_string( $text, 'iso' );
32
    my $dt = dt_from_string( $text, 'iso' );
33
    return output_pref( $dt, undef, undef, !$config->{with_hours} );
33
    return output_pref({ dt => $dt, dateonly => !$config->{with_hours} });
34
}
34
}
35
35
36
1;
36
1;
(-)a/acqui/lateorders.pl (-2 / +2 lines)
Lines 86-95 my $estimateddeliverydateto_dt = $estimateddeliverydateto Link Here
86
86
87
# Format the output of "date from" and "date to"
87
# Format the output of "date from" and "date to"
88
if ($estimateddeliverydatefrom_dt) {
88
if ($estimateddeliverydatefrom_dt) {
89
    $estimateddeliverydatefrom = output_pref($estimateddeliverydatefrom_dt, undef, undef, 1);
89
    $estimateddeliverydatefrom = output_pref({dt => $estimateddeliverydatefrom_dt, dateonly => 1});
90
}
90
}
91
if ($estimateddeliverydateto_dt) {
91
if ($estimateddeliverydateto_dt) {
92
    $estimateddeliverydateto = output_pref($estimateddeliverydateto_dt, undef, undef, 1);
92
    $estimateddeliverydateto = output_pref({dt => $estimateddeliverydateto_dt, dateonly => 1});
93
}
93
}
94
94
95
my $branch     = $input->param('branch');
95
my $branch     = $input->param('branch');
(-)a/members/member.pl (-1 / +1 lines)
Lines 108-114 if ($member || keys %$patron) { Link Here
108
    my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
108
    my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
109
109
110
    if ( $searchfields eq "dateofbirth" ) {
110
    if ( $searchfields eq "dateofbirth" ) {
111
        $member = output_pref(dt_from_string($member), 'iso', undef, 1);
111
        $member = output_pref({dt => dt_from_string($member), dateformat => 'iso', dateonly => 1});
112
    }
112
    }
113
113
114
    my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" );
114
    my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" );
(-)a/t/DateUtils.t (-12 / +19 lines)
Lines 5-11 use DateTime; Link Here
5
use DateTime::TimeZone;
5
use DateTime::TimeZone;
6
6
7
use C4::Context;
7
use C4::Context;
8
use Test::More tests => 30;
8
use Test::More tests => 31;
9
9
10
BEGIN { use_ok('Koha::DateUtils'); }
10
BEGIN { use_ok('Koha::DateUtils'); }
11
11
Lines 23-62 cmp_ok( $dt->ymd(), 'eq', $testdate_iso, 'Returned object matches input' ); Link Here
23
$dt->set_hour(12);
23
$dt->set_hour(12);
24
$dt->set_minute(0);
24
$dt->set_minute(0);
25
25
26
my $date_string = output_pref( $dt, 'iso', '24hr' );
26
my $date_string;
27
28
my $dateformat = C4::Context->preference('dateformat');
29
cmp_ok  output_pref({ dt => $dt, dateformat => $dateformat }),
30
        'eq',
31
        output_pref($dt),
32
        'output_pref gives an hashref or a dt';
33
34
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '24hr' });
27
cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output';
35
cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output';
28
36
29
$date_string = output_pref( $dt, 'iso', '12hr' );
37
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '12hr' });
30
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr';
38
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr';
31
39
32
# "notime" doesn't actually mean anything in this context, but we
40
# "notime" doesn't actually mean anything in this context, but we
33
# can't pass undef or output_pref will try to access the database
41
# can't pass undef or output_pref will try to access the database
34
$date_string = output_pref( $dt, 'iso', 'notime', 1 );
42
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => 'notime', dateonly => 1 });
35
cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)';
43
cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)';
36
44
37
$date_string = output_pref( $dt, 'us', '24hr' );
45
$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '24hr' });
38
cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output';
46
cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output';
39
47
40
$date_string = output_pref( $dt, 'us', '12hr' );
48
$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '12hr' });
41
cmp_ok $date_string, 'eq', '06/16/2011 12:00 PM', 'us output 12hr';
49
cmp_ok $date_string, 'eq', '06/16/2011 12:00 PM', 'us output 12hr';
42
50
43
$date_string = output_pref( $dt, 'us', 'notime', 1 );
51
$date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => 'notime', dateonly => 1 });
44
cmp_ok $date_string, 'eq', '06/16/2011', 'us output (date only)';
52
cmp_ok $date_string, 'eq', '06/16/2011', 'us output (date only)';
45
53
46
# metric should return the French Revolutionary Calendar Really
54
# metric should return the French Revolutionary Calendar Really
47
$date_string = output_pref( $dt, 'metric', '24hr' );
55
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' });
48
cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output';
56
cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output';
49
57
50
$date_string = output_pref( $dt, 'metric', 'notime', 1 );
58
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => 'notime', dateonly => 1 });
51
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)';
59
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)';
52
60
53
$date_string = output_pref_due( $dt, 'metric', '24hr' );
61
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr' });
54
cmp_ok $date_string, 'eq', '16/06/2011 12:00',
62
cmp_ok $date_string, 'eq', '16/06/2011 12:00',
55
  'output_pref_due preserves non midnight HH:SS';
63
  'output_pref_due preserves non midnight HH:SS';
56
64
57
$dt->set_hour(23);
65
$dt->set_hour(23);
58
$dt->set_minute(59);
66
$dt->set_minute(59);
59
$date_string = output_pref_due( $dt, 'metric', '24hr' );
67
$date_string = output_pref_due({ dt => $dt, dateformat => 'metric', timeformat => '24hr' });
60
cmp_ok $date_string, 'eq', '16/06/2011',
68
cmp_ok $date_string, 'eq', '16/06/2011',
61
  'output_pref_due truncates HH:SS at midnight';
69
  'output_pref_due truncates HH:SS at midnight';
62
70
63
- 

Return to bug 10380