Function: icalendar--diarytime-to-isotime

icalendar--diarytime-to-isotime is a byte-compiled function defined in icalendar.el.gz.

Signature

(icalendar--diarytime-to-isotime TIMESTRING AMPMSTRING)

Documentation

Convert a time like 9:30pm to an iso-conform string like T213000.

In this example the TIMESTRING would be "9:30" and the AMPMSTRING would be "pm". The minutes may be missing as long as the colon is missing as well, i.e. "9" is allowed as TIMESTRING and has the same result as "9:00".

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar.el.gz
(defun icalendar--diarytime-to-isotime (timestring ampmstring)
  "Convert a time like 9:30pm to an iso-conform string like T213000.
In this example the TIMESTRING would be \"9:30\" and the
AMPMSTRING would be \"pm\".  The minutes may be missing as long
as the colon is missing as well, i.e. \"9\" is allowed as
TIMESTRING and has the same result as \"9:00\"."
  (if timestring
      (let* ((parts (save-match-data (split-string timestring ":")))
             (h (car parts))
             (m (if (cdr parts) (cadr parts)
                  (if (> (length h) 2) "" "00")))
             (starttimenum (read (concat h m))))
        ;; take care of am/pm style
        ;; Be sure *not* to convert 12:00pm - 12:59pm to 2400-2459
        (if (and ampmstring (string= "pm" ampmstring) (< starttimenum 1200))
            (setq starttimenum (+ starttimenum 1200)))
	;; Similar effect with 12:00am - 12:59am (need to convert to 0000-0059)
        (if (and ampmstring (string= "am" ampmstring) (>= starttimenum 1200))
            (setq starttimenum (- starttimenum 1200)))
        (format "T%04d00" starttimenum))
    nil))