emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: clocktable interprets tstart/tend incorrectly, maybe? [9.0.9 (9.0.9-636-gd39ccc-elpaplus @ /tmp/emacs/.emacs.d/elpa/org-plus-contrib-20170709/)]
@ 2017-07-09 20:46 Dale Sedivec
  2017-07-10  8:59 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Dale Sedivec @ 2017-07-09 20:46 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 7057 bytes --]

Hi!  I think clocktables may be parsing time zones incorrectly in :tstart
and :tend, leading to incorrect output.  Steps to reproduce:

1. Start a fresh Emacs within that same along the lines of:

~~~~~~
mkdir /tmp/emacs
TZ=America/Chicago HOME=/tmp/emacs /path/to/emacs
~~~~~~

I *think* setting TZ to a non-UTC time zone is important to reproduce this.

2. Install latest org-mode from Git.  I did this via package-install-file
on a package I built from a Git checkout of the org-mode repository.

3. Open an org-mode buffer, e.g. C-x C-f ~/test.org RET.

4. Insert:

~~~~~~
#+BEGIN: clocktable :maxlevel 2 :scope file :step day :tstart "<2017-07-02
Sun>" :tend "<2017-07-09 Sun>"
#+END:
~~~~~~

5. Save the buffer.

6. Move point to the start of that dblock and C-c C-c to update it.

Expected results: First step is "Daily report: [2017-07-02 Sun]" which
matches the :tstart.

Actual results: First step is "Daily report: [2017-07-01 Sat]", the day
before the :tstart date.  The last step is also 2017-07-07, not 2017-07-08
as I was expecting.

I notice that as of 112c5ba479d, org-clocktable-steps parses :tstart and
:tend with the ZONE argument to org-parse-time-string as T.  I think this
is causing org-parse-time-string to parse these user-entered dates as UTC
rather than the user's local time as I would have expected.  Changing
org-clocktable-steps from doing (org-parse-time-string ts nil t)
to (org-parse-time-string ts nil nil), and then the same for te as well,
seems to fix this problem.

But time/date math is hard, and this is just a guess as to where the
problem might lie.

Emacs  : GNU Emacs 25.2.1 (x86_64-apple-darwin15.6.0, NS appkit-1404.47
Version 10.11.6 (Build 15G1421))
 of 2017-04-24
Package: Org mode version 9.0.9 (9.0.9-636-gd39ccc-elpaplus @
/tmp/emacs/.emacs.d/elpa/org-plus-contrib-20170709/)

current state:
==============
(setq
 org-src-lang-modes '(("sclang" . sclang) ("ocaml" . tuareg)
     ("elisp" . emacs-lisp) ("ditaa" . artist)
     ("asymptote" . asy) ("dot" . fundamental)
     ("sqlite" . sql) ("calc" . fundamental) ("C" . c)
     ("cpp" . c++) ("C++" . c++) ("screen" . shell-script)
     ("shell" . sh) ("bash" . sh))
 org-tab-first-hook '(org-babel-hide-result-toggle-maybe
     org-babel-header-arg-expand)
 org-speed-command-hook '(org-speed-command-activate
 org-babel-speed-command-activate)
 org-occur-hook '(org-first-headline-recenter)
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-html-format-drawer-function '(closure
  (htmlize-buffer-places
   org-html-format-table-no-css
   htmlize-css-name-prefix
   htmlize-output-type htmlize-output-type
   htmlize-css-name-prefix t)
  (_name contents) contents)
 org-latex-format-inlinetask-function
'org-latex-format-inlinetask-default-function
 org-confirm-shell-link-function 'yes-or-no-p
 org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default
 org-latex-format-headline-function
'org-latex-format-headline-default-function
 org-after-todo-state-change-hook '(org-clock-out-if-current)
 org-latex-format-drawer-function '(closure (t) (_ contents) contents)
 org-odt-format-headline-function 'org-odt-format-headline-default-function
 org-src-mode-hook '(org-src-babel-configure-edit-buffer
    org-src-mode-configure-edit-buffer)
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-babel-pre-tangle-hook '(save-buffer)
 org-mode-hook '(#[0 "\300\301\302\303\304$\207"
  [add-hook change-major-mode-hook org-show-block-all append
   local]
  5]
#[0 "\300\301\302\303\304$\207"
  [add-hook change-major-mode-hook org-babel-show-result-all
   append local]
  5]
(closure
 (org-inlinetask-min-level buffer-face-mode-face org-mode-map
  org-tbl-menu org-org-menu org-struct-menu org-entities
  org-last-state org-id-track-globally org-clock-start-time
  texmathp-why remember-data-file
  org-agenda-tags-todo-honor-ignore-options
  iswitchb-temp-buflist align-mode-rules-list
  org-emphasis-alist org-emphasis-regexp-components
  org-export-registered-backends org-modules
  org-babel-load-languages ffap-url-regexp t)
 nil
 (add-hook (quote change-major-mode-hook)
  (quote org-show-block-all) (quote append) (quote local))
 )
