GNU bug report logs -
#68969
[PATCH] Fix handling of delta values with negative month field
Previous Next
Reported by: Łukasz Stelmach <stlman <at> poczta.fm>
Date: Wed, 7 Feb 2024 13:39:01 UTC
Severity: normal
Tags: patch
Fixed in version 31.1
Done: Stefan Kangas <stefankangas <at> gmail.com>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 68969 in the body.
You can then email your comments to 68969 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68969
; Package
emacs
.
(Wed, 07 Feb 2024 13:39:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Łukasz Stelmach <stlman <at> poczta.fm>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 07 Feb 2024 13:39:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
* lisp/calendar/time-date.el (decoded-time-add): If the new
variable is less then zero, the year needs to be decremented
by quotient of new and 12 increased by one.
* test/lisp/calendar/time-date-tests.el (test-decoded-add):
Add applicable test cases.
---
lisp/calendar/time-date.el | 2 +-
test/lisp/calendar/time-date-tests.el | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index e96e2e7e2db..68b05314f3c 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -473,7 +473,7 @@ decoded-time-add
(when (decoded-time-month delta)
(let ((new (+ (1- (decoded-time-month time)) (decoded-time-month delta))))
(setf (decoded-time-month time) (1+ (mod new 12)))
- (cl-incf (decoded-time-year time) (/ new 12))))
+ (cl-incf (decoded-time-year time) (- (/ new 12) (if (< new 0) 1 0)))))
;; Adjust for month length (as described in the doc string).
(setf (decoded-time-day time)
diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el
index 01f9f8a5108..4ca274fcec6 100644
--- a/test/lisp/calendar/time-date-tests.el
+++ b/test/lisp/calendar/time-date-tests.el
@@ -131,6 +131,18 @@ test-decoded-add
(should (equal (decoded-time-add time (mdec :month 10))
'(12 15 16 8 5 2020 1 t 7200)))
+ (should (equal (decoded-time-add time (mdec :month -1))
+ '(12 15 16 8 6 2019 1 t 7200)))
+
+ (should (equal (decoded-time-add time (mdec :month -10))
+ '(12 15 16 8 9 2018 1 t 7200)))
+
+ (should (equal (decoded-time-add time (mdec :month -14))
+ '(12 15 16 8 5 2018 1 t 7200)))
+
+ (should (equal (decoded-time-add time (mdec :month -24))
+ '(12 15 16 8 7 2017 1 t 7200)))
+
(should (equal (decoded-time-add time (mdec :day 1))
'(12 15 16 9 7 2019 1 t 7200)))
--
2.39.2
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68969
; Package
emacs
.
(Sun, 23 Feb 2025 01:00:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 68969 <at> debbugs.gnu.org (full text, mbox):
Łukasz Stelmach <stlman <at> poczta.fm> writes:
> * lisp/calendar/time-date.el (decoded-time-add): If the new
> variable is less then zero, the year needs to be decremented
> by quotient of new and 12 increased by one.
> * test/lisp/calendar/time-date-tests.el (test-decoded-add):
> Add applicable test cases.
> ---
> lisp/calendar/time-date.el | 2 +-
> test/lisp/calendar/time-date-tests.el | 12 ++++++++++++
> 2 files changed, 13 insertions(+), 1 deletion(-)
Thanks, and sorry for the late reply here.
Could you please explain what is the issue that this patch fixes? Is
there a concrete use case that made you run into this?
> diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
> index e96e2e7e2db..68b05314f3c 100644
> --- a/lisp/calendar/time-date.el
> +++ b/lisp/calendar/time-date.el
> @@ -473,7 +473,7 @@ decoded-time-add
> (when (decoded-time-month delta)
> (let ((new (+ (1- (decoded-time-month time)) (decoded-time-month delta))))
> (setf (decoded-time-month time) (1+ (mod new 12)))
> - (cl-incf (decoded-time-year time) (/ new 12))))
> + (cl-incf (decoded-time-year time) (- (/ new 12) (if (< new 0) 1 0)))))
>
> ;; Adjust for month length (as described in the doc string).
> (setf (decoded-time-day time)
> diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el
> index 01f9f8a5108..4ca274fcec6 100644
> --- a/test/lisp/calendar/time-date-tests.el
> +++ b/test/lisp/calendar/time-date-tests.el
> @@ -131,6 +131,18 @@ test-decoded-add
> (should (equal (decoded-time-add time (mdec :month 10))
> '(12 15 16 8 5 2020 1 t 7200)))
>
> + (should (equal (decoded-time-add time (mdec :month -1))
> + '(12 15 16 8 6 2019 1 t 7200)))
> +
> + (should (equal (decoded-time-add time (mdec :month -10))
> + '(12 15 16 8 9 2018 1 t 7200)))
> +
> + (should (equal (decoded-time-add time (mdec :month -14))
> + '(12 15 16 8 5 2018 1 t 7200)))
> +
> + (should (equal (decoded-time-add time (mdec :month -24))
> + '(12 15 16 8 7 2017 1 t 7200)))
> +
> (should (equal (decoded-time-add time (mdec :day 1))
> '(12 15 16 9 7 2019 1 t 7200)))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#68969
; Package
emacs
.
(Wed, 26 Feb 2025 13:13:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 68969 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Stefan Kangas <stefankangas <at> gmail.com> writes:
> Łukasz Stelmach <stlman <at> poczta.fm> writes:
>
>> * lisp/calendar/time-date.el (decoded-time-add): If the new
>> variable is less then zero, the year needs to be decremented
>> by quotient of new and 12 increased by one.
>> * test/lisp/calendar/time-date-tests.el (test-decoded-add):
>> Add applicable test cases.
>> ---
>> lisp/calendar/time-date.el | 2 +-
>> test/lisp/calendar/time-date-tests.el | 12 ++++++++++++
>> 2 files changed, 13 insertions(+), 1 deletion(-)
>
> Thanks, and sorry for the late reply here.
>
> Could you please explain what is the issue that this patch fixes? Is
> there a concrete use case that made you run into this?
I was playing with Gnus' message list limiting
gnus-summary-limit-to-age[1] and making my own
lksz-gnus-summary-limit-to-month before sending this patch, but honestly
I can't remember exactly. Beginning of a year may suggest that I was
moving some e-mail messages between archive folders and something wasn't
right across the year boundary. This is as close as I can guess.
I still believe, however, the patch as it is needed and makes sense.
[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58820
--
Kind regards,
Łukasz Stelmach
[signature.asc (application/pgp-signature, inline)]
Reply sent
to
Stefan Kangas <stefankangas <at> gmail.com>
:
You have taken responsibility.
(Sat, 01 Mar 2025 03:42:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Łukasz Stelmach <stlman <at> poczta.fm>
:
bug acknowledged by developer.
(Sat, 01 Mar 2025 03:42:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 68969-done <at> debbugs.gnu.org (full text, mbox):
Version: 31.1
Łukasz Stelmach <stlman <at> poczta.fm> writes:
> Stefan Kangas <stefankangas <at> gmail.com> writes:
>
>> Łukasz Stelmach <stlman <at> poczta.fm> writes:
>>
>>> * lisp/calendar/time-date.el (decoded-time-add): If the new
>>> variable is less then zero, the year needs to be decremented
>>> by quotient of new and 12 increased by one.
>>> * test/lisp/calendar/time-date-tests.el (test-decoded-add):
>>> Add applicable test cases.
>>> ---
>>> lisp/calendar/time-date.el | 2 +-
>>> test/lisp/calendar/time-date-tests.el | 12 ++++++++++++
>>> 2 files changed, 13 insertions(+), 1 deletion(-)
>>
>> Thanks, and sorry for the late reply here.
>>
>> Could you please explain what is the issue that this patch fixes? Is
>> there a concrete use case that made you run into this?
>
> I was playing with Gnus' message list limiting
> gnus-summary-limit-to-age[1] and making my own
> lksz-gnus-summary-limit-to-month before sending this patch, but honestly
> I can't remember exactly. Beginning of a year may suggest that I was
> moving some e-mail messages between archive folders and something wasn't
> right across the year boundary. This is as close as I can guess.
>
> I still believe, however, the patch as it is needed and makes sense.
>
> [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58820
Thanks for the patch. I installed it on master.
I'm therefore closing this bug report.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 29 Mar 2025 11:24:37 GMT)
Full text and
rfc822 format available.
This bug report was last modified 98 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.