Function: org-icalendar-convert-timestamp

org-icalendar-convert-timestamp is a byte-compiled function defined in ox-icalendar.el.gz.

Signature

(org-icalendar-convert-timestamp TIMESTAMP KEYWORD &optional END TZ)

Documentation

Convert TIMESTAMP to iCalendar format.

TIMESTAMP is a timestamp object. KEYWORD is added in front of it, in order to make a complete line (e.g. "DTSTART").

When optional argument END is non-nil, use end of time range. Also increase the hour by two (if time string contains a time), or the day by one (if it does not contain a time) when no explicit ending time is specified.

When optional argument TZ is non-nil, timezone data time will be added to the timestamp. It can be the string "UTC", to use UTC time, or a string in the IANA TZ database format (e.g. "Europe/London"). In either case, the value of org-icalendar-date-time-format will be ignored.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-icalendar.el.gz
(defun org-icalendar-convert-timestamp (timestamp keyword &optional end tz)
  "Convert TIMESTAMP to iCalendar format.

TIMESTAMP is a timestamp object.  KEYWORD is added in front of
it, in order to make a complete line (e.g. \"DTSTART\").

When optional argument END is non-nil, use end of time range.
Also increase the hour by two (if time string contains a time),
or the day by one (if it does not contain a time) when no
explicit ending time is specified.

When optional argument TZ is non-nil, timezone data time will be
added to the timestamp.  It can be the string \"UTC\", to use UTC
time, or a string in the IANA TZ database
format (e.g. \"Europe/London\").  In either case, the value of
`org-icalendar-date-time-format' will be ignored."
  (let* ((year-start (org-element-property :year-start timestamp))
	 (year-end (org-element-property :year-end timestamp))
	 (month-start (org-element-property :month-start timestamp))
	 (month-end (org-element-property :month-end timestamp))
	 (day-start (org-element-property :day-start timestamp))
	 (day-end (org-element-property :day-end timestamp))
	 (hour-start (org-element-property :hour-start timestamp))
	 (hour-end (org-element-property :hour-end timestamp))
	 (minute-start (org-element-property :minute-start timestamp))
	 (minute-end (org-element-property :minute-end timestamp))
	 (with-time-p minute-start)
	 (equal-bounds-p
	  (equal (list year-start month-start day-start hour-start minute-start)
		 (list year-end month-end day-end hour-end minute-end)))
	 (mi (cond ((not with-time-p) 0)
		   ((not end) minute-start)
		   ((and org-agenda-default-appointment-duration equal-bounds-p)
		    (+ minute-end org-agenda-default-appointment-duration))
		   (t minute-end)))
	 (h (cond ((not with-time-p) 0)
		  ((not end) hour-start)
		  ((or (not equal-bounds-p)
		       org-agenda-default-appointment-duration)
		   hour-end)
		  (t (+ hour-end 2))))
	 (d (cond ((not end) day-start)
		  ((not with-time-p) (1+ day-end))
		  (t day-end)))
	 (m (if end month-end month-start))
	 (y (if end year-end year-start)))
    (concat
     keyword
     (format-time-string
      (cond ((string-equal tz "UTC") ":%Y%m%dT%H%M%SZ")
	    ((not with-time-p) ";VALUE=DATE:%Y%m%d")
	    ((stringp tz) (concat ";TZID=" tz ":%Y%m%dT%H%M%S"))
	    (t (replace-regexp-in-string "%Z"
					 org-icalendar-timezone
					 org-icalendar-date-time-format
					 t)))
      ;; Convert timestamp into internal time in order to use
      ;; `format-time-string' and fix any mistake (i.e. MI >= 60).
      (org-encode-time 0 mi h d m y)
      (and (or (string-equal tz "UTC")
	       (and (null tz)
		    with-time-p
		    (org-icalendar-use-UTC-date-time-p)))
	   t)))))