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

(-)a/Koha/DateUtils.pm (-24 / +32 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-160 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';
133
    my $date = do {
134
        given ($pref) {
135
            when (/^iso/) {
136
                $dateonly
137
                    ? $dt->strftime("%Y-%m-%d")
138
                    : $dt->strftime("%Y-%m-%d $time");
139
            }
140
            when (/^metric/) {
141
                $dateonly
142
                    ? $dt->strftime("%d/%m/%Y")
143
                    : $dt->strftime("%d/%m/%Y $time");
144
            }
145
            when (/^us/) {
146
                $dateonly
147
                    ? $dt->strftime("%m/%d/%Y")
148
                    : $dt->strftime("%m/%d/%Y $time");
149
            }
150
            default {
151
                $dateonly
152
                    ? $dt->strftime("%Y-%m-%d")
153
                    : $dt->strftime("%Y-%m-%d $time");
154
            }
132
155
133
    given ($pref) {
134
        when (/^iso/) {
135
            return $dateonly
136
                ? $dt->strftime("%Y-%m-%d")
137
                : $dt->strftime("%Y-%m-%d $time");
138
        }
139
        when (/^metric/) {
140
            return $dateonly
141
                ? $dt->strftime("%d/%m/%Y")
142
                : $dt->strftime("%d/%m/%Y $time");
143
        }
144
        when (/^us/) {
145
146
            return $dateonly
147
                ? $dt->strftime("%m/%d/%Y")
148
                : $dt->strftime("%m/%d/%Y $time");
149
        }
150
        default {
151
            return $dateonly
152
                ? $dt->strftime("%Y-%m-%d")
153
                : $dt->strftime("%Y-%m-%d $time");
154
        }
156
        }
157
    };
155
158
159
    if ( $as_due_date ) {
160
        $time_format eq '12hr'
161
            ? $date =~ s| 11:59 PM$||
162
            : $date =~ s| 23:59$||;
156
    }
163
    }
157
    return;
164
165
    return $date;
158
}
166
}
159
167
160
=head2 format_sqldatetime
168
=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