unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#58820: [PATCH] Calculate age cutoff at n-th midnight instead of n*24h mark
@ 2022-10-27 18:50 Łukasz Stelmach
  2023-09-07 20:29 ` Stefan Kangas
  0 siblings, 1 reply; 4+ messages in thread
From: Łukasz Stelmach @ 2022-10-27 18:50 UTC (permalink / raw)
  To: 58820; +Cc: Łukasz Stelmach

* lisp/gnus/gnus-sum.el (gnus-summary-limit-to-age): Calculate cutoff to
point to n-th past midnight (1st is 00:00 today).  This way messages sent
between n*24h mark and the next midnight will be excluded (or included
if limitting to younger messages), which seems more intuitive when users
are asked to enter age in days.
---
 lisp/gnus/gnus-sum.el | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 18ba55a439..a15dedeccf 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -8323,8 +8323,9 @@ articles."
 
 (defun gnus-summary-limit-to-age (age &optional younger-p)
   "Limit the summary buffer to articles that are older than (or equal) AGE days.
-If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
-articles that are younger than AGE days."
+Days are counted at midnight so with AGE equal 1 messages sent before 00:00
+today will be included (or excluded).  If YOUNGER-P (the prefix) is non-nil,
+limit the summary buffer to articles that are younger than AGE days."
   (interactive
    (let ((younger current-prefix-arg)
 	 (days-got nil)
@@ -8347,15 +8348,17 @@ articles that are younger than AGE days."
      (list days younger))
    gnus-summary-mode)
   (prog1
-      (let ((data gnus-newsgroup-data)
-	    (cutoff (days-to-time age))
-	    articles d date is-younger)
+      (let* ((data gnus-newsgroup-data)
+	     (now (append '(0 0 0) (cdddr (decode-time))))
+	     (delta (make-decoded-time :day (* -1 (- age 1))))
+	     (cutoff (encode-time (decoded-time-add now delta)))
+	     articles d date is-younger)
 	(while (setq d (pop data))
 	  (when (and (mail-header-p (gnus-data-header d))
 		     (setq date (mail-header-date (gnus-data-header d))))
 	    (setq is-younger (time-less-p
-			      (time-since (gnus-date-get-time date))
-			      cutoff))
+			      cutoff
+			      (gnus-date-get-time date)))
 	    (when (if younger-p
 		      is-younger
 		    (not is-younger))
-- 
2.30.2






^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#58820: [PATCH] Calculate age cutoff at n-th midnight instead of n*24h mark
  2022-10-27 18:50 bug#58820: [PATCH] Calculate age cutoff at n-th midnight instead of n*24h mark Łukasz Stelmach
@ 2023-09-07 20:29 ` Stefan Kangas
  2023-09-23 23:36   ` Eric Abrahamsen
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Kangas @ 2023-09-07 20:29 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: 58820, Eric Abrahamsen

Łukasz Stelmach <stlman@poczta.fm> writes:

> * lisp/gnus/gnus-sum.el (gnus-summary-limit-to-age): Calculate cutoff to
> point to n-th past midnight (1st is 00:00 today).  This way messages sent
> between n*24h mark and the next midnight will be excluded (or included
> if limitting to younger messages), which seems more intuitive when users
> are asked to enter age in days.

Eric, do you have any comments on this patch?  Thanks in advance.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#58820: [PATCH] Calculate age cutoff at n-th midnight instead of n*24h mark
  2023-09-07 20:29 ` Stefan Kangas
@ 2023-09-23 23:36   ` Eric Abrahamsen
  2023-10-11 14:57     ` Eric Abrahamsen
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2023-09-23 23:36 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 58820, Łukasz Stelmach

