Revert the whole time zone mess

* lisp/org.el (org-time-string-to-time):
(org-time-string-to-seconds): Remove optional ZONE argument.
(org-2ft):
(org-check-before-date):
(org-check-after-date):
(org-check-dates-range):
(org-parse-time-string):
* lisp/org-clock.el (org-clock-get-sum-start):
(org-clock-out):
(org-clock-timestamps-change):
(org-clock-sum):
(org-clock-update-time-maybe):
* lisp/org-colview.el (org-columns--age-to-minutes): Apply change.
* testing/lisp/test-org-clock.el (org-test-clock-create-clock):
(test-org-clock/clocktable/scope):
* testing/lisp/test-org-colview.el (test-org-colview/columns-summary):
  Apply change.  Simplify tests to avoid daylight saving time issue.
This commit is contained in:
Nicolas Goaziou 2017-12-03 08:57:37 +01:00
parent 14620fdf0c
commit 2faaacfeeb
8 changed files with 49 additions and 63 deletions

View File

@ -492,9 +492,6 @@ It used to be ~@samp~ but ~@asis~ is neutral and, therefore, more
suitable as a default value. suitable as a default value.
*** Texinfo default process includes ~--no-split~ option *** Texinfo default process includes ~--no-split~ option
*** New entities : ~\dollar~ and ~\USD~ *** New entities : ~\dollar~ and ~\USD~
*** ~org-parse-time-string~ accepts a new optional argument
=ZONE= specifies the current time zone.
*** ~org-time-string-to-seconds~ now accepts an optional =ZONE= argument
*** Support for date style URLs in =org-protocol://open-source= *** Support for date style URLs in =org-protocol://open-source=
URLs like =https://cool-blog.com/2017/05/20/cool-post/= are URLs like =https://cool-blog.com/2017/05/20/cool-post/= are
covered by rewrite rules. covered by rewrite rules.

View File

@ -40,7 +40,7 @@
;;; Code: ;;; Code:
(require 'ob) (require 'ob)
(declare-function org-time-string-to-time "org" (s &optional zone)) (declare-function org-time-string-to-time "org" (s))
(declare-function org-combine-plists "org" (&rest plists)) (declare-function org-combine-plists "org" (&rest plists))
(declare-function orgtbl-to-generic "org-table" (table params)) (declare-function orgtbl-to-generic "org-table" (table params))
(declare-function gnuplot-mode "ext:gnuplot-mode" ()) (declare-function gnuplot-mode "ext:gnuplot-mode" ())

View File

