emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: Eric S Fraga <e.fraga@ucl.ac.uk>
Cc: nicholas.dokos@hp.com,
	Emacs Org mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: dates before 1970
Date: Thu, 10 Mar 2011 18:06:33 -0500	[thread overview]
Message-ID: <5422.1299798393@alphaville.usa.hp.com> (raw)
In-Reply-To: Message from Eric S Fraga <e.fraga@ucl.ac.uk> of "Thu, 10 Mar 2011 21:00:16 GMT." <87ei6en127.fsf@ucl.ac.uk>

Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

> This is a sort of bug report but possibly more a curiosity...
> 
> I imagine this has something to do with time 0 in Unix but I cannot seem
> to be able to enter any date earlier than 1 Jan 1970 using C-c! (say).
> However, once I have entered a date (later than that), I can use
> S-<down> on the year to get to the date I want.  This seems rather
> inconsistent?
> 
> To be precise, I get the wrong date recorded if I try:
> 
>   C-c ! 1968-12-10 RET
> 
> (where C-c ! is =org-time-stamp-inactive=).
> The result is =[2011-12-10 Sat]=
> 
> The bug is not so much that I cannot input dates I want but that the
> inactive timestamp generated is *incorrect* and yet there is no error
> message.
> 

Good one! The culprit is org-read-date-analyze which near the end contains
this snippet of code:

,----
|     ...
|     (if (< year 100) (setq year (+ 2000 year)))
|     (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
|     (setq org-read-date-analyze-futurep futurep)
|     (list second minute hour day month year)))
`----

The trouble is that the caller (org-read-date) takes the result and
does a round-trip through the emacs time encode/decode functions to make
sure the result is sane. Dates before 1970 would break that (I get (0 9
10 26 11 2033 6 nil -18000)) so it seems it wraps around to 2033 or so).

In addition, most callers of org-read-date call it with a non-nil
to-time argument: that makes it return an emacs-encoded time (which is
then manipulated as such and which I believe has to satisfy the >=1970
requirement).

So I'd guess raising an exception might be the simplest way to deal with
this. Here's a patch to try out:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org.el b/lisp/org.el
index 92f2406..b9acf11 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14718,7 +14718,8 @@ user."
 	     (nth 2 tl))
 	(setq org-time-was-given t))
     (if (< year 100) (setq year (+ 2000 year)))
-    (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
+;    (if (< year 1970) (setq year (nth 5 defdecode))) ; not representable
+    (if (< year 1970) (error "Year must be >= 1970"))
     (setq org-read-date-analyze-futurep futurep)
     (list second minute hour day month year)))
--8<---------------cut here---------------end--------------->8---

I think it does not break anything but I'm not sure I like it much.

Patchwork note: this should not be applied without a lot more thought
and experimentation.

Nick

  reply	other threads:[~2011-03-10 23:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-10 21:00 dates before 1970 Eric S Fraga
2011-03-10 23:06 ` Nick Dokos [this message]
2011-03-11  8:31   ` Bastien
2011-03-11  8:52     ` Carsten Dominik
2011-03-13  7:39     ` Carsten Dominik
2011-03-13 20:08       ` Eric S Fraga
2011-03-14  7:40         ` Carsten Dominik
2011-03-14  9:58           ` Bastien
2011-03-11  8:47   ` Eric S Fraga
2011-03-11 11:36     ` Carsten Dominik
2011-03-11 12:00       ` Eric S Fraga
2011-03-11 15:28         ` Carsten Dominik
2011-03-11 17:56           ` Gregor Zattler
2011-03-12 22:38           ` Robert Horn
2011-03-11 16:30       ` Nick Dokos
2011-03-14 10:21         ` Carsten Dominik
2011-03-14 15:11           ` Nick Dokos
2011-03-14 17:02             ` Carsten Dominik
2011-03-14 17:13               ` Nick Dokos
2011-03-14 18:12                 ` Achim Gratz
2011-03-15  7:24                   ` Carsten Dominik
2011-03-11 16:16     ` Nick Dokos

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=5422.1299798393@alphaville.usa.hp.com \
    --to=nicholas.dokos@hp.com \
    --cc=e.fraga@ucl.ac.uk \
    --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).