Function: icalendar--decode-isodatetime

icalendar--decode-isodatetime is a byte-compiled function defined in icalendar.el.gz.

Signature

(icalendar--decode-isodatetime ISODATETIMESTRING &optional DAY-SHIFT SOURCE-ZONE RESULT-ZONE)

Documentation

Return ISODATETIMESTRING in format like decode-time.

Converts from ISO-8601 to Emacs representation. If ISODATETIMESTRING specifies UTC time (trailing letter Z) the
decoded time is given in the local time zone! If optional
parameter DAY-SHIFT is non-nil the result is shifted by DAY-SHIFT days. SOURCE-ZONE, if provided, is the timezone for decoding the time, in any format understood by encode-time. RESULT-ZONE, if provided, is the timezone for encoding the result in any format understood by decode-time. FIXME: multiple comma-separated values should be allowed!

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar.el.gz
(defun icalendar--decode-isodatetime (isodatetimestring &optional day-shift
                                                        source-zone
                                                        result-zone)
  "Return ISODATETIMESTRING in format like `decode-time'.
Converts from ISO-8601 to Emacs representation.  If
ISODATETIMESTRING specifies UTC time (trailing letter Z) the
decoded time is given in the local time zone!  If optional
parameter DAY-SHIFT is non-nil the result is shifted by DAY-SHIFT
days.
SOURCE-ZONE, if provided, is the timezone for decoding the time,
in any format understood by `encode-time'.
RESULT-ZONE, if provided, is the timezone for encoding the result
in any format understood by `decode-time'.
FIXME: multiple comma-separated values should be allowed!"
  (icalendar--dmsg isodatetimestring)
  (if isodatetimestring
      ;; day/month/year must be present
      (let ((year  (read (substring isodatetimestring 0 4)))
            (month (read (substring isodatetimestring 4 6)))
            (day   (read (substring isodatetimestring 6 8)))
            (hour 0)
            (minute 0)
            (second 0))
        (when (> (length isodatetimestring) 12)
          ;; hour/minute present
          (setq hour (read (substring isodatetimestring 9 11)))
          (setq minute (read (substring isodatetimestring 11 13))))
        (when (> (length isodatetimestring) 14)
          ;; seconds present
          (setq second (read (substring isodatetimestring 13 15))))
	;; FIXME: Support subseconds.
        (when (> (length isodatetimestring) 15)
	  (pcase (aref isodatetimestring 15)
            (?Z
             (setq source-zone t))
	    ((or ?- ?+)
             (setq source-zone
                   (concat "UTC" (substring isodatetimestring 15))))))
        ;; shift if necessary
        (if day-shift
            (let ((mdy (calendar-gregorian-from-absolute
                        (+ (calendar-absolute-from-gregorian
                            (list month day year))
                           day-shift))))
              (setq month (nth 0 mdy))
              (setq day   (nth 1 mdy))
              (setq year  (nth 2 mdy))))
        ;; create the decoded date-time
        ;; FIXME!?!
	(let ((decoded-time (list second minute hour day month year
				  nil -1 source-zone)))
	  (condition-case nil
	      (decode-time (encode-time decoded-time) result-zone)
	    (error
	     (message "Cannot decode \"%s\"" isodatetimestring)
	     ;; Hope for the best....
	     decoded-time))))
    ;; isodatetimestring == nil
    nil))