瀏覽代碼

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.
Nicolas Goaziou 7 年之前
父節點
當前提交
bae41a277e
共有 2 個文件被更改,包括 12 次插入5 次删除
  1. 2 1
      lisp/org-table.el
  2. 10 4
      testing/lisp/test-org-table.el

+ 2 - 1
lisp/org-table.el

@@ -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)

+ 10 - 4
testing/lisp/test-org-table.el

@@ -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"