diff options
author | Bastien Guerry <bzg@altern.org> | 2012-05-05 16:14:33 +0200 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2012-05-05 16:14:33 +0200 |
commit | 8fb20b7f93269a1b3c6de7d53bca6317436ba338 (patch) | |
tree | 040c048d04b467b2e43b90cbd43dfe3d369e652f | |
parent | 73ec7674583518b2f8aacedda64325dfe5ba490f (diff) | |
download | org-mode-8fb20b7f93269a1b3c6de7d53bca6317436ba338.tar.gz |
org-table.el: handle =02:34;t durations formula correctly.
* org-table.el (org-table-time-string-to-seconds): Return the
empty string if provided.
(org-table-eval-formula): When assigning a duration string,
handle it correctly -- i.e. don't make any computation on it,
except the one to insert it using the correct duration format.
Thanks to Sébastien Vauban for spotting this.
-rw-r--r-- | lisp/org-table.el | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el index c2fdf96..714ea45 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -2590,10 +2590,15 @@ not overwrite the stored one." duration-output-format) ev)) (or (fboundp 'calc-eval) (error "Calc does not seem to be installed, and is needed to evaluate the formula")) - (setq ev (calc-eval (cons form org-tbl-calc-modes) (if numbers 'num)) + (setq ev (if (and duration (string-match "^[0-9]+:[0-9]+\\(?::[0-9]+\\)?$" form)) + form + (calc-eval (cons form org-tbl-calc-modes) (if numbers 'num))) ev (if duration (org-table-time-seconds-to-string - (string-to-number ev) - duration-output-format) ev))) + (if (string-match "^[0-9]+:[0-9]+\\(?::[0-9]+\\)?$" ev) + (string-to-number (org-table-time-string-to-seconds ev)) + (string-to-number ev)) + duration-output-format) + ev))) (when org-table-formula-debug (with-output-to-temp-buffer "*Substitution History*" @@ -3288,8 +3293,10 @@ For example: 28 -> AB." "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." - (let (hour minus min sec res) - (cond + (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)) @@ -3307,7 +3314,7 @@ If S is a string representing a number, keep this number." (setq res (- (+ (* hour 3600) (* min 60)))) (setq res (+ (* hour 3600) (* min 60))))) (t (setq res (string-to-number s)))) - (number-to-string res))) + (number-to-string res)))) (defun org-table-time-seconds-to-string (secs &optional output-format) "Convert a number of seconds to a time string. |