emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/iso8601 04eb497 1/2: Add more doc


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] scratch/iso8601 04eb497 1/2: Add more doc
Date: Sun, 7 Jul 2019 22:29:43 -0400 (EDT)

branch: scratch/iso8601
commit 04eb497b52b77b2ab553fd46abc1d5eaf462cb1f
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Add more doc
---
 lisp/calendar/iso8601.el | 50 ++++++++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el
index 3341659..269f9a7 100644
--- a/lisp/calendar/iso8601.el
+++ b/lisp/calendar/iso8601.el
@@ -76,6 +76,30 @@
 (defconst iso8601--zone-match
   "\\(Z\\|\\([-+]\\)?\\([0-9][0-9]\\):?\\([0-9][0-9]\\)?\\)")
 
+(defun iso8601-parse (string)
+  "Parse an ISO 8601 date/time string and return a `decoded-time' structure.
+
+The ISO 8601 date/time strings look like \"2008-03-02T13:47:30\",
+but shorter, incomplete strings like \"2008-03-02\" are valid, as
+well as variants like \"2008W32\" (week number) and
+\"2008-234\" (ordinal day number)."
+  (if (not (iso8601-valid-p string))
+      (signal 'wrong-type-argument string)
+    (let* ((date-string (match-string 1 string))
+           (time-string (match-string 2 string))
+           (zone-string (match-string 3 string))
+           (date (iso8601-parse-date date-string)))
+      (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))))
+      (when zone-string
+        (setf (decoded-time-zone date)
+              ;; The time zone in decoded times are in seconds.
+              (* (iso8601-parse-zone zone-string) 60)))
+      date)))
+
 (defun iso8601-parse-date (string)
   "Parse STRING (which should be on ISO 8601 format) and return a time value."
   (cond
@@ -193,25 +217,6 @@ Return the number of minutes."
                           "\\(" iso8601--zone-match "\\)?")
                   string))
 
-(defun iso8601-parse (string)
-  "Parse an ISO 8601 date/time string."
-  (if (not (iso8601-valid-p string))
-      (signal 'wrong-type-argument string)
-    (let* ((date-string (match-string 1 string))
-           (time-string (match-string 2 string))
-           (zone-string (match-string 3 string))
-           (date (iso8601-parse-date date-string)))
-      (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))))
-      (when zone-string
-        (setf (decoded-time-zone date)
-              ;; The time zone in decoded times are in seconds.
-              (* (iso8601-parse-zone zone-string) 60)))
-      date)))
-
 (defun iso8601-parse-duration (string)
   "Parse ISO 8601 durations on the form P3Y6M4DT12H30M5S."
   (cond
@@ -231,13 +236,16 @@ Return the number of minutes."
       (iso8601--decoded-time :day (* weeks 7))))
    ;; P<date>T<time>
    ((string-match "\\`P[-0-9W]+T[:0-9]+\\'" string)
-    (iso8601-parse (substring string 1)))))
+    (iso8601-parse (substring string 1)))
+   (t
+    (signal 'wrong-type-argument string))))
 
 (defun iso8601-parse-interval (string)
   "Parse ISO 8601 intervals."
   (let ((bits (split-string string "/"))
         start end duration)
-    (when (= (length bits) 2)
+    (if (not (= (length bits) 2))
+        (signal 'wrong-type-argument string)
       (cond
        ((string-match "\\`P" (car bits))
         (setq duration (iso8601-parse-duration (car bits))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]