Bug 18330 - REST API: Date-time handling
Summary: REST API: Date-time handling
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Lari Taskula
QA Contact: Tomás Cohen Arazi (tcohen)
URL:
Keywords:
: 18293 (view as bug list)
Depends on:
Blocks: 25621 16330 19816 24643
  Show dependency treegraph
 
Reported: 2017-03-24 12:09 UTC by Lari Taskula
Modified: 2020-05-29 09:26 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 18330: Add RFC3339 to Koha::DateUtils (3.53 KB, patch)
2017-05-22 09:04 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 18330: Handle date-time in Koha::Object->TO_JSON (3.43 KB, patch)
2017-05-22 09:04 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 18330: (follow-up) Add note to update tests when upgrading Mojolicious (1.41 KB, patch)
2017-05-22 09:04 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 18330: Add RFC3339 to Koha::DateUtils (3.60 KB, patch)
2017-12-12 09:58 UTC, Benjamin Rokseth
Details | Diff | Splinter Review
Bug 18330: Handle date-time in Koha::Object->TO_JSON (3.50 KB, patch)
2017-12-12 09:58 UTC, Benjamin Rokseth
Details | Diff | Splinter Review
Bug 18330: Add RFC3339 to Koha::DateUtils (3.66 KB, patch)
2017-12-12 21:24 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 18330: Handle date-time in Koha::Object->TO_JSON (3.57 KB, patch)
2017-12-12 21:24 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 18330: (follow-up) Adapt holds.t to match the new datetime format (2.67 KB, patch)
2017-12-12 21:36 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 18330: Do not return undef explicitely (1.00 KB, patch)
2017-12-18 15:13 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lari Taskula 2017-03-24 12:09:19 UTC
Swagger2 wants dates and date-times as defined in RFC3339, https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14

Make sure each object property has a format date or date-time defined where needed.

We should include information on time zone and use an appropriate separator "T" between date and time, e.g.:
2017-03-24T14:00:00+02:00
2017-03-24T12:00:00Z
Comment 1 Lari Taskula 2017-05-22 09:04:14 UTC
Created attachment 63603 [details] [review]
Bug 18330: Add RFC3339 to Koha::DateUtils

To test:
1. prove t/DateUtils.t
Comment 2 Lari Taskula 2017-05-22 09:04:28 UTC
Created attachment 63604 [details] [review]
Bug 18330: Handle date-time in Koha::Object->TO_JSON

This patch formats timestamps and datetimes to meet date-time definition
in RFC3339, as required by Swagger documentation.
Comment 3 Lari Taskula 2017-05-22 09:04:38 UTC Comment hidden (obsolete)
Comment 4 Lari Taskula 2017-08-24 11:00:10 UTC
(In reply to Lari Taskula from comment #3)
> Created attachment 63605 [details] [review] [review]
> Bug 18330: (follow-up) Add note to update tests when upgrading Mojolicious
> 
> I noticed this test file is broken with Mojolicious 7. It is because they
> have replaced Mojo::JSON::_Bool with JSON::PP::Boolean. This patch adds
> TODO comment to easily identify the issue when updating.

Marked this patch obsolete as it is fixed in Bug 18290.
Comment 5 Benjamin Rokseth 2017-12-12 09:58:11 UTC
Created attachment 69726 [details] [review]
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>
Comment 6 Benjamin Rokseth 2017-12-12 09:58:18 UTC
Created attachment 69727 [details] [review]
Bug 18330: Handle date-time in Koha::Object->TO_JSON

This patch formats timestamps and datetimes to meet date-time definition
in RFC3339, as required by Swagger documentation.

Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>
Comment 7 Benjamin Rokseth 2017-12-12 09:59:19 UTC
All tests pass. Good work!
Comment 8 Tomás Cohen Arazi (tcohen) 2017-12-12 21:24:08 UTC
Created attachment 69749 [details] [review]
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>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 9 Tomás Cohen Arazi (tcohen) 2017-12-12 21:24:19 UTC
Created attachment 69750 [details] [review]
Bug 18330: Handle date-time in Koha::Object->TO_JSON

This patch formats timestamps and datetimes to meet date-time definition
in RFC3339, as required by Swagger documentation.

Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 10 Tomás Cohen Arazi (tcohen) 2017-12-12 21:36:21 UTC
Created attachment 69751 [details] [review]
Bug 18330: (follow-up) Adapt holds.t to match the new datetime format

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 11 Jonathan Druart 2017-12-13 12:38:23 UTC
What do we do if output_pref is called with dateformat => rfc3339 and dateonly => 1?
Comment 12 Tomás Cohen Arazi (tcohen) 2017-12-13 16:58:57 UTC
(In reply to Jonathan Druart from comment #11)
> What do we do if output_pref is called with dateformat => rfc3339 and
> dateonly => 1?

Raise an exception because RFC doesn't cover that use case?
Comment 13 Jonathan Druart 2017-12-14 20:16:49 UTC
Pushed to master for 18.05, thanks to everybody involved!
Comment 14 Jonathan Druart 2017-12-14 20:59:00 UTC
#   Failed test 'Test::Perl::Critic for "Koha/Object.pm"'
#   at /usr/share/perl5/Test/Perl/Critic.pm line 110.
# 
# Perl::Critic found these violations in "Koha/Object.pm":
# "return" statement with explicit "undef" at line 227, column 17.  See page 199 of PBP.  (Severity: 5)
# Looks like you failed 1 test of 854.
[20:13:10] t/00-testcritic.t 

I let you deal with that one.
Comment 15 Jonathan Druart 2017-12-18 15:13:48 UTC
Created attachment 69851 [details] [review]
Bug 18330: Do not return undef explicitely

This patch fixes a perl critic issue, hopefully it will not break
something else.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 16 Jonathan Druart 2017-12-18 15:19:35 UTC
Last patch has been pushed to master.
Comment 17 Nick Clemens (kidclamp) 2017-12-20 11:51:25 UTC
Awesome work all! Enhancement, not backporting for 17.11
Comment 18 Tomás Cohen Arazi (tcohen) 2020-01-13 11:50:08 UTC
*** Bug 18293 has been marked as a duplicate of this bug. ***
Comment 19 Jonathan Druart 2020-05-29 09:26:00 UTC
This implementation is not correct, the timezone from the string should be taken into account (and UTC used if not provided).

See bug 25621