Bugzilla – Attachment 69726 Details for
Bug 18330
REST API: Date-time handling
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18330: Add RFC3339 to Koha::DateUtils
Bug-18330-Add-RFC3339-to-KohaDateUtils.patch (text/plain), 3.60 KB, created by
Benjamin Rokseth
on 2017-12-12 09:58:11 UTC
(
hide
)
Description:
Bug 18330: Add RFC3339 to Koha::DateUtils
Filename:
MIME Type:
Creator:
Benjamin Rokseth
Created:
2017-12-12 09:58:11 UTC
Size:
3.60 KB
patch
obsolete
>From 42c043448031994180798093c90caf7c97c44a81 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Fri, 24 Mar 2017 16:29:46 +0200 >Subject: [PATCH] Bug 18330: Add RFC3339 to Koha::DateUtils > >To test: >1. prove t/DateUtils.t > >Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no> >--- > Koha/DateUtils.pm | 20 ++++++++++++++++++++ > t/DateUtils.t | 12 +++++++++++- > 2 files changed, 31 insertions(+), 1 deletion(-) > >diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm >index af5ce7e..2b8ee8b 100644 >--- a/Koha/DateUtils.pm >+++ b/Koha/DateUtils.pm >@@ -104,6 +104,22 @@ sub dt_from_string { > (?<year>\d{4}) > |xms; > } >+ elsif ( $date_format eq 'rfc3339' ) { >+ $regex = qr/ >+ (?<year>\d{4}) >+ - >+ (?<month>\d{2}) >+ - >+ (?<day>\d{2}) >+ ([Tt\s]) >+ (?<hour>\d{2}) >+ : >+ (?<minute>\d{2}) >+ : >+ (?<second>\d{2}) >+ (([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9])) >+ /xms; >+ } > elsif ( $date_format eq 'iso' or $date_format eq 'sql' ) { > # iso or sql format are yyyy-dd-mm[ hh:mm:ss]" > $regex = $fallback_re; >@@ -237,6 +253,10 @@ sub output_pref { > ? $dt->strftime("%Y-%m-%d") > : $dt->strftime("%Y-%m-%d $time"); > } >+ elsif ( $pref =~ m/^rfc3339/ ) { >+ $date = $dt->strftime('%FT%T%z'); >+ substr($date, -2, 0, ':'); # timezone "HHmm" => "HH:mm" >+ } > elsif ( $pref =~ m/^metric/ ) { > $date = $dateonly > ? $dt->strftime("%d/%m/%Y") >diff --git a/t/DateUtils.t b/t/DateUtils.t >index 884990b..b0c8b05 100755 >--- a/t/DateUtils.t >+++ b/t/DateUtils.t >@@ -4,7 +4,7 @@ use DateTime::TimeZone; > > use C4::Context; > >-use Test::More tests => 63; >+use Test::More tests => 67; > > use Test::MockModule; > use Test::Warn; >@@ -46,6 +46,9 @@ cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output'; > $date_string = output_pref({ dt => $dt, dateformat => 'iso', timeformat => '12hr' }); > cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr'; > >+$date_string = output_pref({ dt => $dt, dateformat => 'rfc3339' }); >+like($date_string, qr/2011-06-16T12:00:00\+|-\d\d:\d\d/, 'RFC3339 output'); >+ > # "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 => $dt, dateformat => 'iso', timeformat => 'notime', dateonly => 1 }); >@@ -114,6 +117,11 @@ isa_ok( $dt0, 'DateTime', > 'dt_from_string returns a DateTime object passed a zero iso day' ); > cmp_ok( $dt0->ymd(), 'eq', $ymd, 'Returned object corrects iso day 0' ); > >+$dt0 = dt_from_string( '2012-01-00T12:00:00Z', 'rfc3339' ); >+isa_ok( $dt0, 'DateTime', >+ 'dt_from_string returns a DateTime object passed a zero rfc3339 day' ); >+cmp_ok( $dt0->ymd(), 'eq', $ymd, 'Returned object corrects rfc3339 day 0' ); >+ > # Return undef if passed mysql 0 dates > $dt0 = dt_from_string( '0000-00-00', 'iso' ); > is( $dt0, undef, "undefined returned for 0 iso date" ); >@@ -198,6 +206,8 @@ $dt = eval { dt_from_string( '31/01/2015', 'iso' ); }; > is( ref($dt), '', '31/01/2015 is not a correct date in iso format' ); > $dt = eval { dt_from_string( '01/01/2015', 'iso' ); }; > is( ref($dt), '', '01/01/2015 is not a correct date in iso format' ); >+$dt = eval { dt_from_string( '01/01/2015', 'rfc3339' ); }; >+is( ref($dt), '', '01/01/2015 is not a correct date in rfc3339 format' ); > $dt = eval { dt_from_string( '31/01/2015', 'us' ); }; > is( ref($dt), '', '31/01/2015 is not a correct date in us format' ); > $dt = dt_from_string( '01/01/2015', 'us' ); >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18330
:
63603
|
63604
|
63605
|
69726
|
69727
|
69749
|
69750
|
69751
|
69851