Bug 24643

Summary: Koha::DateUtils::dt_from_string rfc3339 cannot handle high precision seconds
Product: Koha Reporter: Andrew Isherwood <bugzilla>
Component: Architecture, internals, and plumbingAssignee: Andrew Isherwood <bugzilla>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: 1joynelson, jonathan.druart, lucas, martin.renvoize
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
20.05.00, 19.11.04, 19.05.09
Bug Depends on: 18330    
Bug Blocks: 24850    
Attachments: Bug 24643: Support fractional seconds
Add unit tests
Bug 24643: Add unit tests
Bug 24643: Support fractional seconds
Bug 24643: Add unit tests
Bug 24643: Support fractional seconds
Bug 24643: Add unit tests
Bug 24643: Add test to cover the timezone

Description Andrew Isherwood 2020-02-12 16:02:15 UTC
The RFC3339 spec (https://www.ietf.org/rfc/rfc3339.txt) says that the second component of a date/time can contain fractions of a second, e.g.

2011-10-05T14:48:00.000Z

This is the format returned by Javascript's toISOString() function. Unfortunately, when dt_from_string encounters a string in this format, it effectively drops the time component entirely and you end up with:

2011-10-05T00:00:00Z

The problem lies in the regex that attempts to match the string when dt_from_string is called with the 'rfc3339' parameter. Adding support for optional fractions is straightforward.
Comment 1 Andrew Isherwood 2020-02-12 16:29:31 UTC
Created attachment 98762 [details] [review]
Bug 24643: Support fractional seconds

This patch allows dt_from_string to handle RFC3339 strings containing
fractional seconds up to one thousandth of a second.

Test plan:

- Apply patch
- prove t/DateUtils.t
Comment 2 Andrew Isherwood 2020-02-12 16:29:34 UTC
Created attachment 98763 [details] [review]
Add unit tests
Comment 3 Andrew Isherwood 2020-02-12 16:30:47 UTC
Created attachment 98764 [details] [review]
Bug 24643: Add unit tests
Comment 4 David Nind 2020-02-12 21:58:43 UTC
Created attachment 98780 [details] [review]
Bug 24643: Support fractional seconds

This patch allows dt_from_string to handle RFC3339 strings containing
fractional seconds up to one thousandth of a second.

Test plan:

- Apply patch
- prove t/DateUtils.t

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 David Nind 2020-02-12 21:58:46 UTC
Created attachment 98781 [details] [review]
Bug 24643: Add unit tests

https://bugs.koha-community.org/show_bug.cgi?id=24643

Signed-off-by: David Nind <david@davidnind.com>
Comment 6 Jonathan Druart 2020-02-13 13:25:44 UTC
Created attachment 98825 [details] [review]
Bug 24643: Support fractional seconds

This patch allows dt_from_string to handle RFC3339 strings containing
fractional seconds up to one thousandth of a second.

Test plan:

- Apply patch
- prove t/DateUtils.t

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 7 Jonathan Druart 2020-02-13 13:25:47 UTC
Created attachment 98826 [details] [review]
Bug 24643: Add unit tests

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 8 Jonathan Druart 2020-02-13 13:25:50 UTC
Created attachment 98827 [details] [review]
Bug 24643: Add test to cover the timezone

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 9 Martin Renvoize 2020-02-13 16:02:07 UTC
Nice work everyone!

Pushed to master for 20.05
Comment 10 Joy Nelson 2020-03-05 01:03:22 UTC
Pushed to 19.11.x branch for 19.11.04
Comment 11 Lucas Gass 2020-03-09 20:11:38 UTC
backported to 19.05.x for 19.05.09