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

(-)a/Koha/DateUtils.pm (-8 / +15 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 => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1 ] });
96
$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1, as_due_date => 0|1 ] });
97
$date_string = output_pref( $dt );
97
$date_string = output_pref( $dt );
98
98
99
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,
Lines 110-121 should be returned without the time. Link Here
110
110
111
sub output_pref {
111
sub output_pref {
112
    my $params = shift;
112
    my $params = shift;
113
    my ( $dt, $force_pref, $force_time, $dateonly );
113
    my ( $dt, $force_pref, $force_time, $dateonly, $as_due_date );
114
    if ( ref $params eq 'HASH' ) {
114
    if ( ref $params eq 'HASH' ) {
115
        $dt         = $params->{dt};
115
        $dt         = $params->{dt};
116
        $force_pref = $params->{dateformat};         # if testing we want to override Context
116
        $force_pref = $params->{dateformat};         # if testing we want to override Context
117
        $force_time = $params->{timeformat};
117
        $force_time = $params->{timeformat};
118
        $dateonly   = $params->{dateonly} || 0;    # if you don't want the hours and minutes
118
        $dateonly   = $params->{dateonly} || 0;    # if you don't want the hours and minutes
119
        $as_due_date = $params->{as_due_date} || 0; # don't display the hours and minutes if eq to 23:59 or 11:59 (depending the TimeFormat value)
119
    } else {
120
    } else {
120
        $dt = $params;
121
        $dt = $params;
121
    }
122
    }
Lines 129-157 sub output_pref { Link Here
129
130
130
    my $time_format = $force_time || C4::Context->preference('TimeFormat');
131
    my $time_format = $force_time || C4::Context->preference('TimeFormat');
131
    my $time = ( $time_format eq '12hr' ) ? '%I:%M %p' : '%H:%M';
132
    my $time = ( $time_format eq '12hr' ) ? '%I:%M %p' : '%H:%M';
132
133
    my $date;
133
    if ( $pref =~ m/^iso/ ) {
134
    if ( $pref =~ m/^iso/ ) {
134
        return $dateonly
135
        $date = $dateonly
135
          ? $dt->strftime("%Y-%m-%d")
136
          ? $dt->strftime("%Y-%m-%d")
136
          : $dt->strftime("%Y-%m-%d $time");
137
          : $dt->strftime("%Y-%m-%d $time");
137
    }
138
    }
138
    elsif ( $pref =~ m/^metric/ ) {
139
    elsif ( $pref =~ m/^metric/ ) {
139
        return $dateonly
140
        $date = $dateonly
140
          ? $dt->strftime("%d/%m/%Y")
141
          ? $dt->strftime("%d/%m/%Y")
141
          : $dt->strftime("%d/%m/%Y $time");
142
          : $dt->strftime("%d/%m/%Y $time");
142
    }
143
    }
143
    elsif ( $pref =~ m/^us/ ) {
144
    elsif ( $pref =~ m/^us/ ) {
144
145
        $date = $dateonly
145
        return $dateonly
146
          ? $dt->strftime("%m/%d/%Y")
146
          ? $dt->strftime("%m/%d/%Y")
147
          : $dt->strftime("%m/%d/%Y $time");
147
          : $dt->strftime("%m/%d/%Y $time");
148
    }
148
    }
149
    else {
149
    else {
150
        return $dateonly
150
        $date = $dateonly
151
          ? $dt->strftime("%Y-%m-%d")
151
          ? $dt->strftime("%Y-%m-%d")
152
          : $dt->strftime("%Y-%m-%d $time");
152
          : $dt->strftime("%Y-%m-%d $time");
153
    }
153
    }
154
154
155
    if ( $as_due_date ) {
156
        $time_format eq '12hr'
157
            ? $date =~ s| 11:59 PM$||
158
            : $date =~ s| 23:59$||;
159
    }
160
161
    return $date;
155
}
162
}
156
163
157
=head2 format_sqldatetime
164
=head2 format_sqldatetime
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 426-432 foreach my $biblioNum (@biblionumbers) { Link Here
426
        # change the background color.
426
        # change the background color.
427
        my $issues= GetItemIssue($itemNum);
427
        my $issues= GetItemIssue($itemNum);
428
        if ( $issues->{'date_due'} ) {
428
        if ( $issues->{'date_due'} ) {
429
            $itemLoopIter->{dateDue} = output_pref({ dt => dt_from_string($issues->{date_due}, 'sql'), dateonly => 1 });
429
            $itemLoopIter->{dateDue} = output_pref({ dt => dt_from_string($issues->{date_due}, 'sql'), as_due_date => 1 });
430
            $itemLoopIter->{backgroundcolor} = 'onloan';
430
            $itemLoopIter->{backgroundcolor} = 'onloan';
431
        }
431
        }
432
432
(-)a/t/DateUtils.t (-2 / +21 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 => 27;
8
use Test::More tests => 31;
9
use Test::MockModule;
9
use Test::MockModule;
10
10
11
BEGIN { use_ok('Koha::DateUtils'); }
11
BEGIN { use_ok('Koha::DateUtils'); }
Lines 108-110 cmp_ok( $formatted, 'eq', '16/06/2011 12:00', 'format_sqldatetime conversion' ); Link Here
108
$formatted = format_sqldatetime( undef, 'metric' );
108
$formatted = format_sqldatetime( undef, 'metric' );
109
cmp_ok( $formatted, 'eq', q{},
109
cmp_ok( $formatted, 'eq', q{},
110
    'format_sqldatetime formats undef as empty string' );
110
    'format_sqldatetime formats undef as empty string' );
111
- 
111
112
# Test the as_due_date parameter
113
$dt = DateTime->new(
114
    year       => 2013,
115
    month      => 12,
116
    day        => 11,
117
    hour       => 23,
118
    minute     => 59,
119
);
120
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr', as_due_date => 1 });
121
cmp_ok $date_string, 'eq', '11/12/2013', 'as_due_date with hours and timeformat 24hr';
122
123
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '24hr', dateonly => 1, as_due_date => 1});
124
cmp_ok $date_string, 'eq', '11/12/2013', 'as_due_date without hours and timeformat 24hr';
125
126
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '12hr', as_due_date => 1 });
127
cmp_ok $date_string, 'eq', '11/12/2013', 'as_due_date with hours and timeformat 12hr';
128
129
$date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '12hr', dateonly => 1, as_due_date => 1});
130
cmp_ok $date_string, 'eq', '11/12/2013', 'as_due_date without hours and timeformat 12hr';

Return to bug 11148