diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 3495e6eed..67f51401f 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -196,6 +196,7 @@ a #+BEGIN_FOO/#+END_FOO block. Bound to C-c C-x w by default. See docstring for details. +*** ~org-timestamp-to-time~ *** ~org-timestamp-from-string~ *** ~org-timestamp-from-time~ *** ~org-attach-dired-to-subtree~ diff --git a/lisp/org.el b/lisp/org.el index 2de3714ab..00a127ee2 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -22546,8 +22546,8 @@ return an active timestamp." :hour-start (and with-time hour) :minute-start (and with-time minute))))) -(defun org-timestamp--to-internal-time (timestamp &optional end) - "Encode TIMESTAMP object into Emacs internal time. +(defun org-timestamp-to-time (timestamp &optional end) + "Convert TIMESTAMP object into an Emacs internal time value. Use end of date range or time range when END is non-nil. Otherwise, use its start." (apply #'encode-time @@ -22571,11 +22571,10 @@ FORMAT is a format specifier to be passed to When optional argument END is non-nil, use end of date-range or time-range, if possible. -When optional argument UTC is non-nil, time will be expressed as +When optional argument UTC is non-nil, time is be expressed as Universal Time." - (format-time-string - format (org-timestamp--to-internal-time timestamp end) - (and utc t))) + (format-time-string format (org-timestamp-to-time timestamp end) + (and utc t))) (defun org-timestamp-split-range (timestamp &optional end) "Extract a TIMESTAMP object from a date or time range. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index ab618f012..2e1d18911 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -6510,6 +6510,61 @@ CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40" (org-element-interpret-data (org-timestamp-from-time '(20339 35296) nil t)))))) +(ert-deftest test-org/timestamp-to-time () + "Test `org-timestamp-to-time' specifications." + (should + (equal "2014-03-04" + (format-time-string + "%Y-%m-%d" + (org-timestamp-to-time + (org-timestamp-from-string "<2014-03-04 Tue>"))))) + (should + (equal "2014-03-04" + (format-time-string + "%Y-%m-%d" + (org-timestamp-to-time + (org-timestamp-from-string "[2014-03-04 Tue]"))))) + (should + (equal "2012-03-29 08:30" + (format-time-string + "%Y-%m-%d %H:%M" + (org-timestamp-to-time + (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>"))))) + (should + (equal "2012-03-29" + (format-time-string + "%Y-%m-%d" + (org-timestamp-to-time + (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>"))))) + (should + (equal "2012-03-29" + (format-time-string + "%Y-%m-%d" + (org-timestamp-to-time + (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]"))))) + ;; When optional argument END is non-nil, use end of date range or + ;; time range. + (should + (equal "2012-03-29 16:40" + (format-time-string + "%Y-%m-%d %H:%M" + (org-timestamp-to-time + (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>") + t)))) + (should + (equal "2014-03-04" + (format-time-string + "%Y-%m-%d" + (org-timestamp-to-time + (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>") + t)))) + (should + (equal "2014-03-04" + (format-time-string + "%Y-%m-%d" + (org-timestamp-to-time + (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]") + t))))) ;;; Visibility