summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2019-08-18 10:44:41 -0400
committerKyle Meyer <kyle@kyleam.com>2019-08-18 17:36:12 -0400
commitbdc5861cf726d23cfa6f7f7b0ec2b32219fab99a (patch)
tree78834c750d706dbfeb7a8f9a53bc3ec7613e5671
parent24ba689506afd11148865e992e507ddc801b2913 (diff)
downloadorg-mode-bdc5861cf726d23cfa6f7f7b0ec2b32219fab99a.tar.gz
org-compat: Add kludges for time-related functions
* lisp/org-compat.el (org-decode-time, org-format-time-string) (org-time-add, org-time-less-p, org-time-since, org-time-subtract): New compatibility functions. On Emacs 24, these functions are stricter about what they accept for time. These new function will be used to port over changes in the Emacs repo. Don't bother doing a bulk substitution in existing Org code because that would produce a lot of churn and these calls should already be compatible with Emacs 24.
-rw-r--r--lisp/org-compat.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 2fb623d..7603f96 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -157,6 +157,35 @@ This is a floating point number if the size is too large for an integer."
Case is significant."
(string< s1 s2)))
+;; The time- functions below translate nil to `current-time` and
+;; accept an integer as of Emacs 25. `decode-time` and
+;; `format-time-string` accept nil on Emacs 24 but don't accept an
+;; integer until Emacs 25.
+(if (< emacs-major-version 25)
+ (let ((convert
+ (lambda (time)
+ (cond ((not time) (current-time))
+ ((numberp time) (seconds-to-time time))
+ (t time)))))
+ (defun org-decode-time (&optional time)
+ (decode-time (funcall convert time)))
+ (defun org-format-time-string (format-string &optional time universal)
+ (format-time-string format-string (funcall convert time) universal))
+ (defun org-time-add (a b)
+ (time-add (funcall convert a) (funcall convert b)))
+ (defun org-time-subtract (a b)
+ (time-subtract (funcall convert a) (funcall convert b)))
+ (defun org-time-since (time)
+ (time-since (funcall convert time)))
+ (defun org-time-less-p (t1 t2)
+ (time-less-p (funcall convert t1) (funcall convert t2))))
+ (defalias 'org-decode-time 'decode-time)
+ (defalias 'org-format-time-string 'format-time-string)
+ (defalias 'org-time-add 'time-add)
+ (defalias 'org-time-subtract 'time-subtract)
+ (defalias 'org-time-since 'time-since)
+ (defalias 'org-time-less-p 'time-less-p))
+
;;; Obsolete aliases (remove them after the next major release).