diff options
author | Bastien Guerry <bzg@altern.org> | 2011-07-24 18:32:51 +0200 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2011-07-24 18:32:51 +0200 |
commit | 9a6a1b6a0495da951e59cac16b5e669c8a17dd56 (patch) | |
tree | 30016a0ffcb30879c748ab28c43bd484870a3fc4 | |
parent | 9c5a8ab2958b63ca979883cb7389c2677fa203cb (diff) | |
download | org-mode-9a6a1b6a0495da951e59cac16b5e669c8a17dd56.tar.gz |
(org-table-time-string-to-seconds): also match negative time values.
-rw-r--r-- | lisp/org-table.el | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el index af1d884..7a24733 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -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." |