Ihor Radchenko <[email protected]> writes:

>
> Ok, but then we need to make sure that we are actually using the time in
> the expected format. Your patch org-timestamp-change: Use proper time
> structure accessor functions uses decoded-time-minute on time0, which is
> from org-parse-time-string. And org-parse-time-string just returns a
> list. Note that decoded-time-minute is a struct method. That struct
> might change in subtle ways, so we should not rely on the list and
> struct being equivalent.

These are fair points.  However, I don't want to go back to the obscure
list accessor functions that where there before.  I also don't want to
duplicate the decoded-time accessor functions.  So what do you think of
the attached patch?  All the tests still pass and there are no compile
warnings.


>From 1a1d2ff549c3bbb0a2499379a0d67c995107fefa Mon Sep 17 00:00:00 2001
From: Morgan Smith <[email protected]>
Date: Sat, 28 Mar 2026 10:54:50 -0400
Subject: [PATCH] org-parse-time-string: Use `make-decoded-time'

* lisp/org-macs.el (org-parse-time-string): Use `make-decoded-time' to
ensure the return value is a proper decoded-time structure instead of
relying on the specific list structure.
---
 lisp/org-macs.el | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index d769fffa0..a7ed0cbb7 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -1616,6 +1616,8 @@ org-encode-time
         (_ (error "`org-encode-time' may be called with 1, 6, or 9 arguments but %d given"
                   (length time)))))))
 
+(declare-function make-decoded-time "time-date" (&rest args))
+
 (defun org-parse-time-string (s &optional nodefault)
   "Parse Org time string S.
 
@@ -1629,17 +1631,17 @@ org-parse-time-string
 This should be a lot faster than the `parse-time-string'."
   (unless (string-match org-ts-regexp0 s)
     (error "Not an Org time string: %s" s))
-  (list 0
-	(cond ((match-beginning 8) (string-to-number (match-string 8 s)))
-	      (nodefault nil)
-	      (t 0))
-	(cond ((match-beginning 7) (string-to-number (match-string 7 s)))
-	      (nodefault nil)
-	      (t 0))
-	(string-to-number (match-string 4 s))
-	(string-to-number (match-string 3 s))
-	(string-to-number (match-string 2 s))
-	nil -1 nil))
+  (make-decoded-time
+   :second 0
+   :minute (cond ((match-beginning 8) (string-to-number (match-string 8 s)))
+                 (nodefault nil)
+                 (t 0))
+   :hour (cond ((match-beginning 7) (string-to-number (match-string 7 s)))
+               (nodefault nil)
+               (t 0))
+   :day (string-to-number (match-string 4 s))
+   :month (string-to-number (match-string 3 s))
+   :year (string-to-number (match-string 2 s))))
 
 (defun org-matcher-time (s)
   "Interpret a time comparison value S as a floating point time.
-- 
2.52.0

Reply via email to