From a89c9a1b4d08b801ce5dee8dddfce2b684e182e6 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 8 Jul 2019 04:29:31 +0200 Subject: Shuffle code around a bit --- lisp/calendar/iso8601.el | 50 +++++++++++++++++++++++++----------------------- 1 file 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)))) ;; PT