Function: erc--read-time-period

erc--read-time-period is a byte-compiled function defined in erc.el.gz.

Signature

(erc--read-time-period PROMPT)

Documentation

Read a time period on the "2h" format.

If there's no letter spec, the input is interpreted as a number of seconds.

If input is blank, this function returns nil. Otherwise it returns the time spec converted to a number of seconds.

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc--read-time-period (prompt)
  "Read a time period on the \"2h\" format.
If there's no letter spec, the input is interpreted as a number of seconds.

If input is blank, this function returns nil.  Otherwise it
returns the time spec converted to a number of seconds."
  (let ((period (string-trim
                 (read-string prompt nil 'erc--read-time-period-history))))
    (cond
     ;; Blank input.
     ((zerop (length period))
      nil)
     ;; All-number -- interpret as seconds.
     ((string-match-p "\\`[0-9]+\\'" period)
      (string-to-number period))
     ;; Parse as a time spec.
     (t
      (let ((time (condition-case nil
                      (iso8601-parse-duration
                       (concat (cond
                                ((string-match-p "\\`P" (upcase period))
                                 ;; Somebody typed in a full ISO8601 period.
                                 (upcase period))
                                ((string-match-p "[YD]" (upcase period))
                                 ;; If we have a year/day element,
                                 ;; we have a full spec.
                                 "P")
                                (t
                                 ;; Otherwise it's just a sub-day spec.
                                 "PT"))
                               (upcase period)))
                    (wrong-type-argument nil))))
        (unless time
          (user-error "%s is not a valid time period" period))
        (decoded-time-period time))))))