(org-table-time-string-to-seconds): also match negative time values.

This commit is contained in:
Bastien Guerry 2011-07-24 18:32:51 +02:00
parent 9c5a8ab295
commit 9a6a1b6a04
1 changed files with 16 additions and 10 deletions

View File

@ -3207,20 +3207,26 @@ For example: 28 -> AB."
(defun org-table-time-string-to-seconds (s)
"Convert a time string into numerical duration in seconds.
S is a string matching either HH:MM:SS or HH:MM."
S must be a string matching either -?HH:MM:SS or -?HH:MM."
(cond
((and (stringp s)
(string-match "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)" s))
(let ((hour (string-to-number (match-string 1 s)))
(min (string-to-number (match-string 2 s)))
(sec (string-to-number (match-string 3 s))))
(+ (* hour 3600) (* min 60) sec)))
(string-match "\\(-?\\)\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)" s))
(let ((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
(- (+ (* hour 3600) (* min 60) sec))
(+ (* hour 3600) (* min 60) sec))))
((and (stringp s)
(not (string-match org-ts-regexp-both s))
(string-match "\\([0-9]+\\):\\([0-9]+\\)" s))
(let ((hour (string-to-number (match-string 1 s)))
(min (string-to-number (match-string 2 s))))
(+ (* hour 3600) (* min 60))))))
(string-match "\\(-?\\)\\([0-9]+\\):\\([0-9]+\\)" s))
(let ((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
(- (+ (* hour 3600) (* min 60)))
(+ (* hour 3600) (* min 60)))))))
(defun org-table-time-seconds-to-string (secs)
"Convert a number of seconds to a time string."