Commit c6323320 authored by Lars Ingebrigtsen's avatar Lars Ingebrigtsen

Use decoded time math to be able to parse intervals

parent a74396af
Pipeline #2304 failed with stage
in 60 minutes and 48 seconds
......@@ -261,13 +261,16 @@ Return the number of minutes."
(t
(signal 'wrong-type-argument string))))
(unless end
(setq end (decode-time (time-add (encode-time start)
(encode-time duration))
(decoded-time-zone start))))
(setq end (decoded-time-add start duration)))
(unless start
(setq start (decode-time (time-subtract (encode-time end)
(encode-time duration))
(decoded-time-zone end))))
(setq start (decoded-time-add end
;; We negate the duration so that
;; we get a subtraction.
(mapcar (lambda (elem)
(if (numberp elem)
(- elem)
elem))
duration))))
(list start end
(or duration
(decode-time (time-subtract (encode-time end)
......
......@@ -386,7 +386,10 @@ decreased to be valid (\"add one month\" to January 31st will
yield a result of February 28th (or 29th, depending on the leap
year status).
Fields are added in a most to least significant order."
Fields are added in a most to least significant order.
When changing the time bits in TIME (i.e., second/minute/hour),
changes in daylight saving time are not taken into account."
(let ((time (copy-sequence time))
seconds)
;; Years are simple.
......@@ -399,7 +402,7 @@ Fields are added in a most to least significant order."
(setf (decoded-time-month time) (mod new 12))
(cl-incf (decoded-time-year time) (/ new 12))))
;; Adjust for month length.
;; Adjust for month length (as described in the doc string).
(setf (decoded-time-day time)
(min (date-days-in-month (decoded-time-year time)
(decoded-time-month time))
......@@ -427,6 +430,7 @@ Fields are added in a most to least significant order."
time))
(defun decoded-time--alter-month (time increase)
"Increase or decrease the month in TIME by 1."
(if increase
(progn
(cl-incf (decoded-time-month time))
......@@ -439,6 +443,7 @@ Fields are added in a most to least significant order."
(cl-decf (decoded-time-year time)))))
(defun decoded-time--alter-day (time increase)
"Increase or decrease the day in TIME by 1."
(if increase
(progn
(cl-incf (decoded-time-day time))
......@@ -455,6 +460,7 @@ Fields are added in a most to least significant order."
(decoded-time-month time))))))
(defun decoded-time--alter-second (time seconds increase)
"Increase or decrease the time in TIME by SECONDS."
(let ((old (+ (* (or (decoded-time-hour time) 0) 3600)
(* (or (decoded-time-minute time) 0) 60)
(or (decoded-time-second time) 0))))
......
......@@ -98,16 +98,12 @@
(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 "2007-03-01T13:00:00Z/P1Y2M10DT2H30M")
'((0 0 13 1 3 2007 nil nil 0)
(0 30 15 11 5 2008 nil 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 0 13 1 3 2007 nil nil 0)
(0 30 15 11 5 2008 nil nil 0)
(0 30 2 10 2 1 nil nil nil)))))
......
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