@ -1467,7 +1467,7 @@ The time is always returned as UTC."
(and (or (not cmt) (equal cmt "auto")) (and (or (not cmt) (equal cmt "auto"))
lr)) lr))
(setq org--msg-extra "showing task time since last repeat.") (setq org--msg-extra "showing task time since last repeat.")
(and lr (org-time-string-to-time lr t))) (and lr (org-time-string-to-time lr)))
(t nil)))) (t nil))))
(defun org-clock-find-position (find-unclosed) (defun org-clock-find-position (find-unclosed)
@ -1604,9 +1604,9 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
(insert "--") (insert "--")
(setq te (org-insert-time-stamp (or at-time now) 'with-hm 'inactive)) (setq te (org-insert-time-stamp (or at-time now) 'with-hm 'inactive))
(setq s (- (float-time (setq s (- (float-time
(apply #'encode-time (org-parse-time-string te nil t))) (apply #'encode-time (org-parse-time-string te)))
(float-time (float-time
(apply #'encode-time (org-parse-time-string ts nil t)))) (apply #'encode-time (org-parse-time-string ts))))
h (floor (/ s 3600)) h (floor (/ s 3600))
s (- s (* 3600 h)) s (- s (* 3600 h))
m (floor (/ s 60)) m (floor (/ s 60))
@ -1711,8 +1711,8 @@ Optional argument N tells to change by that many units."
(begts (if updatets1 begts1 begts2))) (begts (if updatets1 begts1 begts2)))
(setq tdiff (setq tdiff
(time-subtract (time-subtract
(org-time-string-to-time org-last-changed-timestamp t) (org-time-string-to-time org-last-changed-timestamp)
(org-time-string-to-time ts t))) (org-time-string-to-time ts)))
(save-excursion (save-excursion
(goto-char begts) (goto-char begts)
(org-timestamp-change (org-timestamp-change
@ -1820,10 +1820,10 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes."
(lmax 30) (lmax 30)
(ltimes (make-vector lmax 0)) (ltimes (make-vector lmax 0))
(level 0) (level 0)
(tstart (cond ((stringp tstart) (org-time-string-to-seconds tstart t)) (tstart (cond ((stringp tstart) (org-time-string-to-seconds tstart))
((consp tstart) (float-time tstart)) ((consp tstart) (float-time tstart))
(t tstart))) (t tstart)))
(tend (cond ((stringp tend) (org-time-string-to-seconds tend t)) (tend (cond ((stringp tend) (org-time-string-to-seconds tend))
((consp tend) (float-time tend)) ((consp tend) (float-time tend))
(t tend))) (t tend)))
(t1 0) (t1 0)
@ -1840,11 +1840,10 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes."
(let* ((ts (float-time (let* ((ts (float-time
(apply #'encode-time (apply #'encode-time
(save-match-data (save-match-data
(org-parse-time-string (org-parse-time-string (match-string 2))))))
(match-string 2) nil t)))))
(te (float-time (te (float-time
(apply #'encode-time (apply #'encode-time
(org-parse-time-string (match-string 3) nil t)))) (org-parse-time-string (match-string 3)))))
(dt (- (if tend (min te tend) te) (dt (- (if tend (min te tend) te)
(if tstart (max ts tstart) ts)))) (if tstart (max ts tstart) ts))))
(when (> dt 0) (cl-incf t1 (floor (/ dt 60)))))) (when (> dt 0) (cl-incf t1 (floor (/ dt 60))))))
@ -2902,9 +2901,9 @@ Otherwise, return nil."
(setq ts (match-string 1) (setq ts (match-string 1)
te (match-string 3)) te (match-string 3))
(setq s (- (float-time (setq s (- (float-time
(apply #'encode-time (org-parse-time-string te nil t))) (apply #'encode-time (org-parse-time-string te)))
(float-time (float-time
(apply #'encode-time (org-parse-time-string ts nil t)))) (apply #'encode-time (org-parse-time-string ts))))
neg (< s 0) neg (< s 0)
s (abs s) s (abs s)
h (floor (/ s 3600)) h (floor (/ s 3600))

View File

@ -1070,7 +1070,7 @@ as a canonical duration, i.e., using units defined in
(cond (cond
((string-match-p org-ts-regexp s) ((string-match-p org-ts-regexp s)
(/ (- org-columns--time (/ (- org-columns--time
(float-time (apply #'encode-time (org-parse-time-string s nil t)))) (float-time (apply #'encode-time (org-parse-time-string s))))
60)) 60))
((org-duration-p s) (org-duration-to-minutes s t)) ;skip user units ((org-duration-p s) (org-duration-to-minutes s t)) ;skip user units
(t (user-error "Invalid age: %S" s)))) (t (user-error "Invalid age: %S" s))))

View File

@ -149,7 +149,7 @@
(declare-function org-remove-indentation "org" (code &optional n)) (declare-function org-remove-indentation "org" (code &optional n))
(declare-function org-show-subtree "org" ()) (declare-function org-show-subtree "org" ())
(declare-function org-sort-remove-invisible "org" (S)) (declare-function org-sort-remove-invisible "org" (S))
(declare-function org-time-string-to-seconds "org" (s &optional zone)) (declare-function org-time-string-to-seconds "org" (s))
(declare-function org-timer-hms-to-secs "org-timer" (hms)) (declare-function org-timer-hms-to-secs "org-timer" (hms))
(declare-function org-timer-item "org-timer" (&optional arg)) (declare-function org-timer-item "org-timer" (&optional arg))
(declare-function org-trim "org" (s &optional keep-lead)) (declare-function org-trim "org" (s &optional keep-lead))

View File

@ -14632,7 +14632,7 @@ it as a time string and apply `float-time' to it. If S is nil, just return 0."
((numberp s) s) ((numberp s) s)
((stringp s) ((stringp s)
(condition-case nil (condition-case nil
(float-time (apply #'encode-time (org-parse-time-string s nil t))) (float-time (apply #'encode-time (org-parse-time-string s)))
(error 0.))) (error 0.)))
(t 0.))) (t 0.)))
@ -17391,8 +17391,8 @@ both scheduled and deadline timestamps."
'timestamp) 'timestamp)
(org-at-planning-p)) (org-at-planning-p))
(time-less-p (time-less-p
(org-time-string-to-time match t) (org-time-string-to-time match)
(org-time-string-to-time d t))))))) (org-time-string-to-time d)))))))
(message "%d entries before %s" (message "%d entries before %s"
(org-occur regexp nil callback) (org-occur regexp nil callback)
d))) d)))
@ -17413,8 +17413,8 @@ both scheduled and deadline timestamps."
'timestamp) 'timestamp)
(org-at-planning-p)) (org-at-planning-p))
(not (time-less-p (not (time-less-p
(org-time-string-to-time match t) (org-time-string-to-time match)
(org-time-string-to-time d t)))))))) (org-time-string-to-time d))))))))
(message "%d entries after %s" (message "%d entries after %s"
(org-occur regexp nil callback) (org-occur regexp nil callback)
d))) d)))
@ -17437,11 +17437,11 @@ both scheduled and deadline timestamps."
'timestamp) 'timestamp)
(org-at-planning-p)) (org-at-planning-p))
(not (time-less-p (not (time-less-p
(org-time-string-to-time match t) (org-time-string-to-time match)
(org-time-string-to-time start-date t))) (org-time-string-to-time start-date)))
(time-less-p (time-less-p
(org-time-string-to-time match t) (org-time-string-to-time match)
(org-time-string-to-time end-date t)))))))) (org-time-string-to-time end-date))))))))
(message "%d entries between %s and %s" (message "%d entries between %s and %s"
(org-occur regexp nil callback) start-date end-date))) (org-occur regexp nil callback) start-date end-date)))
@ -17526,19 +17526,13 @@ days in order to avoid rounding problems."
(push m l)) (push m l))
(apply 'format fmt (nreverse l)))) (apply 'format fmt (nreverse l))))
(defun org-time-string-to-time (s &optional zone) (defun org-time-string-to-time (s)
"Convert timestamp string S into internal time. "Convert timestamp string S into internal time."
The optional ZONE is omitted or nil for Emacs local time, t for (apply #'encode-time (org-parse-time-string s)))
Universal Time, wall for system wall clock time, or a string as
in the TZ environment variable."
(apply #'encode-time (org-parse-time-string s nil zone)))
(defun org-time-string-to-seconds (s &optional zone) (defun org-time-string-to-seconds (s)
"Convert a timestamp string S into a number of seconds. "Convert a timestamp string S into a number of seconds."
The optional ZONE is omitted or nil for Emacs local time, t for (float-time (org-time-string-to-time s)))
Universal Time, wall for system wall clock time, or a string as
in the TZ environment variable."
(float-time (org-time-string-to-time s zone)))
(org-define-error 'org-diary-sexp-no-match "Unable to match diary sexp") (org-define-error 'org-diary-sexp-no-match "Unable to match diary sexp")
@ -17755,17 +17749,13 @@ day number."
(list (nth 4 d) (nth 3 d) (nth 5 d)))) (list (nth 4 d) (nth 3 d) (nth 5 d))))
((listp d) (list (nth 4 d) (nth 3 d) (nth 5 d))))) ((listp d) (list (nth 4 d) (nth 3 d) (nth 5 d)))))
(defun org-parse-time-string (s &optional nodefault zone) (defun org-parse-time-string (s &optional nodefault)
"Parse the standard Org time string. "Parse the standard Org time string.
This should be a lot faster than the normal `parse-time-string'. This should be a lot faster than the normal `parse-time-string'.
If time is not given, defaults to 0:00. However, with optional If time is not given, defaults to 0:00. However, with optional
NODEFAULT, hour and minute fields will be nil if not given. NODEFAULT, hour and minute fields will be nil if not given."
The optional ZONE is omitted or nil for Emacs local time, t for
Universal Time, wall for system wall clock time, or a string as
in the TZ environment variable."
(cond ((string-match org-ts-regexp0 s) (cond ((string-match org-ts-regexp0 s)
(list 0 (list 0
(when (or (match-beginning 8) (not nodefault)) (when (or (match-beginning 8) (not nodefault))
@ -17775,7 +17765,7 @@ in the TZ environment variable."
(string-to-number (match-string 4 s)) (string-to-number (match-string 4 s))
(string-to-number (match-string 3 s)) (string-to-number (match-string 3 s))
(string-to-number (match-string 2 s)) (string-to-number (match-string 2 s))
nil nil zone)) nil nil nil))
((string-match "^<[^>]+>$" s) ((string-match "^<[^>]+>$" s)
;; FIXME: `decode-time' needs to be called with ZONE as its ;; FIXME: `decode-time' needs to be called with ZONE as its
;; second argument. However, this requires at least Emacs ;; second argument. However, this requires at least Emacs

View File

@ -49,8 +49,8 @@ Return the clock line as a string."
(let* ((beg (org-test-clock-create-timestamp input1 t t)) (let* ((beg (org-test-clock-create-timestamp input1 t t))
(end (and input2 (org-test-clock-create-timestamp input2 t t))) (end (and input2 (org-test-clock-create-timestamp input2 t t)))
(sec-diff (and input2 (sec-diff (and input2
(floor (- (org-time-string-to-seconds end t) (floor (- (org-time-string-to-seconds end)
(org-time-string-to-seconds beg t)))))) (org-time-string-to-seconds beg))))))
(concat org-clock-string " " beg (concat org-clock-string " " beg
(when end (when end
(concat "--" end " => " (concat "--" end " => "
@ -344,15 +344,15 @@ the buffer."
;; line, and ignore "file" column. ;; line, and ignore "file" column.
(should (should
(equal (equal
"| Headline | Time | | "| Headline | Time | |
|--------------+------------+-----| |--------------+--------+-----|
| *Total time* | *16904:01* | foo | | *Total time* | *8:40* | foo |
|--------------+------------+-----| |--------------+--------+-----|
| Test | 16904:01 | foo | | Test | 8:40 | foo |
#+TBLFM: $3=string(\"foo\")" #+TBLFM: $3=string(\"foo\")"
(org-test-with-temp-text-in-file (org-test-with-temp-text-in-file
"* Test "* Test
CLOCK: [2012-03-29 Thu 16:40]--[2014-03-04 Thu 00:41] => 16904:01" CLOCK: [2012-03-29 Thu 8:00]--[2012-03-29 Thu 16:40] => 8:40"
(test-org-clock-clocktable-contents ":scope file-with-archives" (test-org-clock-clocktable-contents ":scope file-with-archives"
"#+TBLFM: $3=string(\"foo\")")))) "#+TBLFM: $3=string(\"foo\")"))))
;; Test "function" scope. ;; Test "function" scope.

View File

@ -513,7 +513,7 @@
(cl-letf (((symbol-function 'current-time) (cl-letf (((symbol-function 'current-time)
(lambda () (lambda ()
(apply #'encode-time (apply #'encode-time
(org-parse-time-string "<2014-03-04 Tue>" nil t))))) (org-parse-time-string "<2014-03-04 Tue>")))))
(org-test-with-temp-text (org-test-with-temp-text
"* H "* H
** S1 ** S1
@ -528,39 +528,39 @@
(get-char-property (point) 'org-columns-value-modified))))) (get-char-property (point) 'org-columns-value-modified)))))
(should (should
(equal (equal
"705d" "2d"
(cl-letf (((symbol-function 'current-time) (cl-letf (((symbol-function 'current-time)
(lambda () (lambda ()
(apply #'encode-time (apply #'encode-time
(org-parse-time-string "<2014-03-04 Tue>" nil t))))) (org-parse-time-string "<2014-03-04 Tue>")))))
(org-test-with-temp-text (org-test-with-temp-text
"* H "* H
** S1 ** S1
:PROPERTIES: :PROPERTIES:
:A: <2012-03-29 Thu> :A: <2014-03-03 Mon>
:END: :END:
** S1 ** S1
:PROPERTIES: :PROPERTIES:
:A: <2014-03-04 Tue> :A: <2014-03-02 Sun>
:END:" :END:"
(let ((org-columns-default-format "%A{@max}")) (org-columns)) (let ((org-columns-default-format "%A{@max}")) (org-columns))
(get-char-property (point) 'org-columns-value-modified))))) (get-char-property (point) 'org-columns-value-modified)))))
(should (should
(equal (equal
"352d 12h" "1d 12h"
(cl-letf (((symbol-function 'current-time) (cl-letf (((symbol-function 'current-time)
(lambda () (lambda ()
(apply #'encode-time (apply #'encode-time
(org-parse-time-string "<2014-03-04 Tue>" nil t))))) (org-parse-time-string "<2014-03-04 Tue>")))))
(org-test-with-temp-text (org-test-with-temp-text
"* H "* H
** S1 ** S1
:PROPERTIES: :PROPERTIES:
:A: <2012-03-29 Thu> :A: <2014-03-03 Mon>
:END: :END:
** S1 ** S1
:PROPERTIES: :PROPERTIES:
:A: <2014-03-04 Tue> :A: <2014-03-02 Sun>
:END:" :END:"
(let ((org-columns-default-format "%A{@mean}")) (org-columns)) (let ((org-columns-default-format "%A{@mean}")) (org-columns))
(get-char-property (point) 'org-columns-value-modified))))) (get-char-property (point) 'org-columns-value-modified)))))