(closure
 (org-bracket-link-regexp org-src-window-setup *this*
  org-babel-confirm-evaluate-answer-no
  org-src-preserve-indentation org-src-lang-modes
  org-edit-src-content-indentation org-babel-library-of-babel
  t)
 nil
 (add-hook (quote change-major-mode-hook)
  (quote org-babel-show-result-all) (quote append)
  (quote local))
 )
org-babel-result-hide-spec org-babel-hide-all-hashes
org-eldoc-load)
 org-bibtex-headline-format-function '(closure
      (org-agenda-search-view-always-boolean
org-agenda-overriding-header t)
      (entry) (cdr (assq :title entry)))
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-ascii-format-drawer-function '(closure (t) (_name contents _width)
   contents)
 org-odt-format-inlinetask-function
'org-odt-format-inlinetask-default-function
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers
 org-cycle-show-empty-lines
 org-optimize-window-after-visibility-change)
 org-confirm-elisp-link-function 'yes-or-no-p
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-odt-format-drawer-function '(closure
 (hfy-user-sheet-assoc hfy-html-quote-regex
  hfy-html-quote-map hfy-face-to-css
  hfy-begin-span-handler hfy-end-span-handler
  archive-zip-extract
  nxml-auto-insert-xml-declaration-flag t)
 (_name contents) contents)
 org-html-format-headline-function
'org-html-format-headline-default-function
 org-link-parameters '(("rmail" :follow org-rmail-open :store
org-rmail-store-link)
      ("mhe" :follow org-mhe-open :store org-mhe-store-link)
      ("irc" :follow org-irc-visit :store org-irc-store-link)
      ("info" :follow org-info-open :export org-info-export
:store org-info-store-link)
      ("gnus" :follow org-gnus-open :store
org-gnus-store-link)
      ("docview" :follow org-docview-open :export
org-docview-export :store org-docview-store-link)
      ("bbdb" :follow org-bbdb-open :export org-bbdb-export
:complete org-bbdb-complete-link :store
org-bbdb-store-link)
      ("w3m" :store org-w3m-store-link)
      ("bibtex" :follow org-bibtex-open :store
org-bibtex-store-link)
      ("id" :follow org-id-open) ("file+sys") ("file+emacs")
      ("doi" :follow org--open-doi-link)
      ("elisp" :follow org--open-elisp-link)
      ("file" :complete org-file-complete-link)
      ("ftp" :follow
(lambda (path) (browse-url (concat "ftp:" path))))
      ("help" :follow org--open-help-link)
      ("http" :follow
(lambda (path) (browse-url (concat "http:" path))))
      ("https" :follow
(lambda (path) (browse-url (concat "https:" path))))
      ("mailto" :follow
(lambda (path) (browse-url (concat "mailto:" path))))
      ("news" :follow
(lambda (path) (browse-url (concat "news:" path))))
      ("shell" :follow org--open-shell-link))
 org-html-format-inlinetask-function
'org-html-format-inlinetask-default-function
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 )

Regards,
Dale

[-- Attachment #2: Type: text/html, Size: 13297 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug: clocktable interprets tstart/tend incorrectly, maybe? [9.0.9 (9.0.9-636-gd39ccc-elpaplus @ /tmp/emacs/.emacs.d/elpa/org-plus-contrib-20170709/)]
  2017-07-09 20:46 Bug: clocktable interprets tstart/tend incorrectly, maybe? [9.0.9 (9.0.9-636-gd39ccc-elpaplus @ /tmp/emacs/.emacs.d/elpa/org-plus-contrib-20170709/)] Dale Sedivec
@ 2017-07-10  8:59 ` Nicolas Goaziou
  2017-07-15  6:15   ` Dale Sedivec
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2017-07-10  8:59 UTC (permalink / raw)
  To: Dale Sedivec; +Cc: emacs-orgmode

Hello,

Dale Sedivec <dale@codefu.org> writes:

> Hi!  I think clocktables may be parsing time zones incorrectly in :tstart
> and :tend, leading to incorrect output.  Steps to reproduce:
>
> 1. Start a fresh Emacs within that same along the lines of:
>
> ~~~~~~
> mkdir /tmp/emacs
> TZ=America/Chicago HOME=/tmp/emacs /path/to/emacs
> ~~~~~~
>
> I *think* setting TZ to a non-UTC time zone is important to reproduce this.
>
> 2. Install latest org-mode from Git.  I did this via package-install-file
> on a package I built from a Git checkout of the org-mode repository.
>
> 3. Open an org-mode buffer, e.g. C-x C-f ~/test.org RET.
>
> 4. Insert:
>
> ~~~~~~
>
> #+BEGIN: clocktable :maxlevel 2 :scope file :step day :tstart "<2017-07-02
> Sun>" :tend "<2017-07-09 Sun>"
>
> #+END:
> ~~~~~~
>
> 5. Save the buffer.
>
> 6. Move point to the start of that dblock and C-c C-c to update it.
>
> Expected results: First step is "Daily report: [2017-07-02 Sun]" which
> matches the :tstart.
>
> Actual results: First step is "Daily report: [2017-07-01 Sat]", the day
> before the :tstart date.  The last step is also 2017-07-07, not 2017-07-08
> as I was expecting.
>
> I notice that as of 112c5ba479d, org-clocktable-steps parses :tstart and
> :tend with the ZONE argument to org-parse-time-string as T.  I think this
> is causing org-parse-time-string to parse these user-entered dates as UTC
> rather than the user's local time as I would have expected.  Changing
> org-clocktable-steps from doing (org-parse-time-string ts nil t)
> to (org-parse-time-string ts nil nil), and then the same for te as well,
> seems to fix this problem.

Fixed. Thank you for the report and the analysis.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug: clocktable interprets tstart/tend incorrectly, maybe? [9.0.9 (9.0.9-636-gd39ccc-elpaplus @ /tmp/emacs/.emacs.d/elpa/org-plus-contrib-20170709/)]
  2017-07-10  8:59 ` Nicolas Goaziou
@ 2017-07-15  6:15   ` Dale Sedivec
  2017-07-24  7:43     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Dale Sedivec @ 2017-07-15  6:15 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1630 bytes --]

