summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-04-17 16:06:09 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-04-17 16:06:09 +0200
commitff3f3876a8d6b132e911f095639d0c2813551202 (patch)
tree027b483ead682648cf01ea3268f85517ef490718
parent1171d5ef0c183721d961ddc3499739eb70bc53ed (diff)
downloadorg-mode-ff3f3876a8d6b132e911f095639d0c2813551202.tar.gz
Move time related functions from "org.el" to "org-macs.el"
* lisp/org.el (org-2ft): (org-time=): (org-time<): (org-time<=): (org-time>): (org-time>=): (org-time<>): (org-matcher-time): Move from here to... * lisp/org-macs.el: ... here
-rw-r--r--lisp/org-macs.el65
-rw-r--r--lisp/org.el42
2 files changed, 66 insertions, 41 deletions
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 6345781..a087c08 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -858,6 +858,71 @@ return nil."
+;;; Time
+
+(defun org-2ft (s)
+ "Convert S to a floating point time.
+If S is already a number, just return it. If it is a string,
+parse it as a time string and apply `float-time' to it. If S is
+nil, just return 0."
+ (cond
+ ((numberp s) s)
+ ((stringp s)
+ (condition-case nil
+ (float-time (apply #'encode-time (org-parse-time-string s)))
+ (error 0.)))
+ (t 0.)))
+
+(defun org-time= (a b)
+ (let ((a (org-2ft a))
+ (b (org-2ft b)))
+ (and (> a 0) (> b 0) (= a b))))
+
+(defun org-time< (a b)
+ (let ((a (org-2ft a))
+ (b (org-2ft b)))
+ (and (> a 0) (> b 0) (< a b))))
+
+(defun org-time<= (a b)
+ (let ((a (org-2ft a))
+ (b (org-2ft b)))
+ (and (> a 0) (> b 0) (<= a b))))
+
+(defun org-time> (a b)
+ (let ((a (org-2ft a))
+ (b (org-2ft b)))
+ (and (> a 0) (> b 0) (> a b))))
+
+(defun org-time>= (a b)
+ (let ((a (org-2ft a))
+ (b (org-2ft b)))
+ (and (> a 0) (> b 0) (>= a b))))
+
+(defun org-time<> (a b)
+ (let ((a (org-2ft a))
+ (b (org-2ft b)))
+ (and (> a 0) (> b 0) (\= a b))))
+
+(defun org-matcher-time (s)
+ "Interpret a time comparison value S."
+ (let ((today (float-time (apply #'encode-time
+ (append '(0 0 0) (nthcdr 3 (decode-time)))))))
+ (save-match-data
+ (cond
+ ((string= s "<now>") (float-time))
+ ((string= s "<today>") today)
+ ((string= s "<tomorrow>") (+ 86400.0 today))
+ ((string= s "<yesterday>") (- today 86400.0))
+ ((string-match "\\`<\\([-+][0-9]+\\)\\([hdwmy]\\)>\\'" s)
+ (+ today
+ (* (string-to-number (match-string 1 s))
+ (cdr (assoc (match-string 2 s)
+ '(("d" . 86400.0) ("w" . 604800.0)
+ ("m" . 2678400.0) ("y" . 31557600.0)))))))
+ (t (org-2ft s))))))
+
+
+
;;; Text properties
(defconst org-rm-props '(invisible t face t keymap t intangible t mouse-face t
diff --git a/lisp/org.el b/lisp/org.el
index 01149ed..39d98ea 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14141,47 +14141,7 @@ When DOWNCASE is non-nil, expand downcased TAGS."
((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
(nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
-(defun org<> (a b) (not (= a b)))
-(defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
-(defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
-(defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
-(defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
-(defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
-(defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
-(defun org-2ft (s)
- "Convert S to a floating point time.
-If S is already a number, just return it. If it is a string, parse
-it as a time string and apply `float-time' to it. If S is nil, just return 0."
- (cond
- ((numberp s) s)
- ((stringp s)
- (condition-case nil
- (float-time (apply #'encode-time (org-parse-time-string s)))
- (error 0.)))
- (t 0.)))
-
-(defun org-time-today ()
- "Time in seconds today at 0:00.
-Returns the float number of seconds since the beginning of the
-epoch to the beginning of today (00:00)."
- (float-time (apply 'encode-time
- (append '(0 0 0) (nthcdr 3 (decode-time))))))
-
-(defun org-matcher-time (s)
- "Interpret a time comparison value."
- (save-match-data
- (cond
- ((string= s "<now>") (float-time))
- ((string= s "<today>") (org-time-today))
- ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
- ((string= s "<yesterday>") (- (org-time-today) 86400.0))
- ((string-match "^<\\([-+][0-9]+\\)\\([hdwmy]\\)>$" s)
- (+ (org-time-today)
- (* (string-to-number (match-string 1 s))
- (cdr (assoc (match-string 2 s)
- '(("d" . 86400.0) ("w" . 604800.0)
- ("m" . 2678400.0) ("y" . 31557600.0)))))))
- (t (org-2ft s)))))
+(defun org<> (a b) (/= a b))
(defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
(defvar org-tags-overlay (make-overlay 1 1))