[-- Attachment #1: Type: text/plain, Size: 885 bytes --]

Stefan Kangas <stefankangas@gmail.com> writes:

> Łukasz Stelmach <stlman@poczta.fm> writes:
>
>> * lisp/gnus/gnus-sum.el (gnus-summary-limit-to-age): Calculate cutoff to
>> point to n-th past midnight (1st is 00:00 today).  This way messages sent
>> between n*24h mark and the next midnight will be excluded (or included
>> if limitting to younger messages), which seems more intuitive when users
>> are asked to enter age in days.
>
> Eric, do you have any comments on this patch?  Thanks in advance.

Hi!

I do think this a reasonable change, thanks to Łukasz for the report.
I'd like to apply the attached, which is mostly Łukasz's code with the
addition of a simplification of the argument reading.

I've also changed the docstring a bit, as I found the original change a
little hard to understand. However, this might not be any better!

WDYT?

Eric


[-- Attachment #2: 0001-Have-gnus-summary-limit-to-age-operate-on-calendar-d.patch --]
[-- Type: text/x-patch, Size: 3098 bytes --]

From 5b050f666dce02636921f4d1f7529efae6aec856 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Sat, 23 Sep 2023 16:31:10 -0700
Subject: [PATCH] Have gnus-summary-limit-to-age operate on calendar days
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reported and patched by Łukasz Stelmach <stlman@poczta.fm>.

* lisp/gnus/gnus-sum.el (gnus-summary-limit-to-age): Rather than
24-hour blocks. Also use `read-number', and drop the confusing option
to reverse younger/older both with the prefix argument and with a
negative number.
---
 lisp/gnus/gnus-sum.el | 40 +++++++++++++++-------------------------
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index a3be5577f7a..f576d4e6147 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -8331,39 +8331,29 @@ gnus-summary-limit-to-predicate
 
 (defun gnus-summary-limit-to-age (age &optional younger-p)
   "Limit the summary buffer to articles that are older than (or equal) AGE days.
-If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
-articles that are younger than AGE days."
+Days are counted from midnight to midnight, and now to the
+previous midnight counts as day one.  If YOUNGER-P (the prefix)
+is non-nil, limit the summary buffer to articles that are younger
+than AGE days."
   (interactive
-   (let ((younger current-prefix-arg)
-	 (days-got nil)
-	 days)
-     (while (not days-got)
-       (setq days (if younger
-		      (read-string "Limit to articles younger than (in days, older when negative): ")
-		    (read-string
-		     "Limit to articles older than (in days, younger when negative): ")))
-       (when (> (length days) 0)
-	 (setq days (read days)))
-       (if (numberp days)
-	   (progn
-	     (setq days-got t)
-	     (when (< days 0)
-	       (setq younger (not younger))
-	       (setq days (* days -1))))
-	 (message "Please enter a number.")
-	 (sleep-for 1)))
+   (let* ((younger current-prefix-arg)
+	  (days (read-number
+                 (if younger "Limit to articles younger than days: "
+                   "Limit to articles older than days: "))))
      (list days younger))
    gnus-summary-mode)
   (prog1
-      (let ((data gnus-newsgroup-data)
-	    (cutoff (days-to-time age))
-	    articles d date is-younger)
+      (let* ((data gnus-newsgroup-data)
+             (now (append '(0 0 0) (cdddr (decode-time))))
+             (delta (make-decoded-time :day (* -1 (- age 1))))
+             (cutoff (encode-time (decoded-time-add now delta)))
+	     articles d date is-younger)
 	(while (setq d (pop data))
 	  (when (and (mail-header-p (gnus-data-header d))
 		     (setq date (mail-header-date (gnus-data-header d))))
 	    (setq is-younger (time-less-p
-			      (time-since (gnus-date-get-time date))
-			      cutoff))
+			      cutoff
+			      (gnus-date-get-time date)))
 	    (when (if younger-p
 		      is-younger
 		    (not is-younger))
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#58820: [PATCH] Calculate age cutoff at n-th midnight instead of n*24h mark
  2023-09-23 23:36   ` Eric Abrahamsen
@ 2023-10-11 14:57     ` Eric Abrahamsen
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Abrahamsen @ 2023-10-11 14:57 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 58820, Łukasz Stelmach

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Stefan Kangas <stefankangas@gmail.com> writes:
>
>> Łukasz Stelmach <stlman@poczta.fm> writes:
>>
>>> * lisp/gnus/gnus-sum.el (gnus-summary-limit-to-age): Calculate cutoff to
>>> point to n-th past midnight (1st is 00:00 today).  This way messages sent
>>> between n*24h mark and the next midnight will be excluded (or included
>>> if limitting to younger messages), which seems more intuitive when users
>>> are asked to enter age in days.
>>
>> Eric, do you have any comments on this patch?  Thanks in advance.
>
> Hi!
>
> I do think this a reasonable change, thanks to Łukasz for the report.
> I'd like to apply the attached, which is mostly Łukasz's code with the
> addition of a simplification of the argument reading.
>
> I've also changed the docstring a bit, as I found the original change a
> little hard to understand. However, this might not be any better!
>
> WDYT?

I feel fairly okay about this patch, so will apply tomorrow unless
anyone complains.

Thanks,
Eric





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-11 14:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 18:50 bug#58820: [PATCH] Calculate age cutoff at n-th midnight instead of n*24h mark Łukasz Stelmach
2023-09-07 20:29 ` Stefan Kangas
2023-09-23 23:36   ` Eric Abrahamsen
2023-10-11 14:57     ` Eric Abrahamsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).