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

(-)a/Koha/DateUtils.pm (+20 lines)
Lines 104-109 sub dt_from_string { Link Here
104
            (?<year>\d{4})
104
            (?<year>\d{4})
105
        |xms;
105
        |xms;
106
    }
106
    }
107
    elsif ( $date_format eq 'rfc3339' ) {
108
        $regex = qr/
109
            (?<year>\d{4})
110
            -
111
            (?<month>\d{2})
112
            -
113
            (?<day>\d{2})
114
            ([Tt\s])
115
            (?<hour>\d{2})
116
            :
117
            (?<minute>\d{2})
118
            :
119
            (?<second>\d{2})
120
            (([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))
121
        /xms;
122
    }
107
    elsif ( $date_format eq 'iso' or $date_format eq 'sql' ) {
123
    elsif ( $date_format eq 'iso' or $date_format eq 'sql' ) {
108
        # iso or sql format are yyyy-dd-mm[ hh:mm:ss]"
124
        # iso or sql format are yyyy-dd-mm[ hh:mm:ss]"
109
        $regex = $fallback_re;
125
        $regex = $fallback_re;
Lines 237-242 sub output_pref { Link Here
237
          ? $dt->strftime("%Y-%m-%d")
253
          ? $dt->strftime("%Y-%m-%d")
238
          : $dt->strftime("%Y-%m-%d $time");
254
          : $dt->strftime("%Y-%m-%d $time");
239
    }
255
    }
256
    elsif ( $pref =~ m/^rfc3339/ ) {
257
        $date = $dt->strftime('%FT%T%z');
258
        substr($date, -2, 0, ':'); # timezone "HHmm" => "HH:mm"
259
    }
240
    elsif ( $pref =~ m/^metric/ ) {
260
    elsif ( $pref =~ m/^metric/ ) {
241
        $date = $dateonly
261
        $date = $dateonly
242
          ? $dt->strftime("%d/%m/%Y")
262
          ? $dt->strftime("%d/%m/%Y")
(-)a/t/DateUtils.t (-2 / +11 lines)
Lines 4-10 use DateTime::TimeZone; Link Here
4
4
5
use C4::Context;
5
use C4::Context;
6
6
7
use Test::More tests => 63;
7
use Test::More tests => 67;
8
8
9
use Test::MockModule;
9
use Test::MockModule;
10
use Test::Warn;
10
use Test::Warn;
Lines 46-51 cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output'; Link Here
46
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '12hr' });
46
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '12hr' });
47
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr';
47
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr';
48
48
49
$date_string = output_pref({ dt => $dt, dateformat => 'rfc3339' });
50
like($date_string, qr/2011-06-16T12:00:00\+|-\d\d:\d\d/, 'RFC3339 output');
51
49
# "notime" doesn't actually mean anything in this context, but we
52
# "notime" doesn't actually mean anything in this context, but we
50
# can't pass undef or output_pref will try to access the database
53
# can't pass undef or output_pref will try to access the database
51
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => 'notime', dateonly => 1 });
54
$date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => 'notime', dateonly => 1 });
Lines 114-119 isa_ok( $dt0, 'DateTime', Link Here
114
    'dt_from_string returns a DateTime object passed a zero iso day' );
117
    'dt_from_string returns a DateTime object passed a zero iso day' );
115
cmp_ok( $dt0->ymd(), 'eq', $ymd, 'Returned object corrects iso day 0' );
118
cmp_ok( $dt0->ymd(), 'eq', $ymd, 'Returned object corrects iso day 0' );
116
119
120
$dt0 = dt_from_string( '2012-01-00T12:00:00Z', 'rfc3339' );
121
isa_ok( $dt0, 'DateTime',
122
    'dt_from_string returns a DateTime object passed a zero rfc3339 day' );
123
cmp_ok( $dt0->ymd(), 'eq', $ymd, 'Returned object corrects rfc3339 day 0' );
124
117
# Return undef if passed mysql 0 dates
125
# Return undef if passed mysql 0 dates
118
$dt0 = dt_from_string( '0000-00-00', 'iso' );
126
$dt0 = dt_from_string( '0000-00-00', 'iso' );
119
is( $dt0, undef, "undefined returned for 0 iso date" );
127
is( $dt0, undef, "undefined returned for 0 iso date" );
Lines 198-203 $dt = eval { dt_from_string( '31/01/2015', 'iso' ); }; Link Here
198
is( ref($dt), '', '31/01/2015 is not a correct date in iso format' );
206
is( ref($dt), '', '31/01/2015 is not a correct date in iso format' );
199
$dt = eval { dt_from_string( '01/01/2015', 'iso' ); };
207
$dt = eval { dt_from_string( '01/01/2015', 'iso' ); };
200
is( ref($dt), '', '01/01/2015 is not a correct date in iso format' );
208
is( ref($dt), '', '01/01/2015 is not a correct date in iso format' );
209
$dt = eval { dt_from_string( '01/01/2015', 'rfc3339' ); };
210
is( ref($dt), '', '01/01/2015 is not a correct date in rfc3339 format' );
201
$dt = eval { dt_from_string( '31/01/2015', 'us' ); };
211
$dt = eval { dt_from_string( '31/01/2015', 'us' ); };
202
is( ref($dt), '', '31/01/2015 is not a correct date in us format' );
212
is( ref($dt), '', '31/01/2015 is not a correct date in us format' );
203
$dt = dt_from_string( '01/01/2015', 'us' );
213
$dt = dt_from_string( '01/01/2015', 'us' );
204
- 

Return to bug 18330