Function: org-table-time-string-to-seconds

org-table-time-string-to-seconds is a byte-compiled function defined in org-table.el.gz.

Signature

(org-table-time-string-to-seconds S)

Documentation

Convert a time string into numerical duration in seconds.

S can be a string matching either -?HH:MM:SS or -?HH:MM. If S is a string representing a number, keep this number.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
(defun org-table-time-string-to-seconds (s)
  "Convert a time string into numerical duration in seconds.
S can be a string matching either -?HH:MM:SS or -?HH:MM.
If S is a string representing a number, keep this number."
  (if (equal s "")
      s
    (let (hour minus min sec res)
      (cond
       ((and (string-match "\\(-?\\)\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)" s))
	(setq minus (< 0 (length (match-string 1 s)))
	      hour (string-to-number (match-string 2 s))
	      min (string-to-number (match-string 3 s))
	      sec (string-to-number (match-string 4 s)))
	(if minus
	    (setq res (- (+ (* hour 3600) (* min 60) sec)))
	  (setq res (+ (* hour 3600) (* min 60) sec))))
       ((and (not (string-match org-ts-regexp-both s))
	     (string-match "\\(-?\\)\\([0-9]+\\):\\([0-9]+\\)" s))
	(setq minus (< 0 (length (match-string 1 s)))
	      hour (string-to-number (match-string 2 s))
	      min (string-to-number (match-string 3 s)))
	(if minus
	    (setq res (- (+ (* hour 3600) (* min 60))))
	  (setq res (+ (* hour 3600) (* min 60)))))
       (t (setq res (string-to-number s))))
      (number-to-string res))))