all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#40217: 28.0.50; Add check for valid month to date-days-in-month
@ 2020-03-24 23:39 Alex Branham
  2020-04-03 11:22 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Branham @ 2020-03-24 23:39 UTC (permalink / raw)
  To: 40217

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-check-for-valid-month-to-date-days-in-month.patch --]
[-- Type: text/x-patch, Size: 1564 bytes --]

From f9c3040d516314209d64738fd23deafc5eb59faa Mon Sep 17 00:00:00 2001
From: Alex Branham <alex.branham@gmail.com>
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


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

* bug#40217: 28.0.50; Add check for valid month to date-days-in-month
  2020-03-24 23:39 bug#40217: 28.0.50; Add check for valid month to date-days-in-month Alex Branham
@ 2020-04-03 11:22 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2020-04-03 11:22 UTC (permalink / raw)
  To: Alex Branham; +Cc: 40217-done

> From: Alex Branham <alex.branham@gmail.com>
> 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).





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

end of thread, other threads:[~2020-04-03 11:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-24 23:39 bug#40217: 28.0.50; Add check for valid month to date-days-in-month Alex Branham
2020-04-03 11:22 ` Eli Zaretskii

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.