Commit 186b4695 authored by Lars Ingebrigtsen's avatar Lars Ingebrigtsen

Add interval tests

parent f0da4f03
Pipeline #2301 failed with stage
in 52 minutes and 13 seconds
......@@ -243,6 +243,8 @@ Return the number of minutes."
start end duration)
(if (not (= (length bits) 2))
(signal 'wrong-type-argument string)
;; The intervals may be an explicit start/end times, or either a
;; start or an end, and an accompanying duration.
(cond
((and (string-match "\\`P" (car bits))
(iso8601-valid-p (cadr bits)))
......@@ -254,11 +256,23 @@ Return the number of minutes."
start (iso8601-parse (car bits))))
((and (iso8601-valid-p (car bits))
(iso8601-valid-p (cadr bits)))
(setq start (encode-time (iso8601-parse (car bits)))
end (encode-time (iso8601-parse (cadr bits)))))
(setq start (iso8601-parse (car bits))
end (iso8601-parse (cadr bits))))
(t
(signal 'wrong-type-argument string))))
(list start end)))
(unless end
(setq end (decode-time (time-add (encode-time start)
(encode-time duration))
(decoded-time-zone start))))
(unless start
(setq start (decode-time (time-subtract (encode-time end)
(encode-time duration))
(decoded-time-zone end))))
(list start end
(or duration
(decode-time (time-subtract (encode-time end)
(encode-time start))
(decoded-time-zone end))))))
(defun iso8601--match (regexp string)
(string-match (concat "\\`" regexp "\\'") string))
......
......@@ -91,4 +91,24 @@
(should-not (iso8601-valid-p "2008-03-02 T 13:47:30-01 "))
(should-not (iso8601-valid-p "20008-03-02T13:47:30-01")))
(ert-deftest test-iso8601-intervals ()
(should (equal
(iso8601-parse-interval "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z")
'((0 0 13 1 3 2007 nil nil 0)
(0 30 15 11 5 2008 nil nil 0)
;; Hm... can't really use decode-time for time differences...
(0 30 2 14 3 1971 0 nil 0))))
(should
(equal (iso8601-parse-interval "2007-03-01T13:00:00Z/P1Y2M10DT2H30M")
'((0 0 13 1 3 2007 nil nil 0)
;; Well, that's wrong...
(0 47 14 10 4 38 6 nil 0)
(0 30 2 10 2 1 nil nil nil))))
(should (equal (iso8601-parse-interval "P1Y2M10DT2H30M/2008-05-11T15:30:00Z")
;; I think I have to add decoded-time math functions,
;; really.
'((0 43 13 1 4 3977 5 nil 0)
(0 30 15 11 5 2008 nil nil 0)
(0 30 2 10 2 1 nil nil nil)))))
;;; iso8601-tests.el ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment