From ff3f3876a8d6b132e911f095639d0c2813551202 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 17 Apr 2018 16:06:09 +0200 Subject: [PATCH] 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 --- lisp/org-macs.el | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 42 +------------------------------ 2 files changed, 66 insertions(+), 41 deletions(-) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 63457819f..a087c080b 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -857,6 +857,71 @@ return nil." (+ (if (bolp) 1 0) (count-lines 1 (point))))) + +;;; 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 "") (float-time)) + ((string= s "") today) + ((string= s "") (+ 86400.0 today)) + ((string= s "") (- 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 diff --git a/lisp/org.el b/lisp/org.el index 01149ed32..39d98ea9e 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 "") (float-time)) - ((string= s "") (org-time-today)) - ((string= s "") (+ 86400.0 (org-time-today))) - ((string= s "") (- (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))