emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] European date format
@ 2011-03-04 17:56 Jan Seeger
  2011-03-04 19:04 ` Nick Dokos
  2011-04-08 10:06 ` Carsten Dominik
  0 siblings, 2 replies; 10+ messages in thread
From: Jan Seeger @ 2011-03-04 17:56 UTC (permalink / raw)
  To: emacs-orgmode

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

Greetings!

I was annoyed that org only read the bassackwards american date
format, and implemented european date format matching. I hope it's
correct, it seems to work for dates with and without year.

Regards,
Jan


[-- Attachment #2: org-patch.patch --]
[-- Type: application/octet-stream, Size: 1010 bytes --]

diff --git a/lisp/org.el b/lisp/org.el
index 3a07cfd..fa54d4e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14584,6 +14584,17 @@ user."
       (if (< year 100) (setq year (+ 2000 year)))
       (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
 			       t nil ans)))
+    ;; European date match
+    (when (string-match
+	   "^ *\\(3[01]\\|0?[1-9]\\|[12][0-9]\\)\\.\\(0?[1-9]\\|1[012]\\)\\.\\([1-9][0-9][0-9][0-9]\\)?" ans)
+      (setq year (if (match-end 3)
+		     (string-to-number (match-string 3 ans))
+		   (progn (setq kill-year t)
+			  (string-to-number (format-time-string "%Y"))))
+	    day (string-to-number (match-string 1 ans))
+	    month (string-to-number (match-string 2 ans))
+	    ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
+				     t nil ans)))
     ;; Help matching am/pm times, because `parse-time-string' does not do that.
     ;; If there is a time with am/pm, and *no* time without it, we convert
     ;; so that matching will be successful.

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

* Re: [PATCH] European date format
  2011-03-04 17:56 [PATCH] European date format Jan Seeger
@ 2011-03-04 19:04 ` Nick Dokos
  2011-03-04 19:11   ` Jan Seeger
  2011-03-05  7:45   ` Achim Gratz
  2011-04-08 10:06 ` Carsten Dominik
  1 sibling, 2 replies; 10+ messages in thread
From: Nick Dokos @ 2011-03-04 19:04 UTC (permalink / raw)
  To: Jan Seeger; +Cc: nicholas.dokos, emacs-orgmode

Jan Seeger <jan.seeger@thenybble.de> wrote:

> Greetings!
> 
> I was annoyed that org only read the bassackwards american date
> format, and implemented european date format matching. I hope it's
> correct, it seems to work for dates with and without year.
> 

It would help if you provided a few examples of what "European format" is.
Deciphering long regexps is maybe fun the first time you do it, but after
that it quickly loses its charm :-)

BTW, if you (and I don't just mean Jan here) haven't tried re-builder,
you should: add a few strings to a buffer, M-x re-builder and type in
the regexp. It interactively and incrementally shows what matches.

In any case, I tried to decipher your regexp and it seems to me that
there is at least one (small) problem: a date without a year won't match
without a final period. E.g.

4.3. ==> the fourth day of March, 2011
4.3  ==> does not match

Thanks,
Nick

PS. Also, patches are just text, so please include them in the mail (or at least
make sure that they are attached as text/plain or something similar, rather
than application/octet-stream).

Here's the patch for reference:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org.el b/lisp/org.el
index 3a07cfd..fa54d4e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14584,6 +14584,17 @@ user."
       (if (< year 100) (setq year (+ 2000 year)))
       (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
 			       t nil ans)))
+    ;; European date match
+    (when (string-match
+	   "^ *\\(3[01]\\|0?[1-9]\\|[12][0-9]\\)\\.\\(0?[1-9]\\|1[012]\\)\\.\\([1-9][0-9][0-9][0-9]\\)?" ans)
+      (setq year (if (match-end 3)
+		     (string-to-number (match-string 3 ans))
+		   (progn (setq kill-year t)
+			  (string-to-number (format-time-string "%Y"))))
+	    day (string-to-number (match-string 1 ans))
+	    month (string-to-number (match-string 2 ans))
+	    ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
+				     t nil ans)))
     ;; Help matching am/pm times, because `parse-time-string' does not do that.
     ;; If there is a time with am/pm, and *no* time without it, we convert
     ;; so that matching will be successful.
--8<---------------cut here---------------end--------------->8---

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

* Re: [PATCH] European date format
  2011-03-04 19:04 ` Nick Dokos
@ 2011-03-04 19:11   ` Jan Seeger
  2011-03-04 19:46     ` Nick Dokos
  2011-03-05  7:45   ` Achim Gratz
  1 sibling, 1 reply; 10+ messages in thread
