From c8e0bae4c96f72412962c0003d6b0bb5d5d51ccf Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Mon, 2 May 2022 17:41:34 +0700 Subject: [PATCH 4/6] testing/lisp: Use `org-time-string-to-time' * testing/lisp/test-org.el (test-org/org-read-date, test-org/deadline) (test-org/schedule, test-org/time-stamp, test-org/timestamp-from-time): * testing/org-test.el (org-test-at-time): Use `org-time-string-to-time' instead of composition of `org-parse-time-string' and `encode-time'. The actual goal is to prepare to replace `encode-time' by `org-encode-time' compatibility and convenience macro. --- testing/lisp/test-org.el | 44 ++++++++++++++++------------------------ testing/org-test.el | 2 +- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 4b5105a57..8748cfa75 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -201,14 +201,14 @@ (org-test-at-time "2014-03-04" (org-read-date t nil "+1y" nil - (apply #'encode-time (org-parse-time-string "2012-03-29")))))) + (org-time-string-to-time "2012-03-29"))))) (should (equal "2013-03-29" (org-test-at-time "2014-03-04" (org-read-date t nil "++1y" nil - (apply #'encode-time (org-parse-time-string "2012-03-29")))))) + (org-time-string-to-time "2012-03-29"))))) ;; When `org-read-date-prefer-future' is non-nil, prefer future ;; dates (relatively to now) when incomplete. Otherwise, use ;; default date. @@ -255,7 +255,7 @@ (let ((org-read-date-prefer-future t)) (org-read-date t nil "1" nil - (apply #'encode-time (org-parse-time-string "2012-03-29"))))))) + (org-time-string-to-time "2012-03-29")))))) (should (equal "2014-03-25" @@ -263,7 +263,7 @@ (let ((org-read-date-prefer-future t)) (org-read-date t nil "25" nil - (apply #'encode-time (org-parse-time-string "2012-03-29")))))))) + (org-time-string-to-time "2012-03-29"))))))) (ert-deftest test-org/org-parse-time-string () "Test `org-parse-time-string'." @@ -5443,8 +5443,7 @@ Paragraph" (equal "* H\nDEADLINE: <2012-03-29 -705d>" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time - (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) @@ -5453,8 +5452,7 @@ Paragraph" (should-error (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time - (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-test-with-temp-text "* H" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) @@ -5557,8 +5555,7 @@ Paragraph" (equal "* H\nSCHEDULED: <2012-03-29 -705d>" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time - (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) @@ -5567,8 +5564,7 @@ Paragraph" (should-error (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time - (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-test-with-temp-text "* H" (let ((org-adapt-indentation nil) (org-last-inserted-timestamp nil)) @@ -7786,7 +7782,7 @@ CLOSED: %s (org-test-with-temp-text "Text" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-time-stamp nil) (buffer-string))))) ;; With a prefix argument, also insert time. @@ -7796,8 +7792,7 @@ CLOSED: %s (org-test-with-temp-text "Text" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time - (org-parse-time-string "2014-03-04 00:41"))))) + (org-time-string-to-time "2014-03-04 00:41")))) (org-time-stamp '(4)) (buffer-string))))) ;; With two universal prefix arguments, insert an active timestamp @@ -7816,7 +7811,7 @@ CLOSED: %s (org-test-with-temp-text "Text" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-time-stamp nil t) (buffer-string))))) ;; When called from a timestamp, replace existing one. @@ -7826,7 +7821,7 @@ CLOSED: %s (org-test-with-temp-text "<2012-03-29 thu.>" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-time-stamp nil) (buffer-string))))) (should @@ -7835,7 +7830,7 @@ CLOSED: %s (org-test-with-temp-text "<2012-03-29 thu.>--<2014-03-04 tue.>" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-time-stamp nil) (buffer-string))))) ;; When replacing a timestamp, preserve repeater, if any. @@ -7845,7 +7840,7 @@ CLOSED: %s (org-test-with-temp-text "<2012-03-29 thu. +2y>" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (org-time-stamp nil) (buffer-string))))) ;; When called twice in a raw, build a date range. @@ -7855,7 +7850,7 @@ CLOSED: %s (org-test-with-temp-text "<2012-03-29 thu.>" (cl-letf (((symbol-function 'org-read-date) (lambda (&rest args) - (apply #'encode-time (org-parse-time-string "2014-03-04"))))) + (org-time-string-to-time "2014-03-04")))) (let ((last-command 'org-time-stamp) (this-command 'org-time-stamp)) (org-time-stamp nil)) @@ -8030,8 +8025,7 @@ CLOSED: %s "<2012-03-29 .+>" (org-element-interpret-data (org-timestamp-from-time - (apply #'encode-time - (org-parse-time-string "<2012-03-29 Thu 16:40>")))))) + (org-time-string-to-time "<2012-03-29 Thu 16:40>"))))) ;; When optional argument WITH-TIME is non-nil, provide time ;; information. (should @@ -8039,8 +8033,7 @@ CLOSED: %s "<2012-03-29 .+ 16:40>" (org-element-interpret-data (org-timestamp-from-time - (apply #'encode-time - (org-parse-time-string "<2012-03-29 Thu 16:40>")) + (org-time-string-to-time "<2012-03-29 Thu 16:40>") t)))) ;; When optional argument INACTIVE is non-nil, return an inactive ;; timestamp. @@ -8049,8 +8042,7 @@ CLOSED: %s "[2012-03-29 .+]" (org-element-interpret-data (org-timestamp-from-time - (apply #'encode-time - (org-parse-time-string "<2012-03-29 Thu 16:40>")) + (org-time-string-to-time "<2012-03-29 Thu 16:40>") nil t))))) (ert-deftest test-org/timestamp-to-time () diff --git a/testing/org-test.el b/testing/org-test.el index 0f1e254aa..d19c7f044 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -455,7 +455,7 @@ TIME can be a non-nil Lisp time value, or a string specifying a date and time." (at (cl-gensym))) `(let* ((,tm ,time) (,at (if (stringp ,tm) - (apply #'encode-time (org-parse-time-string ,tm)) + (org-time-string-to-time ,tm) ,tm))) (cl-letf ;; Wrap builtins whose behavior can depend on the current time. -- 2.25.1