all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* date parsing
@ 2004-08-10 15:18 Yoni Rabkin Katzenell
  2004-08-10 16:32 ` Ehud Karni
       [not found] ` <mailman.682.1092155793.2011.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Yoni Rabkin Katzenell @ 2004-08-10 15:18 UTC (permalink / raw)



I'm looking for an Emacs Lisp function library for parsing
human-readable dates. It seems that Emacs can parse RFC 1123 dates (for
Emails) but no other human-readable formats.

-- 
"Cut your own wood and it will warm you twice"
	Regards, Yoni Rabkin Katzenell

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

* Re: date parsing
  2004-08-10 15:18 date parsing Yoni Rabkin Katzenell
@ 2004-08-10 16:32 ` Ehud Karni
  2004-08-10 16:45   ` Ehud Karni
       [not found] ` <mailman.682.1092155793.2011.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Ehud Karni @ 2004-08-10 16:32 UTC (permalink / raw)
  Cc: help-gnu-emacs

On Tue, 10 Aug 2004 18:18:35 +0300, Yoni Rabkin Katzenell <yoni-r@actcom.com> wrote:
>
> I'm looking for an Emacs Lisp function library for parsing
> human-readable dates. It seems that Emacs can parse RFC 1123 dates (for
> Emails) but no other human-readable formats.

I don't know why you say that. Look at at gnus/parse-time.el,
change the value of `parse-time-rules' by adding (just) 1 element:

(setq parse-time-rules
  `(((6) parse-time-weekdays)
    ((3) (1 31))
    ((4) (1 12))                   ;;Added element by Ehud Karni
    ((4) parse-time-months)
    ((5) (100 4038))
    ((2 1 0)
     ,#'(lambda () (and (stringp elt)
			(= (length elt) 8)
			(= (aref elt 2) ?:)
			(= (aref elt 5) ?:)))
     [0 2] [3 5] [6 8])
    ((8 7) parse-time-zoneinfo
     ,#'(lambda () (car val))
     ,#'(lambda () (cadr val)))
    ((8)
     ,#'(lambda ()
	  (and (stringp elt)
	       (= 5 (length elt))
	       (or (= (aref elt 0) ?+) (= (aref elt 0) ?-))))
     ,#'(lambda () (* 60 (+ (parse-integer elt 3 5)
			    (* 60 (parse-integer elt 1 3)))
		      (if (= (aref elt 0) ?-) -1 1))))
    ((5 4 3)
     ,#'(lambda () (and (stringp elt)
			(= (length elt) 10)
			(= (aref elt 4) ?-)
			(= (aref elt 7) ?-)))
     [0 4] [5 7] [8 10])
    ((2 1 0)
     ,#'(lambda () (and (stringp elt) (= (length elt) 5) (= (aref elt 2) ?:)))
     [0 2] [3 5] ,#'(lambda () 0))
    ((2 1 0)
     ,#'(lambda () (and (stringp elt)
			(= (length elt) 4)
			(= (aref elt 1) ?:)))
     [0 1] [2 4] ,#'(lambda () 0))
    ((2 1 0)
     ,#'(lambda () (and (stringp elt)
			(= (length elt) 7)
			(= (aref elt 1) ?:)))
     [0 1] [2 4] [5 7])
    ((5) (50 110) ,#'(lambda () (+ 1900 elt)))
    ((5) (0 49) ,#'(lambda () (+ 2000 elt)))))

and check this by evaluating the following:

  (parse-time-string "10/01/2004  11:22:33")
  (parse-time-string "10/Jan/2004 11:22:33")
  (parse-time-string "2004-01-10  11:22:33")
  (parse-time-string "10/1/2004   11:22:33")
  (parse-time-string "10 Jan 2004 11:22:33")
  (parse-time-string "Jan 10 2004 11:22:33")
  (parse-time-string "2004 Jan 10 11:22:33")
  (parse-time-string "10 Jan 04 11:22:33")
  (parse-time-string "10/01/04  11:22:33")
  (parse-time-string "10/Jan/04 11:22:33")
  (parse-time-string "10/1/04   11:22:33")
  (parse-time-string "11:22:33 10/01/2004")
  (parse-time-string "11:22:33 10/Jan/2004")
  (parse-time-string "11:22:33 2004-01-10")
  (parse-time-string "11:22:33 10/1/2004")

each of these gives: (33 22 11 10 1 2004 nil nil nil)

`parse-time-string' fails when you use only 1 digit for the
month or day, or 2 digits for the year in the Y-M-D format.
i.e.  (parse-time-string "11:22:33 04-01-10") ==>
      (33 22 11 nil nil nil nil nil nil)

If you have other "human readable" format just check them.

Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry

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

* Re: date parsing
  2004-08-10 16:32 ` Ehud Karni
@ 2004-08-10 16:45   ` Ehud Karni
  0 siblings, 0 replies; 4+ messages in thread
From: Ehud Karni @ 2004-08-10 16:45 UTC (permalink / raw)
  Cc: help-gnu-emacs

On Tue, 10 Aug 2004 19:32:12 +0300, Ehud Karni <ehud@unix.mvs.co.il> wrote:
>
> I don't know why you say that. Look at at gnus/parse-time.el,

In emacs 21.4 (CVS version) it was moved to calendar/parse-time.el.
My suggested addendum still applies.

Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry

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

* Re: date parsing
       [not found] ` <mailman.682.1092155793.2011.help-gnu-emacs@gnu.org>
@ 2004-08-10 20:15   ` Yoni Rabkin Katzenell
  0 siblings, 0 replies; 4+ messages in thread
From: Yoni Rabkin Katzenell @ 2004-08-10 20:15 UTC (permalink / raw)



Thanks, but I think I'll stick to changes that will not disappear next
time I compile Emacs.

Modifying the functions from the calendar dir was is still my last
resort. As for checking that parse-time is really ok, the real test
would be to encode that value that parse-time gives you and then decode
it back to a string and see that they match.

I'll quote from time-date.el:

              ;; `parse-time-string' isn't sufficiently general or
	      ;; robust.  It fails to grok some of the formats that
	      ;; timezone does (e.g. dodgy post-2000 stuff from some
	      ;; Elms) and either fails or returns bogus values.  Lars
	      ;; reverted this change, but that loses non-trivially
	      ;; often for me.  -- fx

Nevertheless, thank you for the cool idea and the time you took to
promptly reply.

-- 
"Cut your own wood and it will warm you twice"
	Regards, Yoni Rabkin Katzenell

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

end of thread, other threads:[~2004-08-10 20:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-10 15:18 date parsing Yoni Rabkin Katzenell
2004-08-10 16:32 ` Ehud Karni
2004-08-10 16:45   ` Ehud Karni
     [not found] ` <mailman.682.1092155793.2011.help-gnu-emacs@gnu.org>
2004-08-10 20:15   ` Yoni Rabkin Katzenell

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.