From: Jan Seeger @ 2011-03-04 19:11 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode

Hey!

Ah, I'm sorry. Yeah, european format is Day.Month.Year (optional). And
the final trailing dot is intentional, because I think it looks nicer
(and I think it simplifies the regex). Also, my last mail was missing
a smiley, I was only kidding of course.

Regards,
Jan

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

* Re: [PATCH] European date format
  2011-03-04 19:11   ` Jan Seeger
@ 2011-03-04 19:46     ` Nick Dokos
  2011-03-04 21:13       ` Milan Zamazal
  0 siblings, 1 reply; 10+ messages in thread
From: Nick Dokos @ 2011-03-04 19:46 UTC (permalink / raw)
  To: Jan Seeger; +Cc: nicholas.dokos, emacs-orgmode

Jan Seeger <jan.seeger@thenybble.de> wrote:

> Hey!
> 
> Ah, I'm sorry. Yeah, european format is Day.Month.Year (optional). And
> the final trailing dot is intentional, because I think it looks nicer
> (and I think it simplifies the regex). Also, my last mail was missing
> a smiley, I was only kidding of course.
> 

You mean about the "bassackwards" comment? I think you got it exactly
right :-)

The problem with the required final trailing dot (if you want to leave
out the year) is that it is not obvious - at least to me: the equivalent
ISO would be "-03-04" and the equivalent American would be "3/4/" which
look horrible - however, I don't know what the general practice is in
Europe.

Nick

PS. BTW, another reason to avoid application/octet-stream is that
patches sent to the list are saved in Patchwork - but not if they are
application/octet-stream: see the thread

    http://thread.gmane.org/gmane.emacs.orgmode/25513

and in particular

    http://thread.gmane.org/gmane.emacs.orgmode/25513/focus=25560

In this case, my reposting of your patch inline has archived it
to Patchwork so you don't need to do it again, but keep it in mind
if you submit patches in the future.

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

* Re: [PATCH] European date format
  2011-03-04 19:46     ` Nick Dokos
@ 2011-03-04 21:13       ` Milan Zamazal
  2011-03-04 21:21         ` Nick Dokos
  2011-03-04 23:11         ` Sébastien Vauban
  0 siblings, 2 replies; 10+ messages in thread
From: Milan Zamazal @ 2011-03-04 21:13 UTC (permalink / raw)
  To: emacs-orgmode

>>>>> "ND" == Nick Dokos <nicholas.dokos@hp.com> writes:

    ND> The problem with the required final trailing dot (if you want to
    ND> leave out the year) is that it is not obvious - at least to me:
    ND> the equivalent ISO would be "-03-04" and the equivalent American
    ND> would be "3/4/" which look horrible - however, I don't know what
    ND> the general practice is in Europe.

The dots are not separators, they mark ordinal numbers.  And at least
here in Czech Republic the correct typeset form is e.g. "4. 3. 2011"
although the compact form "4.3.2011" is often used.

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

* Re: Re: [PATCH] European date format
  2011-03-04 21:13       ` Milan Zamazal
@ 2011-03-04 21:21         ` Nick Dokos
  2011-03-04 21:38           ` Michael Radziej
  2011-03-04 23:11         ` Sébastien Vauban
  1 sibling, 1 reply; 10+ messages in thread
From: Nick Dokos @ 2011-03-04 21:21 UTC (permalink / raw)
  To: Milan Zamazal; +Cc: nicholas.dokos, emacs-orgmode

Milan Zamazal <pdm@zamazal.org> wrote:

> >>>>> "ND" == Nick Dokos <nicholas.dokos@hp.com> writes:
> 
>     ND> The problem with the required final trailing dot (if you want to
>     ND> leave out the year) is that it is not obvious - at least to me:
>     ND> the equivalent ISO would be "-03-04" and the equivalent American
>     ND> would be "3/4/" which look horrible - however, I don't know what
>     ND> the general practice is in Europe.
> 
> The dots are not separators, they mark ordinal numbers.  And at least
> here in Czech Republic the correct typeset form is e.g. "4. 3. 2011"
> although the compact form "4.3.2011" is often used.
> 

Interesting - I never thought of that. So I take it that if the year is left
out (implying the current year), the trailing dot is included because it
is significant: the fourth day of the third month - is that correct?

Thanks,
Nick

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

* Re: Re: [PATCH] European date format
  2011-03-04 21:21         ` Nick Dokos
