org-table: Fix sorting with times > 100 hours

* lisp/org-table.el (org-table-sort-lines): Fix regexp.  Also test
  durations.

* testing/lisp/test-org-table.el (test-org-table/sort-lines): Update
  tests.  Add a new one.
This commit is contained in:
Nicolas Goaziou 2017-08-25 00:04:28 +02:00
parent b47de25062
commit bae41a277e
2 changed files with 12 additions and 5 deletions

View File

@ -1740,7 +1740,8 @@ function is being called interactively."
(cond ((string-match org-ts-regexp-both f)
(float-time
(org-time-string-to-time (match-string 0 f))))
((string-match "[0-9]\\{1,2\\}:[0-9]\\{2\\}" f)
((org-duration-p f) (org-duration-to-minutes f))
((string-match "\\<[0-9]+:[0-9]\\{2\\}\\>" f)
(org-duration-to-minutes (match-string 0 f)))
(t 0))))
((?f ?F)

View File

@ -1668,15 +1668,21 @@ See also `test-org-table/copy-field'."
(buffer-string))))
;; Sort by time (HH:MM values)
(should
(equal "| 1:00 |\n| 14:00 |\n| 17:00 |\n"
(org-test-with-temp-text "| 14:00 |\n| 17:00 |\n| 1:00 |\n"
(equal "| 1:00 |\n| 17:00 |\n| 114:00 |\n"
(org-test-with-temp-text "| 114:00 |\n| 17:00 |\n| 1:00 |\n"
(org-table-sort-lines nil ?t)
(buffer-string))))
(should
(equal "| 17:00 |\n| 14:00 |\n| 1:00 |\n"
(org-test-with-temp-text "| 14:00 |\n| 17:00 |\n| 1:00 |\n"
(equal "| 114:00 |\n| 17:00 |\n| 1:00 |\n"
(org-test-with-temp-text "| 114:00 |\n| 17:00 |\n| 1:00 |\n"
(org-table-sort-lines nil ?T)
(buffer-string))))
;; Sort by time (durations)
(should
(equal "| 1d 3:00 |\n| 28:00 |\n"
(org-test-with-temp-text "| 28:00 |\n| 1d 3:00 |\n"
(org-table-sort-lines nil ?t)
(buffer-string))))
;; Sort with custom functions.
(should
(equal "| 22 |\n| 15 |\n| 18 |\n"