emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master afee776: Fix logic of gnus-search-imap-handle-date


From: Eric Abrahamsen
Subject: master afee776: Fix logic of gnus-search-imap-handle-date
Date: Mon, 14 Dec 2020 12:27:34 -0500 (EST)

branch: master
commit afee776594fc7df881106fab5188f3dd40a3f8b8
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    Fix logic of gnus-search-imap-handle-date
    
    * lisp/gnus/gnus-search.el (gnus-search-imap-handle-date): Just
    rewrite this whole ridiculous function.
---
 lisp/gnus/gnus-search.el | 61 +++++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 32 deletions(-)

diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el
index 0e67fac..829e0fa 100644
--- a/lisp/gnus/gnus-search.el
+++ b/lisp/gnus/gnus-search.el
@@ -1252,44 +1252,41 @@ means (usually the \"mark\" keyword)."
                    (gnus-search-imap-handle-string engine (cdr expr))))))))))
 
 (cl-defmethod gnus-search-imap-handle-date ((_engine gnus-search-imap)
-                                    (date list))
+                                           (date list))
   "Turn DATE into a date string recognizable by IMAP.
 While other search engines can interpret partially-qualified
 dates such as a plain \"January\", IMAP requires an absolute
 date.
 
 DATE is a list of (dd mm yyyy), any element of which could be
-nil.  Massage those numbers into the most recent past occurrence
-of whichever date elements are present."
-  (let ((now (decode-time (current-time))))
-    ;; Set nil values to 1, current-month, current-year, or else 1, 1,
-    ;; current-year, depending on what we think the user meant.
-    (unless (seq-elt date 1)
-      (setf (seq-elt date 1)
-           (if (seq-elt date 0)
-               (seq-elt now 4)
-             1)))
-    (unless (seq-elt date 0)
-      (setf (seq-elt date 0) 1))
-    (unless (seq-elt date 2)
-      (setf (seq-elt date 2)
-           (seq-elt now 5)))
-    ;; Fiddle with the date until it's in the past.  There
-    ;; must be a way to combine all these steps.
-    (unless (< (seq-elt date 2)
-              (seq-elt now 5))
-      (when (< (seq-elt now 3)
-              (seq-elt date 0))
-       (cl-decf (seq-elt date 1)))
-      (cond ((zerop (seq-elt date 1))
-            (setf (seq-elt date 1) 1)
-            (cl-decf (seq-elt date 2)))
-           ((< (seq-elt now 4)
-               (seq-elt date 1))
-            (cl-decf (seq-elt date 2))))))
-  (format-time-string "%e-%b-%Y" (apply #'encode-time
-                                       (append '(0 0 0)
-                                               date))))
+nil (except that (dd nil yyyy) is not allowed).  Massage those
+numbers into the most recent past occurrence of whichever date
+elements are present."
+  (pcase-let ((`(,nday ,nmonth ,nyear)
+              (seq-subseq (decode-time (current-time))
+                          3 6))
+             (`(,dday ,dmonth ,dyear) date))
+    (unless (and dday dmonth dyear)
+      (unless dday (setq dday 1))
+      (if dyear
+         ;; If we have a year, then leave everything else as is or set
+         ;; to 1.
+         (setq dmonth (or dmonth 1))
+       (if dmonth
+           (setq dyear
+                 (if (or (> dmonth nmonth)
+                         (and (= dmonth nmonth)
+                              (> dday nday)))
+                     ;; If our day/month combo is ahead of "now",
+                     ;; move the year back.
+                     (1- nyear)
+                   nyear))
+         (setq dmonth 1))))
+    (format-time-string
+     "%e-%b-%Y"
+     (apply #'encode-time
+           (append '(0 0 0)
+                   (list dday dmonth dyear))))))
 
 (cl-defmethod gnus-search-imap-handle-string ((engine gnus-search-imap)
                                              (str string))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]