On Mon, Jul 10, 2017 at 3:59 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Dale Sedivec <dale@codefu.org> writes:
>
[...]

> > I notice that as of 112c5ba479d, org-clocktable-steps parses :tstart and
> > :tend with the ZONE argument to org-parse-time-string as T.  I think this
> > is causing org-parse-time-string to parse these user-entered dates as UTC
> > rather than the user's local time as I would have expected.  Changing
> > org-clocktable-steps from doing (org-parse-time-string ts nil t)
> > to (org-parse-time-string ts nil nil), and then the same for te as well,
> > seems to fix this problem.
>
> Fixed. Thank you for the report and the analysis.
>

Thank you as always Nicolas!  You fixed the time zone for :tstart in
60eda8e4ec4.  However, I think the parsing of :tend (locally bound as te)
eight lines below that needs the same fix.  Diff attached this time, just
to demonstrate what I'm talking about.  (Sorry I don't send more patches,
but I have not updated my copyright assignment to reflect my new employer.)

Steps to reproduce:

* Start Emacs 25.1 in an empty $HOME with TZ=America/Chicago

* Install org-mode HEAD

* Insert the following into an org-mode buffer and update the dblock:

~~~~~~
* Test
  :LOGBOOK:
  CLOCK: [2017-07-15 Sat 00:01]--[2017-07-15 Sat 01:01] =>  1:00
  :END:
#+BEGIN: clocktable :maxlevel 2 :scope subtree :tstart "<2017-07-09 Sun>"
:tend "<2017-07-16 Sun>" :step day
#+END:
~~~~~~

Expected result: The last step in the clock table for 2017-07-15 shows 1
hour

Actual result: The last step in the clock table for 2017-07-15 shows 0 hours

Thanks again,
Dale

[-- Attachment #1.2: Type: text/html, Size: 2623 bytes --]

[-- Attachment #2: org-clocktable-end-fix.diff --]
[-- Type: text/plain, Size: 659 bytes --]

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 8e04aec2dd..4164c92aba 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2710,8 +2710,7 @@ LEVEL is an integer.  Indent by two spaces per level above 1."
       (pcase-let ((`(,month ,day ,year) (calendar-gregorian-from-absolute te)))
 	(setq te (float-time (encode-time 0 0 0 day month year)))))
      (te
-      (setq te (float-time
-		(apply #'encode-time (org-parse-time-string te nil t))))))
+      (setq te (float-time (apply #'encode-time (org-parse-time-string te))))))
     (setq tsb
 	  (if (eq step0 'week)
 	      (- ts (* 86400 (- (nth 6 (decode-time (seconds-to-time ts))) ws)))

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Bug: clocktable interprets tstart/tend incorrectly, maybe? [9.0.9 (9.0.9-636-gd39ccc-elpaplus @ /tmp/emacs/.emacs.d/elpa/org-plus-contrib-20170709/)]
  2017-07-15  6:15   ` Dale Sedivec
@ 2017-07-24  7:43     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2017-07-24  7:43 UTC (permalink / raw)
  To: Dale Sedivec; +Cc: emacs-orgmode

Hello,

Dale Sedivec <dale@codefu.org> writes:

> Thank you as always Nicolas!  You fixed the time zone for :tstart in
> 60eda8e4ec4.  However, I think the parsing of :tend (locally bound as te)
> eight lines below that needs the same fix.

Oops! Fixed. Thank you.

Regards,

-- 
Nicolas Goaziou                                                0x80A93738

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-24  7:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-09 20:46 Bug: clocktable interprets tstart/tend incorrectly, maybe? [9.0.9 (9.0.9-636-gd39ccc-elpaplus @ /tmp/emacs/.emacs.d/elpa/org-plus-contrib-20170709/)] Dale Sedivec
2017-07-10  8:59 ` Nicolas Goaziou
2017-07-15  6:15   ` Dale Sedivec
2017-07-24  7:43     ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).