summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2019-07-08 04:29:31 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2019-07-08 04:29:31 +0200
commita89c9a1b4d08b801ce5dee8dddfce2b684e182e6 (patch)
tree779f5220ba132bceff54644dbdd9a1edffa70fcb
parent04eb497b52b77b2ab553fd46abc1d5eaf462cb1f (diff)
downloademacs-a89c9a1b4d08b801ce5dee8dddfce2b684e182e6.tar.gz
Shuffle code around a bit
-rw-r--r--lisp/calendar/iso8601.el50
1 files changed, 26 insertions, 24 deletions
diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el
index 269f9a7e898..512ab4b093d 100644
--- a/lisp/calendar/iso8601.el
+++ b/lisp/calendar/iso8601.el
@@ -21,29 +21,10 @@
;;; Commentary:
-;;
-
;;; Code:
(require 'time-date)
-
-(defun iso8601--value (elem default)
- (if (stringp elem)
- (string-to-number elem)
- (or elem default)))
-
-(cl-defmethod 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)
- nil
- dst
- zone))
+(require 'cl-lib)
(defconst iso8601--year-match
"\\([-+]\\)?\\([0-9][0-9][0-9][0-9]\\)")
@@ -89,11 +70,13 @@ well as variants like \"2008W32\" (week number) and
(time-string (match-string 2 string))
(zone-string (match-string 3 string))
(date (iso8601-parse-date date-string)))
+ ;; The time portion is optional.
(when time-string
(let ((time (iso8601-parse-time time-string)))
(setf (decoded-time-hour date) (decoded-time-hour time))
(setf (decoded-time-minute date) (decoded-time-minute time))
(setf (decoded-time-second date) (decoded-time-second time))))
+ ;; The time zone is optional.
(when zone-string
(setf (decoded-time-zone date)
;; The time zone in decoded times are in seconds.
@@ -204,9 +187,6 @@ Return the number of minutes."
;; "Z".
0)))
-(defun iso8601--match (regexp string)
- (string-match (concat "\\`" regexp "\\'") string))
-
(defun iso8601-valid-p (string)
"Say whether STRING is a valid ISO 8601 representation."
(iso8601--match (concat "\\(" iso8601--date-match "\\)"
@@ -235,7 +215,8 @@ Return the number of minutes."
;; Does this make sense? Hm...
(iso8601--decoded-time :day (* weeks 7))))
;; P<date>T<time>
- ((string-match "\\`P[-0-9W]+T[:0-9]+\\'" string)
+ ((and (string-match "\\`P" string)
+ (iso8601-valid-p (substring string 1)))
(iso8601-parse (substring string 1)))
(t
(signal 'wrong-type-argument string))))
@@ -260,6 +241,27 @@ Return the number of minutes."
end (encode-time (iso8601-parse (cadr bits)))))))
(list start end)))
+(defun iso8601--match (regexp string)
+ (string-match (concat "\\`" regexp "\\'") string))
+
+(defun iso8601--value (elem default)
+ (if (stringp elem)
+ (string-to-number elem)
+ (or elem default)))
+
+(cl-defmethod 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)
+ nil
+ dst
+ zone))
+
(provide 'iso8601)
;;; iso8601.el ends here