Browse Source

org-clone-subtree-with-time-shift: Support hour time shift

* lisp/org.el (org-clone-subtree-with-time-shift): Support hour time
shift.
* testing/lisp/test-org.el (test-org/clone-with-time-shift): Add
tests.

Suggested-by: Felipe Barros <felipebarros@protonmail.com>
Link: https://orgmode.org/list/urqRSSSRsE8In5xtAPBR8AZalNGUCBkwwVV8ujNSN8_AOyh0reiE8XMrY6eviTBYUsV5fCF5GyJAtw7FB8xo-XBPPpYHOnP0zQuce4odhI8=@protonmail.com
Kyle Meyer 4 years ago
parent
commit
15c7385458
2 changed files with 27 additions and 2 deletions
  1. 2 1
      lisp/org.el
  2. 25 1
      testing/lisp/test-org.el

+ 2 - 1
lisp/org.el

@@ -7906,7 +7906,7 @@ with the original repeater."
 		"")))			;No time shift
 	 (doshift
 	  (and (org-string-nw-p shift)
-	       (or (string-match "\\`[ \t]*\\([+-]?[0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
+	       (or (string-match "\\`[ \t]*\\([+-]?[0-9]+\\)\\([hdwmy]\\)[ \t]*\\'"
 				 shift)
 		   (user-error "Invalid shift specification %s" shift)))))
     (goto-char end-of-tree)
@@ -7916,6 +7916,7 @@ with the original repeater."
 	   (shift-n (and doshift (string-to-number (match-string 1 shift))))
 	   (shift-what (pcase (and doshift (match-string 2 shift))
 			 (`nil nil)
+			 ("h" 'hour)
 			 ("d" 'day)
 			 ("w" (setq shift-n (* 7 shift-n)) 'day)
 			 ("m" 'month)

+ 25 - 1
testing/lisp/test-org.el

@@ -1804,7 +1804,31 @@
 		 (lambda (&rest args) "+1d")))
 	(org-clone-subtree-with-time-shift 1))
       (buffer-substring-no-properties (line-beginning-position 2)
-				      (line-end-position 2))))))
+				      (line-end-position 2)))))
+  ;; Hour shift.
+  (should
+   (equal "\
+* H1\n<2015-06-21 20:00>
+* H1\n<2015-06-21 23:00>
+* H1\n<2015-06-22 02:00>
+"
+          (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
+            (org-clone-subtree-with-time-shift 2 "+3h")
+            (replace-regexp-in-string
+             "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
+             (buffer-substring-no-properties (point-min) (point-max))
+             nil nil 1))))
+  (should
+   (equal "\
+* H1\n<2015-06-21 20:00>
+* H1\n<2015-06-21 18:00>
+"
+          (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
+            (org-clone-subtree-with-time-shift 1 "-2h")
+            (replace-regexp-in-string
+             "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
+             (buffer-substring-no-properties (point-min) (point-max))
+             nil nil 1)))))
 
 
 ;;; Fixed-Width Areas