From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.bugs Subject: bug#14776: 24.3.50; [PATCH] parse-time-string performance Date: Sat, 06 Jul 2013 19:47:30 +0200 Message-ID: <87k3l3r365.fsf@hochschule-trier.de> References: <87sizwxwu2.fsf@hochschule-trier.de> <87li5m1geu.fsf@hochschule-trier.de> <87k3l6jedt.fsf@hochschule-trier.de> <87ppuyhw32.fsf@hochschule-trier.de> <87hagaeztj.fsf@hochschule-trier.de> <87hag7zor2.fsf@building.gnus.org> <87y59jwuvd.fsf@hochschule-trier.de> <87r4fby95z.fsf@building.gnus.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1373132895 15462 80.91.229.3 (6 Jul 2013 17:48:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 6 Jul 2013 17:48:15 +0000 (UTC) Cc: 14776@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 06 19:48:14 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UvWaj-0006Fe-7P for geb-bug-gnu-emacs@m.gmane.org; Sat, 06 Jul 2013 19:48:13 +0200 Original-Received: from localhost ([::1]:35678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UvWai-0007DG-S4 for geb-bug-gnu-emacs@m.gmane.org; Sat, 06 Jul 2013 13:48:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UvWac-0007Cq-Qv for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2013 13:48:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UvWaZ-0001xR-7Q for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2013 13:48:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40827) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UvWaZ-0001xN-5H for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2013 13:48:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1UvWaY-0005YT-Vf for bug-gnu-emacs@gnu.org; Sat, 06 Jul 2013 13:48:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas Politz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Jul 2013 17:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14776 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 14776-submit@debbugs.gnu.org id=B14776.137313287621329 (code B ref 14776); Sat, 06 Jul 2013 17:48:02 +0000 Original-Received: (at 14776) by debbugs.gnu.org; 6 Jul 2013 17:47:56 +0000 Original-Received: from localhost ([127.0.0.1]:35140 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UvWaS-0005Xv-1S for submit@debbugs.gnu.org; Sat, 06 Jul 2013 13:47:56 -0400 Original-Received: from gateway-a.fh-trier.de ([143.93.54.181]:60572) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UvWaN-0005XI-8W for 14776@debbugs.gnu.org; Sat, 06 Jul 2013 13:47:54 -0400 X-Virus-Scanned: by Amavisd-new + McAfee uvscan + ClamAV [Rechenzentrum Hochschule Trier] Original-Received: from luca (dslb-178-004-120-200.pools.arcor-ip.net [178.4.120.200]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: politza) by gateway-a.fh-trier.de (Postfix) with ESMTPSA id B7425175FA72; Sat, 6 Jul 2013 19:47:30 +0200 (CEST) Original-Received: from localhost ([127.0.0.1] helo=luca) by luca with esmtp (Exim 4.72) (envelope-from ) id 1UvWa2-0008Fu-2G; Sat, 06 Jul 2013 19:47:30 +0200 In-Reply-To: <87r4fby95z.fsf@building.gnus.org> (Lars Ingebrigtsen's message of "Sat, 06 Jul 2013 17:56:08 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:76009 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > Well, the old function is designed for parsing RFC822 Date headers... Also, people may be keeping ancient mail around, containing dates which may be parsed by the current function. Anyway here is an updated version, incorporating 2-digit years and textual timezones. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=parse-time-rfc2822.el Content-Transfer-Encoding: quoted-printable ;;; parse-time-rfc2822.el --- Parse a RFC2822 compliant date format. ;; Copyright (C) 2013 Andreas Politz ;; Author: Andreas Politz ;; Keywords: mail ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;;=20 ;;; Code: (require 'parse-time) (require 'cl-lib) (defconst parse-time-rfc2822-regex (let* ((fws "[ \t\r\n]+") (ofws "[ \t\r\n]*") (day-of-week (regexp-opt (mapcar 'car parse-time-weekdays))) (day "[0-9]\\{1,2\\}") (month (regexp-opt (mapcar 'car parse-time-months))) (year "\\(?:[0-9]\\{2\\}\\|[0-9]\\{4,\\}\\)") (hour "[0-9]\\{2\\}") (minute hour) (second hour) (zone "[+-][0-9]\\{4\\}") (zone-text (regexp-opt (mapcar 'car parse-time-zoneinfo))) ;; A rather non strict comment. (cfws "(\\(?:.\\|\n\\)*)")) (concat (format "\\`%s\\(?:\\(%s\\),%s\\)?" ofws day-of-week ofws) (format "\\(%s\\)%s\\(%s\\)%s\\(%s\\)%s" day fws month fws year fws) (format "\\(%s\\):\\(%s\\)\\(?::\\(%s\\)\\)?%s" hour minute second fws) (format "\\(?:\\(%s\\)\\|\\(%s\\)\\)" zone zone-text) (format "%s\\(?:%s\\)?%s\\'" ofws cfws ofws))) "A regex matching a strict rfc2822 date.") (defun parse-time-string-rfc2822 (string) "Parse the strict rfc2822 time-string STRING Return either a list (SEC MIN HOUR DAY MON YEAR DOW DST TZ) or nil, if STRING is not valid." (setq s string) (when (string-match parse-time-rfc2822-regex (setq string (downcase string))) (let ((dow (cdr (assoc (match-string 1 string) parse-time-weekdays))) (day (string-to-number (match-string 2 string))) (month (cdr (assoc (match-string 3 string) parse-time-months))) (year (string-to-number (match-string 4 string))) (hour (string-to-number (match-string 5 string))) (min (string-to-number (match-string 6 string))) (sec (string-to-number (or (match-string 7 string) "0"))) zone dst) (if (match-string 9 string) (let ((zoneinfo (cdr (assoc (match-string 9 string) parse-time-zoneinfo)))) (setq dst (cadr zoneinfo) zone (car zoneinfo))) (setq zone (string-to-number (match-string 8 string)))) ;; adjust 2 digit RFC822 years (1969 - 2068) (when (< year 100) (if (> year 68) (cl-incf year 1900) (cl-incf year 2000))) (let ((zone (+ (* (/ zone 100) 3600) (* (% zone 100) 60)))) (list sec min hour day month year dow dst zone))))) (provide 'parse-time-rfc2822) ;;; parse-time-rfc2822.el ends here --=-=-= Content-Type: text/plain -ap --=-=-=--