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

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

[elpa] externals/compat 61d8e3953f: Add decoded-time-period defined in E


From: ELPA Syncer
Subject: [elpa] externals/compat 61d8e3953f: Add decoded-time-period defined in Emacs 28
Date: Sun, 10 Jul 2022 15:57:22 -0400 (EDT)

branch: externals/compat
commit 61d8e3953fb9a36c97a6a1fa0e730144e22e7e9a
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add decoded-time-period defined in Emacs 28
---
 MANUAL          |  1 +
 compat-28.el    | 20 +++++++++++++
 compat-tests.el | 92 ++++++++++++++++++++++++++++++---------------------------
 compat.texi     |  5 +++-
 4 files changed, 74 insertions(+), 44 deletions(-)

diff --git a/MANUAL b/MANUAL
index 005d122c15..02070c8b89 100644
--- a/MANUAL
+++ b/MANUAL
@@ -448,6 +448,7 @@ provided by Compat by default:
 - Function: file-backup-file-names :: See [[info:elisp#Backup Names][(elisp) 
Backup Names]].
 - Function: make-lock-file-name :: Defined in ~files.el~.
 - Function: null-device :: Defined in ~files.el~.
+- Function: decoded-time-period :: Defined in ~time-data.el~.
 
 These functions are prefixed with ~compat~ prefix, and are only loaded
 when ~compat-28~ is required:
diff --git a/compat-28.el b/compat-28.el
index 874e3e4780..9c5b00c00a 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -846,5 +846,25 @@ directory or directories specified."
     (apply 'update-directory-autoloads
            (if (listp dir) dir (list dir)))))
 
+;;;; Defined in time-data.el
+
+(compat-defun decoded-time-period (time)
+  "Interpret DECODED as a period and return its length in seconds.
+For computational purposes, years are 365 days long and months
+are 30 days long."
+  :feature 'time-date
+  :version "28"
+  ;; Inlining the definitions from compat-27
+  (+ (if (consp (nth 0 time))
+         ;; Fractional second.
+         (/ (float (car (nth 0 time)))
+            (cdr (nth 0 time)))
+       (or (nth 0 time) 0))
+     (* (or (nth 1 time) 0) 60)
+     (* (or (nth 2 time) 0) 60 60)
+     (* (or (nth 3 time) 0) 60 60 24)
+     (* (or (nth 4 time) 0) 60 60 24 30)
+     (* (or (nth 5 time) 0) 60 60 24 365)))
+
 (provide 'compat-28)
 ;;; compat-28.el ends here
diff --git a/compat-tests.el b/compat-tests.el
index 2ec6ed9aaa..e762eefdf2 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1721,49 +1721,55 @@ being compared against."
   (ought 29 2020 2)
   (ought 28 2021 2))
 
-(compat-deftest file-attribute-collect
-  (ought '(0) '(0 1 2 3 4 5 6 7 8 9 10 11)
-         'type)
-  (ought '(8) '(0 1 2 3 4 5 6 7 8 9 10 11)
-         'modes)
-  (ought '(10) '(0 1 2 3 4 5 6 7 8 9 10 11)
-         'inode-number)
-  (expect error '(0 1 2 3 4 5 6 7 8 9 10 11)
-          'something-else-that-shouldnt-exist)
-  (ought '(0 8) '(0 1 2 3 4 5 6 7 8 9 10 11)
-         'type 'modes)
-  (ought '(8 0) '(0 1 2 3 4 5 6 7 8 9 10 11)
-         'modes 'type)
-  (ought '(0 8 8) '(0 1 2 3 4 5 6 7 8 9 10 11)
-         'type 'modes 'modes)
-  (ought '(8 0 8) '(0 1 2 3 4 5 6 7 8 9 10 11)
-         'modes 'type 'modes)
-  (ought '(0 1 2 3 4 5 6 7 8 10 11)
-         '(0 1 2 3 4 5 6 7 8 9 10 11)
-         'type
-         'link-number
-         'user-id
-         'group-id
-         'access-time
-         'modification-time
-         'status-change-time
-         'size
-         'modes
-         'inode-number
-         'device-number)
-  (ought '(0 1 2 3 4 5 6 7 9 10 11)
-         '(1 0 3 2 5 4 7 6 9 8 11 10)
-         'link-number
-         'type
-         'group-id
-         'user-id
-         'modification-time
-         'access-time
-         'size
-         'status-change-time
-         'modes
-         'device-number
-         'inode-number))
+(compat-deftest decoded-time-period
+  (ought 0 '())
+  (ought 0 '(0))
+  (ought 1 '(1))
+  (ought 0.125 '((1 . 8)))
+
+  (ought 60 '(0 1))
+  (ought 61 '(1 1))
+  (ought -59 '(1 -1))
+
+  (ought (* 60 60) '(0 0 1))
+  (ought (+ (* 60 60) 60) '(0 1 1))
+  (ought (+ (* 60 60) 120 1) '(1 2 1))
+
+  (ought (* 60 60 24) '(0 0 0 1))
+  (ought (+ (* 60 60 24) 1) '(1 0 0 1))
+  (ought (+ (* 60 60 24) (* 60 60) 60 1) '(1 1 1 1))
+  (ought (+ (* 60 60 24) (* 60 60) 120 1) '(1 2 1 1))
+
+  (ought (* 60 60 24 30) '(0 0 0 0 1))
+  (ought (+ (* 60 60 24 30) 1) '(1 0 0 0 1))
+  (ought (+ (* 60 60 24 30) 60 1) '(1 1 0 0 1))
+  (ought (+ (* 60 60 24 30) (* 60 60) 60 1)
+         '(1 1 1 0 1))
+  (ought (+ (* 60 60 24 30) (* 60 60 24) (* 60 60) 120 1)
+         '(1 2 1 1 1))
+
+  (ought (* 60 60 24 365) '(0 0 0 0 0 1))
+  (ought (+ (* 60 60 24 365) 1)
+         '(1 0 0 0 0 1))
+  (ought (+ (* 60 60 24 365) 60 1)
+         '(1 1 0 0 0 1))
+  (ought (+ (* 60 60 24 365) (* 60 60) 60 1)
+         '(1 1 1 0 0 1))
+  (ought (+ (* 60 60 24 365) (* 60 60 24) (* 60 60) 60 1)
+         '(1 1 1 1 0 1))
+  (ought (+ (* 60 60 24 365)
+            (* 60 60 24 30)
+            (* 60 60 24)
+            (* 60 60)
+            120 1)
+         '(1 2 1 1 1 1))
+
+  (expect wrong-type-argument 'a)
+  (expect wrong-type-argument '(0 a))
+  (expect wrong-type-argument '(0 0 a))
+  (expect wrong-type-argument '(0 0 0 a))
+  (expect wrong-type-argument '(0 0 0 0 a))
+  (expect wrong-type-argument '(0 0 0 0 0 a)))
 
 (provide 'compat-tests)
 ;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index 5f16078804..b92fdbb639 100644
--- a/compat.texi
+++ b/compat.texi
@@ -1011,6 +1011,9 @@ Defined in @code{files.el}.
 
 @defun null-device
 Defined in @code{files.el}.
+
+@defun decoded-time-period
+Defined in @code{time-data.el}.
 @end defun
 
 These functions are prefixed with @code{compat} prefix, and are only loaded
@@ -1143,4 +1146,4 @@ contribution (roughly 15 lines of code) can be applied.
 
 @printindex vr
 
-@bye
\ No newline at end of file
+@bye



reply via email to

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