emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [PATCH] European date format


From: Nick Dokos
Subject: Re: [O] [PATCH] European date format
Date: Fri, 04 Mar 2011 14:04:42 -0500

Jan Seeger <address@hidden> 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---




reply via email to

[Prev in Thread] Current Thread [Next in Thread]