forked from mirrors/org-mode
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
This commit is contained in:
parent
1171d5ef0c
commit
ff3f3876a8
|
@ -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 "<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
|
||||
|
||||
|
|
42
lisp/org.el
42
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))
|
||||
|
|
Loading…
Reference in New Issue