Bug 24643 - Koha::DateUtils::dt_from_string rfc3339 cannot handle high precision seconds
Summary: Koha::DateUtils::dt_from_string rfc3339 cannot handle high precision seconds
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Andrew Isherwood
QA Contact: Testopia
URL:
Keywords:
Depends on: 18330
Blocks: 24850
  Show dependency treegraph
 
Reported: 2020-02-12 16:02 UTC by Andrew Isherwood
Modified: 2021-01-27 10:45 UTC (History)
4 users (show)

See Also:
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


Attachments
Bug 24643: Support fractional seconds (954 bytes, patch)
2020-02-12 16:29 UTC, Andrew Isherwood
Details | Diff | Splinter Review
Add unit tests (1.45 KB, patch)
2020-02-12 16:29 UTC, Andrew Isherwood
Details | Diff | Splinter Review
Bug 24643: Add unit tests (1.46 KB, patch)
2020-02-12 16:30 UTC, Andrew Isherwood
Details | Diff | Splinter Review
Bug 24643: Support fractional seconds (1003 bytes, patch)
2020-02-12 21:58 UTC, David Nind
Details | Diff | Splinter Review
Bug 24643: Add unit tests (1.51 KB, patch)
2020-02-12 21:58 UTC, David Nind
Details | Diff | Splinter Review
Bug 24643: Support fractional seconds (1.05 KB, patch)
2020-02-13 13:25 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 24643: Add unit tests (1.52 KB, patch)
2020-02-13 13:25 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 24643: Add test to cover the timezone (1.53 KB, patch)
2020-02-13 13:25 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 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