branch: externals/compat
commit 67316e83b2164da67807dd9280936aec2815f61b
Author: Philip Kaludercic <phil...@posteo.net>
Commit: Philip Kaludercic <phil...@posteo.net>

    Add date-days-in-month
---
 MANUAL          |  4 +++-
 compat-27.el    | 15 +++++++++++++++
 compat-tests.el |  6 ++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/MANUAL b/MANUAL
index a2397ba9c7..91cfc3ba53 100644
--- a/MANUAL
+++ b/MANUAL
@@ -303,6 +303,9 @@ provided by Compat by default:
 - Function: decoded-time-zone :: Defined in ~simple.el~.
 - Function: package-get-version :: Defined in ~package.el~.
 - Function: time-equal-p :: See [[info:elisp#Time Calculations][(elisp) Time 
Calculations]].
+- Function: date-days-in-month :: See [[info:elisp#Time Calculations][(elisp) 
Time Calculations]].
+
+  This function requires the ~time-date~ feature to be loaded.
 
 These functions are prefixed with ~compat~ prefix, and are only loaded
 when ~compat-27~ is required:
@@ -338,7 +341,6 @@ implemented in 27.1:
 - Bigint support.
 - The function ~time-convert~.
 - All ~iso8601-*~ functions.
-- The function ~date-days-in-month~.
 - The macro ~benchmark-progn~.
 - The function ~read-char-from-minibuffer~.
 - The minor mode ~reveal-mode~.
diff --git a/compat-27.el b/compat-27.el
index acb7ffdbfa..147db3e9e1 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -584,5 +584,20 @@ The return value is a string (or nil in case we can’t find 
it)."
         (user-error (if (stringp error) error "No files specified"))
       result)))
 
+;;;; Defined in time-date.el
+
+(compat-defun date-days-in-month (year month)
+  "The number of days in MONTH in YEAR."
+  :feature 'time-date
+  (unless (and (numberp month) (<= 1 month 12))
+    (error "Month %s is invalid" month))
+  (if (= month 2)
+      (if (date-leap-year-p year)
+          29
+        28)
+    (if (memq month '(1 3 5 7 8 10 12))
+        31
+      30)))
+
 (provide 'compat-27)
 ;;; compat-27.el ends here
diff --git a/compat-tests.el b/compat-tests.el
index 05b75bcb99..12fa1cf94a 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1653,5 +1653,11 @@ being compared against."
   (ought nil '(1 2 3 4) '(2 2 3 4))
   (ought nil '(2 2 3 4) '(1 2 3 4)))
 
+(compat-deftest date-days-in-month
+  (ought 31 2020 1)
+  (ought 30 2020 4)
+  (ought 29 2020 2)
+  (ought 28 2021 2))
+
 (provide 'compat-tests)
 ;;; compat-tests.el ends here

Reply via email to