@ 2011-03-04 21:38           ` Michael Radziej
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Radziej @ 2011-03-04 21:38 UTC (permalink / raw)
  To: Milan Zamazal; +Cc: nicholas.dokos, emacs-orgmode

On Fri, 04 Mar 2011 16:21:47 -0500, Nick Dokos <nicholas.dokos@hp.com> wrote:
> Milan Zamazal <pdm@zamazal.org> wrote:
> > The dots are not separators, they mark ordinal numbers.  And at least
> > here in Czech Republic the correct typeset form is e.g. "4. 3. 2011"
> > although the compact form "4.3.2011" is often used.
> > 
> 
> Interesting - I never thought of that. So I take it that if the year is left
> out (implying the current year), the trailing dot is included because it
> is significant: the fourth day of the third month - is that correct?

Same in German. When you pronounce "3.4.", you'd say "dritter vierter",
i.e. third (of) fourth.

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

* Re: Re: [PATCH] European date format
  2011-03-04 21:13       ` Milan Zamazal
  2011-03-04 21:21         ` Nick Dokos
@ 2011-03-04 23:11         ` Sébastien Vauban
  1 sibling, 0 replies; 10+ messages in thread
From: Sébastien Vauban @ 2011-03-04 23:11 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Milan,

Milan Zamazal wrote:
>>>>>> "ND" == Nick Dokos <nicholas.dokos-VXdhtT5mjnY@public.gmane.org> writes:
>
>     ND> The problem with the required final trailing dot (if you want to
>     ND> leave out the year) is that it is not obvious - at least to me:
>     ND> the equivalent ISO would be "-03-04" and the equivalent American
>     ND> would be "3/4/" which look horrible - however, I don't know what
>     ND> the general practice is in Europe.
>
> The dots are not separators, they mark ordinal numbers.  And at least
> here in Czech Republic the correct typeset form is e.g. "4. 3. 2011"
> although the compact form "4.3.2011" is often used.

I don't think we have a real European format: in Belgium, a date is
16/03/2011, or 16/3/2011 for the sixteenth of March. So, here, the common
separator is the dash, but the order is well day/month/year...

Best regards,
  Seb

-- 
Sébastien Vauban

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

* Re: [PATCH] European date format
  2011-03-04 19:04 ` Nick Dokos
  2011-03-04 19:11   ` Jan Seeger
@ 2011-03-05  7:45   ` Achim Gratz
  1 sibling, 0 replies; 10+ messages in thread
From: Achim Gratz @ 2011-03-05  7:45 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> writes:
> 4.3. ==> the fourth day of March, 2011
> 4.3  ==> does not match

As it should, IMHO.  This format is relying on interpreting dates as
ordinals (fourth day of the third month).  Also there'd be no way for a
regex to distinguish some dates from some FP numbers, at least when the
point is, well, "." (in Germany at least it would be ",").  But really,
there isn't any "european" date format that I'm aware of and the only
standard date format is ISO8601:2004.  If you use the extended format
(with the dashes), dates are easily recognizable and most important of
all there are no ambiguities.

> the equivalent ISO would be "-03-04"

No, this has nothing to do with ISO dates.  Dropping must always occur
from the least significant part, so you can't leave out the year.
Truncating the year designator to two digits was allowed in a former
version "by agreement", but has been eliminated from the standard, BTW.


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

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

* Re: [PATCH] European date format
  2011-03-04 17:56 [PATCH] European date format Jan Seeger
  2011-03-04 19:04 ` Nick Dokos
@ 2011-04-08 10:06 ` Carsten Dominik
  1 sibling, 0 replies; 10+ messages in thread
From: Carsten Dominik @ 2011-04-08 10:06 UTC (permalink / raw)
  To: Jan Seeger; +Cc: emacs-orgmode

Applied, thanks.

On Mar 4, 2011, at 6:56 PM, Jan Seeger wrote:

> Greetings!
> 
> I was annoyed that org only read the bassackwards american date
> format, and implemented european date format matching. I hope it's
> correct, it seems to work for dates with and without year.
> 
> Regards,
> Jan
> 
> <org-patch.patch>

- Carsten

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

end of thread, other threads:[~2011-04-08 10:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-04 17:56 [PATCH] European date format Jan Seeger
2011-03-04 19:04 ` Nick Dokos
2011-03-04 19:11   ` Jan Seeger
2011-03-04 19:46     ` Nick Dokos
2011-03-04 21:13       ` Milan Zamazal
2011-03-04 21:21         ` Nick Dokos
2011-03-04 21:38           ` Michael Radziej
2011-03-04 23:11         ` Sébastien Vauban
2011-03-05  7:45   ` Achim Gratz
2011-04-08 10:06 ` Carsten Dominik

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