summaryrefslogtreecommitdiff
path: root/lisp/calendar/iso8601.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/calendar/iso8601.el')
-rw-r--r--lisp/calendar/iso8601.el38
1 files changed, 28 insertions, 10 deletions
diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el
index 67c39a0d980..5952586cc86 100644
--- a/lisp/calendar/iso8601.el
+++ b/lisp/calendar/iso8601.el
@@ -148,7 +148,7 @@ well as variants like \"2008W32\" (week number) and
(string-to-number (match-string 4 string))))
(jan-start (decoded-time-weekday
(decode-time
- (encode-time
+ (iso8601--encode-time
(iso8601--decoded-time :year year
:month 1
:day 4)))))
@@ -291,14 +291,14 @@ Return the number of minutes."
duration))))
(list start end
(or duration
- (decode-time (time-subtract (encode-time end)
- (encode-time start))
+ (decode-time (time-subtract (iso8601--encode-time end)
+ (iso8601--encode-time start))
(decoded-time-zone end))))))
(defun iso8601--match (regexp string)
(string-match (concat "\\`" regexp "\\'") string))
-(defun iso8601--value (elem default)
+(defun iso8601--value (elem &optional default)
(if (stringp elem)
(string-to-number elem)
(or elem default)))
@@ -306,16 +306,34 @@ Return the number of minutes."
(cl-defun iso8601--decoded-time (&key second minute hour
day month year
dst zone)
- (list (iso8601--value second 0)
- (iso8601--value minute 0)
- (iso8601--value hour 0)
- (iso8601--value day 1)
- (iso8601--value month 1)
- (iso8601--value year 0)
+ (list (iso8601--value second)
+ (iso8601--value minute)
+ (iso8601--value hour)
+ (iso8601--value day)
+ (iso8601--value month)
+ (iso8601--value year)
nil
dst
zone))
+(defun iso8601--encode-time (time)
+ "Like `encode-time', but fill in nil values in TIME."
+ (setq time (copy-sequence time))
+ (unless (decoded-time-second time)
+ (setf (decoded-time-second time) 0))
+ (unless (decoded-time-minute time)
+ (setf (decoded-time-minute time) 0))
+ (unless (decoded-time-hour time)
+ (setf (decoded-time-hour time) 0))
+
+ (unless (decoded-time-day time)
+ (setf (decoded-time-day time) 1))
+ (unless (decoded-time-month time)
+ (setf (decoded-time-month time) 1))
+ (unless (decoded-time-year time)
+ (setf (decoded-time-year time) 0))
+ (encode-time time))
+
(provide 'iso8601)
;;; iso8601.el ends here