emacs-bug-tracker
[Top][All Lists]
Advanced

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

bug#40217: closed (28.0.50; Add check for valid month to date-days-in-mo


From: GNU bug Tracking System
Subject: bug#40217: closed (28.0.50; Add check for valid month to date-days-in-month)
Date: Fri, 03 Apr 2020 11:23:02 +0000

Your message dated Fri, 03 Apr 2020 14:22:18 +0300
with message-id <address@hidden>
and subject line Re: bug#40217: 28.0.50; Add check for valid month to 
date-days-in-month
has caused the debbugs.gnu.org bug report #40217,
regarding 28.0.50; Add check for valid month to date-days-in-month
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden.)


-- 
40217: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=40217
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: 28.0.50; Add check for valid month to date-days-in-month Date: Tue, 24 Mar 2020 19:39:44 -0400 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
Hello -

Here's a patch that adds a check for whether the month argument is
valid in the new date-days-in-month function. It currently returns 30
for a month value of, say, 15.

Thanks,
Alex

>From f9c3040d516314209d64738fd23deafc5eb59faa Mon Sep 17 00:00:00 2001
From: Alex Branham <address@hidden>
Date: Tue, 24 Mar 2020 19:34:14 -0400
Subject: [PATCH] Add check for valid month to date-days-in-month

* lisp/calendar/time-date.el (date-days-in-month): Add check.
* test/lisp/calendar/time-date-tests.el (test-days-in-month): Add test
for new error.
---
 lisp/calendar/time-date.el            | 2 ++
 test/lisp/calendar/time-date-tests.el | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index e2402de801..9b58a4884b 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -355,6 +355,8 @@ seconds-to-string
 
 (defun date-days-in-month (year month)
   "The number of days in MONTH in YEAR."
+  (unless (<= 1 month 12)
+    (error "Month %s invalid" month))
   (if (= month 2)
       (if (date-leap-year-p year)
           29
diff --git a/test/lisp/calendar/time-date-tests.el 
b/test/lisp/calendar/time-date-tests.el
index 4c8f18a7a9..9c90300cfe 100644
--- a/test/lisp/calendar/time-date-tests.el
+++ b/test/lisp/calendar/time-date-tests.el
@@ -31,7 +31,8 @@ test-leap-year
 (ert-deftest test-days-in-month ()
   (should (= (date-days-in-month 2004 2) 29))
   (should (= (date-days-in-month 2004 3) 31))
-  (should-not (= (date-days-in-month 1900 3) 28)))
+  (should-not (= (date-days-in-month 1900 3) 28))
+  (should-error (date-days-in-month 2020 15)))
 
 (ert-deftest test-ordinal ()
   (should (equal (date-ordinal-to-time 2008 271)
-- 
2.25.1


--- End Message ---
--- Begin Message --- Subject: Re: bug#40217: 28.0.50; Add check for valid month to date-days-in-month Date: Fri, 03 Apr 2020 14:22:18 +0300
> From: Alex Branham <address@hidden>
> Date: Tue, 24 Mar 2020 19:39:44 -0400
> 
> Here's a patch that adds a check for whether the month argument is
> valid in the new date-days-in-month function. It currently returns 30
> for a month value of, say, 15.

Thanks, pushed to the master branch (after some minor fixes of the
commit log message).


--- End Message ---

reply via email to

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