diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2016-07-21 11:49:15 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2016-07-21 11:49:15 +0200 |
commit | 47138a986ebeb0189962c732d47ea16e4922b5c1 (patch) | |
tree | ccee4001abbb2296b28ab46205075abf553f9259 | |
parent | 8fc25eb409c09d03cad7f36107bb571eba20d1ce (diff) | |
download | org-mode-47138a986ebeb0189962c732d47ea16e4922b5c1.tar.gz |
org-table: Fix calculations with locale specific time-stamps
* lisp/org-table.el (org-table-eval-formula): Fix calculations with
locale specific time-stamps.
* testing/lisp/test-org-table.el (test-org-table/time-stamps): New test.
Reported-by: "Ulrich J. Herter" <ujh@posteo.de>
<http://permalink.gmane.org/gmane.emacs.orgmode/108165>
-rw-r--r-- | lisp/org-table.el | 28 | ||||
-rw-r--r-- | testing/lisp/test-org-table.el | 19 |
2 files changed, 35 insertions, 12 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el index 6713f6f..3d59602 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -2847,18 +2847,22 @@ not overwrite the stored one. SUPPRESS-ANALYSIS prevents any call to (string-to-number ev) duration-output-format) ev)) - ;; Use <...> time-stamps so that Calc can handle them - (while (string-match (concat "\\[" org-ts-regexp1 "\\]") form) - (setq form (replace-match "<\\1>" nil nil form))) - ;; I18n-ize local time-stamps by setting (system-time-locale "C") - (when (string-match org-ts-regexp2 form) - (let* ((ts (match-string 0 form)) - (tsp (apply 'encode-time (save-match-data (org-parse-time-string ts)))) - (system-time-locale "C") - (tf (or (and (save-match-data (string-match "[0-9]\\{1,2\\}:[0-9]\\{2\\}" ts)) - (cdr org-time-stamp-formats)) - (car org-time-stamp-formats)))) - (setq form (replace-match (format-time-string tf tsp) t t form)))) + ;; Use <...> time-stamps so that Calc can handle them. + (setq form + (replace-regexp-in-string org-ts-regexp-inactive "<\\1>" form)) + ;; Internationalize local time-stamps by setting locale to + ;; "C". + (setq form + (replace-regexp-in-string + org-ts-regexp + (lambda (ts) + (let ((system-time-locale "C")) + (format-time-string + (org-time-stamp-format + (string-match-p "[0-9]\\{1,2\\}:[0-9]\\{2\\}" ts)) + (apply #'encode-time + (save-match-data (org-parse-time-string ts)))))) + form t t)) (setq ev (if (and duration (string-match "^[0-9]+:[0-9]+\\(?::[0-9]+\\)?$" form)) form diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 323212f..c036ece 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -1923,6 +1923,25 @@ is t, then new columns should be added as needed" (org-table-calc-current-TBLFM) (buffer-string))))) +(ert-deftest test-org-table/time-stamps () + "Test time-stamps handling." + ;; Standard test. + (should + (string-match-p + "| 1 |" + (org-test-with-temp-text + "| <2016-07-07 Sun> | <2016-07-08 Fri> | |\n<point>#+TBLFM: $3=$2-$1" + (org-table-calc-current-TBLFM) + (buffer-string)))) + ;; Handle locale specific time-stamps. + (should + (string-match-p + "| 1 |" + (org-test-with-temp-text + "| <2016-07-07 Do> | <2016-07-08 Fr> | |\n<point>#+TBLFM: $3=$2-$1" + (org-table-calc-current-TBLFM) + (buffer-string))))) + (ert-deftest test-org-table/orgtbl-ascii-draw () "Test `orgtbl-ascii-draw'." |