emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Allen Li <vianchielfaura@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Bug: org-2ft and/or float-time is wrong [9.1.2 (9.1.2-22-ga2a034-elpaplus @ ~/.emacs.d/elpa/org-plus-contrib-20171023/)]
Date: Mon, 30 Oct 2017 21:33:37 -0700	[thread overview]
Message-ID: <CAJr1M6cBkr0RoFLN=P0DL=7JrWvSnM2EnepSyjT-+LvSPQ8ngQ@mail.gmail.com> (raw)
In-Reply-To: <CAJr1M6d5ccgteNjMncKeOVfS3uygkpRte4i2Hem4-WOJEBA51A@mail.gmail.com>

On Mon, Oct 30, 2017 at 5:40 PM, Allen Li <vianchielfaura@gmail.com> wrote:
> (current-time-string (time-to-seconds (org-2ft "<2017-10-31>")))
> "Sun Oct 29 17:00:00 2017"
>
> This seems wrong
>
> In org-2ft
>
> (org-parse-time-string s nil t)
>
> The t means use UTC instead of Emacs local time.
>
> However, Org translates <now> into (float-time), which is in Emacs localtime.
>
> 1. SCHEDULED>"<now>" compares a UTC time against a local time.
> 2. Either org-2ft should be fixed to be localtime, or <now> should be
> (float-time) in UTC.
>
> I don't know how Org internals works, but my experience so far has
> been that Emacs and *nix in general is very naive about timezones; a
> naked timestamp is assumed to be localtime if it does not have
> accompanying timezone information.
>
> Thus, it seems to be more correct to change org-2ft to parse times as
> localtime.  However, I don't know if UTC timestamps are assumed by
> other parts of Org internals, in which case fixing <now> (float-time)
> would be safest.

My initial analysis was wrong because I wasn't thinking clearly.

Just to set a stake in the ground: timestamps are seconds since epoch
and timezone neutral.  Emacs time values are also timezone neutral:
(sec-high sec-low microsec picosec)

(current-time-string (float-time))
"Mon Oct 30 21:21:31 2017" ; right

(current-time-string (org-time-today))
"Mon Oct 30 00:00:00 2017" ; right

(current-time-string (org-2ft "<2017-10-31>"))
"Mon Oct 30 17:00:00 2017" ; wrong

Removing the t for zone fixes it

(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.)))

(current-time-string (org-2ft "<2017-10-31>"))
"Tue Oct 31 00:00:00 2017" ; now right

I will also note that the FIXME comment in org-parse-time-string
suggests that it too is not handling timezones correctly.  In fact,
perhaps org-parse-time-string should not take a zone argument, since
Org does not support timezones thus the only valid value for zone is
nil.  I suspect that org-display-custom-time, another caller that
passes t for zone, is also timezone incorrect.

That is to say, nothing in Org allows passing in a custom timezone,
let alone a UTC timezone; thus, every caller that passes a non-nil
zone to org-parse-time-string is getting an incorrect result.

tl;dr time is hard.

  reply	other threads:[~2017-10-31  4:33 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31  0:40 Bug: org-2ft and/or float-time is wrong [9.1.2 (9.1.2-22-ga2a034-elpaplus @ ~/.emacs.d/elpa/org-plus-contrib-20171023/)] Allen Li
2017-10-31  4:33 ` Allen Li [this message]
2017-10-31 18:23   ` Nicolas Goaziou
2017-10-31 18:35     ` Allen Li
2017-10-31 18:52       ` Nicolas Goaziou
2017-11-01  5:07         ` Allen Li
2017-11-01  5:41           ` Tim Cross
2017-11-01  6:26             ` Allen Li
2017-11-01  7:18               ` Tim Cross
2017-11-01  8:28                 ` Allen Li
2017-11-01 13:09                   ` Tim Cross
2017-11-01 19:14                     ` Allen Li
2017-11-01 19:21                       ` Allen Li
2017-11-02  0:09                         ` Tim Cross
2017-11-02  0:26                           ` Allen Li
2017-11-02  3:27                             ` Tim Cross
2017-11-02  4:05                               ` Allen Li
2017-11-02  4:28                                 ` Allen Li
2017-11-02  4:49                                   ` Allen Li
2017-11-02  4:56                                 ` Tim Cross
2017-11-02  5:12                                   ` Allen Li
2017-11-02 16:19                                     ` Nick Dokos
2017-11-02 19:56                                     ` Tim Cross
2017-11-01 20:55           ` Nicolas Goaziou
2017-11-02  0:10             ` Allen Li
2017-11-02  9:35               ` Nicolas Goaziou
2017-11-02 11:12                 ` Tim Cross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJr1M6cBkr0RoFLN=P0DL=7JrWvSnM2EnepSyjT-+LvSPQ8ngQ@mail.gmail.com' \
    --to=vianchielfaura@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).