From 1af666c6b4325a28a0facaf6424b69ad64b7b254 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 29 Jul 2019 12:54:45 +0200 Subject: Add more tests from the standard --- lisp/calendar/iso8601.el | 8 ++-- test/lisp/calendar/iso8601-tests.el | 80 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el index 83b57a4f56a..f44ed3858f6 100644 --- a/lisp/calendar/iso8601.el +++ b/lisp/calendar/iso8601.el @@ -66,7 +66,7 @@ "\\([0-9][0-9]\\):?\\([0-9][0-9]\\)?:?\\([0-9][0-9]\\)?\\.?\\([0-9][0-9][0-9]\\)?") (defconst iso8601--zone-match - "\\(Z\\|\\([-+]\\)?\\([0-9][0-9]\\):?\\([0-9][0-9]\\)?\\)") + "\\(Z\\|\\([-+]\\)\\([0-9][0-9]\\):?\\([0-9][0-9]\\)?\\)") (defconst iso8601--full-time-match (concat "\\(" (replace-regexp-in-string "(" "(?:" iso8601--time-match) "\\)" @@ -76,8 +76,8 @@ (concat "\\(" iso8601--date-match "\\)" "\\(?:T\\(" (replace-regexp-in-string "(" "(?:" iso8601--time-match) - "\\)\\)?" - "\\(" iso8601--zone-match "\\)?")) + "\\)" + "\\(" iso8601--zone-match "\\)?\\)?")) (defconst iso8601--duration-full-match "P\\([0-9]+Y\\)?\\([0-9]+M\\)?\\([0-9]+D\\)?\\(T\\([0-9]+H\\)?\\([0-9]+M\\)?\\([0-9]+S\\)?\\)?") @@ -303,7 +303,7 @@ Return the number of minutes." (or duration (decode-time (time-subtract (iso8601--encode-time end) (iso8601--encode-time start)) - (decoded-time-zone end)))))) + (or (decoded-time-zone end) 0)))))) (defun iso8601--match (regexp string) (string-match (concat "\\`" regexp "\\'") string)) diff --git a/test/lisp/calendar/iso8601-tests.el b/test/lisp/calendar/iso8601-tests.el index 5403c8e2077..7b1dbfdf495 100644 --- a/test/lisp/calendar/iso8601-tests.el +++ b/test/lisp/calendar/iso8601-tests.el @@ -208,4 +208,84 @@ (should (equal (iso8601-parse-time "15:27:46-05") '(46 27 15 nil nil nil nil nil -300)))) +(ert-deftest standard-test-date-and-time-of-day () + (should (equal (iso8601-parse "19850412T101530") + '(30 15 10 12 4 1985 nil nil nil))) + (should (equal (iso8601-parse "1985-04-12T10:15:30") + '(30 15 10 12 4 1985 nil nil nil))) + + (should (equal (iso8601-parse "1985102T235030Z") + '(30 50 23 12 4 1985 nil nil 0))) + (should (equal (iso8601-parse "1985-102T23:50:30Z") + '(30 50 23 12 4 1985 nil nil 0))) + + (should (equal (iso8601-parse "1985W155T235030") + '(30 50 23 12 4 1985 nil nil nil))) + (should (equal (iso8601-parse "1985-W155T23:50:30") + '(30 50 23 12 4 1985 nil nil nil)))) + +(ert-deftest standard-test-interval () + ;; A time interval starting at 20 minutes and 50 seconds past 23 + ;; hours on 12 April 1985 and ending at 30 minutes past 10 hours on + ;; 25 June 1985. + (should (equal (iso8601-parse-interval "19850412T232050/19850625T103000") + '((50 20 23 12 4 1985 nil nil nil) + (0 30 10 25 6 1985 nil nil nil) + (10 9 11 15 3 1970 0 nil 0)))) + (should (equal (iso8601-parse-interval + "1985-04-12T23:20:50/1985-06-25T10:30:00") + '((50 20 23 12 4 1985 nil nil nil) + (0 30 10 25 6 1985 nil nil nil) + (10 9 11 15 3 1970 0 nil 0)))) + + ;; A time interval starting at 12 April 1985 and ending on 25 June + ;; 1985. + + ;; This example doesn't seem valid according to the standard. + ;; "0625" is unambiguous, and means "the year 625". Weird. + ;; (should (equal (iso8601-parse-interval "19850412/0625") + ;; '((nil nil nil 12 4 1985 nil nil nil) + ;; (nil nil nil nil nil 625 nil nil nil) + ;; (0 17 0 22 9 609 5 nil 0)))) + + ;; A time interval of 2 years, 10 months, 15 days, 10 hours, 20 + ;; minutes and 30 seconds. + (should (equal (iso8601-parse-duration "P2Y10M15DT10H20M30S") + '(30 20 10 15 10 2 nil nil nil))) + + (should (equal (iso8601-parse-duration "P00021015T102030") + '(30 20 10 15 10 2 nil nil nil))) + (should (equal (iso8601-parse-duration "P0002-10-15T10:20:30") + '(30 20 10 15 10 2 nil nil nil))) + + ;; A time interval of 1 year and 6 months. + (should (equal (iso8601-parse-duration "P1Y6M") + '(0 0 0 0 6 1 nil nil nil))) + (should (equal (iso8601-parse-duration "P0001-06") + '(nil nil nil nil 6 1 nil nil nil))) + + ;; A time interval of seventy-two hours. + (should (equal (iso8601-parse-duration "PT72H") + '(0 0 72 0 0 0 nil nil nil))) + + ;; Defined by start and duration + ;; A time interval of 1 year, 2 months, 15 days and 12 hours, + ;; beginning on 12 April 1985 at 20 minutes past 23 hours. + (should (equal (iso8601-parse-interval "19850412T232000/P1Y2M15DT12H") + '((0 20 23 12 4 1985 nil nil nil) + (0 20 11 28 6 1986 nil nil nil) + (0 0 12 15 2 1 nil nil nil)))) + (should (equal (iso8601-parse-interval "1985-04-12T23:20:00/P1Y2M15DT12H") + '((0 20 23 12 4 1985 nil nil nil) + (0 20 11 28 6 1986 nil nil nil) + (0 0 12 15 2 1 nil nil nil)))) + + ;; Defined by duration and end + ;; A time interval of 1 year, 2 months, 15 days and 12 hours, ending + ;; on 12 April 1985 at 20 minutes past 23 hour. + (should (equal (iso8601-parse-interval "P1Y2M15DT12H/19850412T232000") + '((0 20 11 28 1 1984 nil nil nil) + (0 20 23 12 4 1985 nil nil nil) + (0 0 12 15 2 1 nil nil nil))))) + ;;; iso8601-tests.el ends here -- cgit v1.2.1