From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Ehud Karni" Newsgroups: gmane.emacs.help Subject: Re: date parsing Date: Tue, 10 Aug 2004 19:32:12 +0300 Organization: Mivtach-Simon Insurance agencies Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <200408101632.i7AGWClE004076@beta.mvs.co.il> References: Reply-To: ehud@unix.mvs.co.il NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-8-i Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1092257750 11999 80.91.224.253 (11 Aug 2004 20:55:50 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 11 Aug 2004 20:55:50 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 10 18:32:48 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BuZYN-0008ED-00 for ; Tue, 10 Aug 2004 18:32:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BuZcB-0000aJ-Mu for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Aug 2004 12:36:43 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BuZbz-0000Y0-Tg for help-gnu-emacs@gnu.org; Tue, 10 Aug 2004 12:36:32 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BuZby-0000Vx-DX for help-gnu-emacs@gnu.org; Tue, 10 Aug 2004 12:36:30 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BuZby-0000Vo-At for help-gnu-emacs@gnu.org; Tue, 10 Aug 2004 12:36:30 -0400 Original-Received: from [193.16.147.12] (helo=unix.mvs.co.il) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BuZY0-0002Ri-9I for help-gnu-emacs@gnu.org; Tue, 10 Aug 2004 12:32:24 -0400 Original-Received: from beta.mvs.co.il (beta [10.253.0.3]) by unix.mvs.co.il (8.13.0/8.13.0) with ESMTP id i7AGWCVx029995 for ; Tue, 10 Aug 2004 19:32:12 +0300 Original-Received: from beta.mvs.co.il (localhost [127.0.0.1]) by beta.mvs.co.il (8.12.10/8.12.10) with ESMTP id i7AGWCqi004080 for ; Tue, 10 Aug 2004 19:32:12 +0300 Original-Received: (from root@localhost) by beta.mvs.co.il (8.12.10/8.12.10/Submit) id i7AGWClE004076; Tue, 10 Aug 2004 19:32:12 +0300 Original-To: yoni-r@actcom.com In-reply-to: (message from Yoni Rabkin Katzenell on Tue, 10 Aug 2004 18:18:35 +0300) X-Mailer: Emacs 21.3.1 rmail (send-msg 1.108) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:20084 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:20084 On Tue, 10 Aug 2004 18:18:35 +0300, Yoni Rabkin Katzenell 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 Better Safe Than Sorry