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 (and (> (length isodatetimestring) 15)
;; UTC specifier present
(char-equal ?Z (aref isodatetimestring 15)))
(setq source-zone t
;; decode to local time unless result-zone is explicitly given,
;; i.e. do not decode to UTC, i.e. do not (setq result-zone t)
))
;; 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))