aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2020-04-03 14:21:07 +0300
committerEli Zaretskii2020-04-03 14:21:07 +0300
commitd8dae04e5ae5cc4897c8d1af8548a0c1576137b6 (patch)
tree7fe76277745fd42fc16e63fbb78022351356f791
parentf134dfa041b30a8c28484a13c2fa08f2fee27ff5 (diff)
downloademacs-d8dae04e5ae5cc4897c8d1af8548a0c1576137b6.tar.gz
emacs-d8dae04e5ae5cc4897c8d1af8548a0c1576137b6.zip
Improve last change
* lisp/calendar/time-date.el (date-days-in-month): Improve the error message text and make sure MONTH is a number. (Bug#40217)
-rw-r--r--lisp/calendar/time-date.el4
-rw-r--r--test/lisp/calendar/time-date-tests.el3
2 files changed, 4 insertions, 3 deletions
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index 9b58a4884bc..eeb09926a6e 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -355,8 +355,8 @@ is output until the first non-zero unit is encountered."
355 355
356(defun date-days-in-month (year month) 356(defun date-days-in-month (year month)
357 "The number of days in MONTH in YEAR." 357 "The number of days in MONTH in YEAR."
358 (unless (<= 1 month 12) 358 (unless (and (numberp month) (<= 1 month 12))
359 (error "Month %s invalid" month)) 359 (error "Month %s is invalid" month))
360 (if (= month 2) 360 (if (= month 2)
361 (if (date-leap-year-p year) 361 (if (date-leap-year-p year)
362 29 362 29
diff --git a/test/lisp/calendar/time-date-tests.el b/test/lisp/calendar/time-date-tests.el
index 9c90300cfe6..3eecc67eb53 100644
--- a/test/lisp/calendar/time-date-tests.el
+++ b/test/lisp/calendar/time-date-tests.el
@@ -32,7 +32,8 @@
32 (should (= (date-days-in-month 2004 2) 29)) 32 (should (= (date-days-in-month 2004 2) 29))
33 (should (= (date-days-in-month 2004 3) 31)) 33 (should (= (date-days-in-month 2004 3) 31))
34 (should-not (= (date-days-in-month 1900 3) 28)) 34 (should-not (= (date-days-in-month 1900 3) 28))
35 (should-error (date-days-in-month 2020 15))) 35 (should-error (date-days-in-month 2020 15))
36 (should-error (date-days-in-month 2020 'foo)))
36 37
37(ert-deftest test-ordinal () 38(ert-deftest test-ordinal ()
38 (should (equal (date-ordinal-to-time 2008 271) 39 (should (equal (date-ordinal-to-time 2008 271)