Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate comma in seconds when rfc3339 parsing #91

Merged
merged 1 commit into from May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/local-time.lisp
Expand Up @@ -1415,6 +1415,7 @@ The value of this variable should have the methods `local-time::clock-now', and
(fail-on-error t) (time-separator #\:)
(date-separator #\-)
(date-time-separator #\T)
(fract-time-separators '(#\. #\,))
(allow-missing-elements t)
(allow-missing-date-part allow-missing-elements)
(allow-missing-time-part allow-missing-elements)
Expand Down Expand Up @@ -1552,7 +1553,7 @@ The value of this variable should have the methods `local-time::clock-now', and
(time-minute (start-end)
(parse-integer-into start-end minute 0 59))
(time-second (start-end)
(with-parts-and-count ((car start-end) (cdr start-end) '(#\. #\,))
(with-parts-and-count ((car start-end) (cdr start-end) fract-time-separators)
(passert (<= 1 count 2))
(let ((*read-eval* nil))
(parse-integer-into (first parts) second 0 59)
Expand Down Expand Up @@ -1615,7 +1616,8 @@ The value of this variable should have the methods `local-time::clock-now', and
(parse-timestring timestring :fail-on-error fail-on-error
:allow-missing-timezone-part nil
:allow-missing-time-part allow-missing-time-part
:allow-missing-date-part nil))
:allow-missing-date-part nil
:fract-time-separators #\.))

(defun parse-timestring (timestring &key
start
Expand All @@ -1624,6 +1626,7 @@ The value of this variable should have the methods `local-time::clock-now', and
(time-separator #\:)
(date-separator #\-)
(date-time-separator #\T)
(fract-time-separators '(#\. #\,))
(allow-missing-elements t)
(allow-missing-date-part allow-missing-elements)
(allow-missing-time-part allow-missing-elements)
Expand All @@ -1641,6 +1644,7 @@ in the input string."
:time-separator time-separator
:date-separator date-separator
:date-time-separator date-time-separator
:fract-time-separators fract-time-separators
:allow-missing-elements allow-missing-elements
:allow-missing-date-part allow-missing-date-part
:allow-missing-time-part allow-missing-time-part
Expand Down
7 changes: 7 additions & 0 deletions test/parsing.lisp
Expand Up @@ -79,3 +79,10 @@

(deftest test/parsing/error ()
(signals invalid-timestring (parse-timestring "2019-w2-20")))

(deftest test/parsing/parse-rfc3339 ()
(let ((local-time:*default-timezone* local-time:+utc-zone+))
(is (equal (multiple-value-list (decode-timestamp (local-time::parse-rfc3339-timestring "2006-01-02T03:04:05.6-05")))
'(600000000 5 4 8 2 1 2006 1 NIL 0 "UTC")))
;; rfc3339 only supports . for fractional seconds
(signals local-time::invalid-timestring (local-time::parse-rfc3339-timestring "2006-01-02T03:04:05,6-05"))))