aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-16 23:43:13 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-16 23:47:34 +0100
commit6b512e05ead3b2333e64a52bd9f4879ad3d1f256 (patch)
tree1078b43182d327ea19e087283f7440664b9977a4
parentb64eaff775fdca48f1ac226fb84b4b6538ca18f2 (diff)
compat-27: Add date-ordinal-to-time
-rw-r--r--NEWS.org4
-rw-r--r--compat-27.el10
-rw-r--r--compat-tests.el4
-rw-r--r--compat.texi9
4 files changed, 27 insertions, 0 deletions
diff --git a/NEWS.org b/NEWS.org
index 59d86ff..4a5849a 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,5 +1,9 @@
#+title: compat.el - Changelog
+* Development
+
+- compat-27: Add ~date-ordinal-to-time~.
+
* Release of "Compat" Version 29.1.2.0
- All compatibility functions are covered by tests!
diff --git a/compat-27.el b/compat-27.el
index fadf934..1b4bbdf 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -538,6 +538,16 @@ The return value is a string (or nil in case we can’t find it)."
31
30)))
+(compat-defun date-ordinal-to-time (year ordinal) ;; <compat-tests:date-ordinal-to-time>
+ "Convert a YEAR/ORDINAL to the equivalent `decoded-time' structure.
+ORDINAL is the number of days since the start of the year, with
+January 1st being 1."
+ (let ((month 1))
+ (while (> ordinal (date-days-in-month year month))
+ (setq ordinal (- ordinal (date-days-in-month year month))
+ month (1+ month)))
+ (list nil nil nil ordinal month year nil nil nil)))
+
;;;; Defined in text-property-search.el
(compat-defun make-prop-match (&rest attr) ;; <compat-tests:make-prop-match>
diff --git a/compat-tests.el b/compat-tests.el
index 25215f3..4ee1325 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -2504,6 +2504,10 @@
(should-equal 29 (date-days-in-month 2020 2))
(should-equal 28 (date-days-in-month 2021 2)))
+(ert-deftest date-ordinal-to-time ()
+ (should-equal '(nil nil nil 9 4 2020 nil nil nil) (date-ordinal-to-time 2020 100))
+ (should-equal '(nil nil nil 19 7 2021 nil nil nil) (date-ordinal-to-time 2021 200)))
+
(ert-deftest regexp-opt ()
;; Ensure `regexp-opt' doesn't change the existing
;; behaviour:
diff --git a/compat.texi b/compat.texi
index be893ce..9aca75b 100644
--- a/compat.texi
+++ b/compat.texi
@@ -1079,6 +1079,15 @@ February 2020 has 29 days.
@code{time-date} feature to be loaded.
@end defun
+@defun date-ordinal-to-time year ordinal
+Convert a @var{year}/@var{ordinal} to the equivalent decoded-time
+structure. @var{ordinal} is the number of days since the start of the
+year, with January 1st being 1.
+
+@xref{Time Calculations,,,elisp}. This function requires the
+@code{time-date} feature to be loaded.
+@end defun
+
@defopt exec-path
The value of this variable is a list of directories to search for
programs to run in subprocesses. Each element is either the name of a