From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Hong Xu Newsgroups: gmane.emacs.bugs Subject: bug#25086: [PATCH] Fix the timezone detection of parse-iso8601-time-string. Date: Thu, 1 Dec 2016 19:46:48 -0800 Message-ID: <1480650408-26252-1-git-send-email-hong@topbug.net> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1480650497 16708 195.159.176.226 (2 Dec 2016 03:48:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 2 Dec 2016 03:48:17 +0000 (UTC) To: 25086@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 02 04:48:11 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCepV-000387-8A for geb-bug-gnu-emacs@m.gmane.org; Fri, 02 Dec 2016 04:48:09 +0100 Original-Received: from localhost ([::1]:60428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCepY-00022t-Jc for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Dec 2016 22:48:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCepS-00022k-5E for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2016 22:48:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCepP-0007Tl-20 for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2016 22:48:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33905) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cCepO-0007Td-Up for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2016 22:48:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cCepO-0006Uy-Ld for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2016 22:48:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Hong Xu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Dec 2016 03:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 25086 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.148065042624915 (code B ref -1); Fri, 02 Dec 2016 03:48:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 Dec 2016 03:47:06 +0000 Original-Received: from localhost ([127.0.0.1]:49304 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCeoU-0006Tn-0R for submit@debbugs.gnu.org; Thu, 01 Dec 2016 22:47:06 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:53190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCeoS-0006TJ-Hc for submit@debbugs.gnu.org; Thu, 01 Dec 2016 22:47:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCeoM-0006gc-9U for submit@debbugs.gnu.org; Thu, 01 Dec 2016 22:46:59 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:39845) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCeoM-0006gF-6f for submit@debbugs.gnu.org; Thu, 01 Dec 2016 22:46:58 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCeoK-0001nx-TD for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2016 22:46:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCeoH-0006bN-OY for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2016 22:46:56 -0500 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21459) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCeoH-0006aw-Eu for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2016 22:46:53 -0500 Original-Received: from localhost (cpe-104-32-170-214.socal.res.rr.com [104.32.170.214]) by mx.zohomail.com with SMTPS id 1480650408710973.6395530284094; Thu, 1 Dec 2016 19:46:48 -0800 (PST) X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:126382 Archived-At: * parse-time.el (parse-iso8601-time-string): Fix its timezone parsing. * parse-time.el: Add doc for parse-iso8601-time-string and make it autoload. * editfns.c (Fdecode-time): Minor doc improvement for decode-time. --- doc/misc/emacs-mime.texi | 3 +++ lisp/calendar/parse-time.el | 12 ++++++++---- src/editfns.c | 5 ++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi index 4d68246bba4b..8d6536265416 100644 --- a/doc/misc/emacs-mime.texi +++ b/doc/misc/emacs-mime.texi @@ -1536,6 +1536,9 @@ time-date (date-to-time "Sat Sep 12 12:21:54 1998 +0200") @result{} (13818 19266) +(parse-iso8601-time-string "1998-09-12T12:21:54+0200") +@result{} (13818 19266) + (float-time '(13818 19266)) @result{} 905595714.0 diff --git a/lisp/calendar/parse-time.el b/lisp/calendar/parse-time.el index 6ba26a4a00d0..bc1efbb074e3 100644 --- a/lisp/calendar/parse-time.el +++ b/lisp/calendar/parse-time.el @@ -195,7 +195,7 @@ parse-time-iso8601-regexp (time-minute 2digit) (time-second 2digit) (time-secfrac "\\(\\.[0-9]+\\)?") - (time-numoffset (concat "[-+]\\(" time-hour "\\):" time-minute)) + (time-numoffset (concat "\\([-+]" time-hour "\\):?" time-minute)) (time-offset (concat "Z" time-numoffset)) (partial-time (concat time-hour colon time-minute colon time-second time-secfrac)) @@ -204,13 +204,17 @@ parse-time-iso8601-regexp (date-time (concat full-date "T" full-time))) (list (concat "^" full-date) (concat "T" partial-time) - (concat "Z" time-numoffset))) + (concat "Z?" time-numoffset))) "List of regular expressions matching ISO 8601 dates. 1st regular expression matches the date. 2nd regular expression matches the time. 3rd regular expression matches the (optional) timezone specification.") +;;;###autoload (defun parse-iso8601-time-string (date-string) + "Parse an ISO 8601 time string, such as 2016-12-01T23:35:06-05:00. +If DATE-STRING cannot be parsed, it falls back to +`parse-time-string'." (let* ((date-re (nth 0 parse-time-iso8601-regexp)) (time-re (nth 1 parse-time-iso8601-regexp)) (tz-re (nth 2 parse-time-iso8601-regexp)) @@ -235,10 +239,10 @@ parse-iso8601-time-string "0")) re-start (match-end 0)) (when (string-match tz-re date-string re-start) - (setq tz (match-string 1 date-string))) + (setq tz (* 3600 (string-to-number (match-string 1 date-string))))) (setq time (list seconds minute hour day month year day-of-week dst tz)))) - ;; Fall back to having Gnus do fancy things for us. + ;; Fall back to having `parse-time-string' do fancy things for us. (when (not time) (setq time (parse-time-string date-string))) diff --git a/src/editfns.c b/src/editfns.c index 5cc4a67ab19b..2f1f412d9e4e 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2101,9 +2101,8 @@ format_time_string (char const *format, ptrdiff_t formatlen, DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 2, 0, doc: /* Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST UTCOFF). -The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED), -as from `current-time' and `file-attributes', or nil to use the -current time. +The optional TIME should be a list of (HIGH LOW . IGNORED), as from +`current-time' and `file-attributes', or nil to use the current time. It can also be a single integer number of seconds since the epoch. The obsolete form (HIGH . LOW) is also still accepted. The optional ZONE is omitted or nil for Emacs local time, t for -- 2.1.4