emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 6b512e05ea: compat-27: Add date-ordinal-to-time


From: ELPA Syncer
Subject: [elpa] externals/compat 6b512e05ea: compat-27: Add date-ordinal-to-time
Date: Mon, 16 Jan 2023 17:57:26 -0500 (EST)

branch: externals/compat
commit 6b512e05ead3b2333e64a52bd9f4879ad3d1f256
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    compat-27: Add date-ordinal-to-time
---
 NEWS.org        |  4 ++++
 compat-27.el    | 10 ++++++++++
 compat-tests.el |  4 ++++
 compat.texi     |  9 +++++++++
 4 files changed, 27 insertions(+)

diff --git a/NEWS.org b/NEWS.org
index 59d86ff58c..4a5849a318 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 fadf934c2d..1b4bbdfe8c 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 25215f36f3..4ee1325d82 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 be893ce48e..9aca75b8f7 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]