[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master f134dfa 1/2: Error out if 'date-days-in-month' is given an invali
From: |
Eli Zaretskii |
Subject: |
master f134dfa 1/2: Error out if 'date-days-in-month' is given an invalid month |
Date: |
Fri, 3 Apr 2020 07:21:59 -0400 (EDT) |
branch: master
commit f134dfa041b30a8c28484a13c2fa08f2fee27ff5
Author: Alex Branham <address@hidden>
Commit: Eli Zaretskii <address@hidden>
Error out if 'date-days-in-month' is given an invalid month
* lisp/calendar/time-date.el (date-days-in-month): Add test for
month validity; signal an error if it isn't. (Bug#40217)
* test/lisp/calendar/time-date-tests.el (test-days-in-month): Add
a test for the 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 e2402de..9b58a48 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -355,6 +355,8 @@ is output until the first non-zero unit is encountered."
(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 4c8f18a..9c90300 100644
--- a/test/lisp/calendar/time-date-tests.el
+++ b/test/lisp/calendar/time-date-tests.el
@@ -31,7 +31,8 @@
(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)