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: Sat, 17 Dec 2016 12:42:57 -0800 Message-ID: <87eg16z3qm.fsf@topbug.net> References: <1480650408-26252-1-git-send-email-hong@topbug.net> <874m2nyog6.fsf@topbug.net> <8737i7yo27.fsf@topbug.net> <837f6y7gch.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1482007667 16796 195.159.176.226 (17 Dec 2016 20:47:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 17 Dec 2016 20:47:47 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 25.1.90.6 Cc: 25086@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Dec 17 21:47:43 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 1cILtN-0003e1-UN for geb-bug-gnu-emacs@m.gmane.org; Sat, 17 Dec 2016 21:47:42 +0100 Original-Received: from localhost ([::1]:38207 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cILtS-0005iX-38 for geb-bug-gnu-emacs@m.gmane.org; Sat, 17 Dec 2016 15:47:46 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36048) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cILpu-0003IG-Bp for bug-gnu-emacs@gnu.org; Sat, 17 Dec 2016 15:44:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cILpq-0004Vi-FK for bug-gnu-emacs@gnu.org; Sat, 17 Dec 2016 15:44:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58046) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cILpq-0004Va-Bo for bug-gnu-emacs@gnu.org; Sat, 17 Dec 2016 15:44:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cILpp-0006lr-UQ for bug-gnu-emacs@gnu.org; Sat, 17 Dec 2016 15:44:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Hong Xu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Dec 2016 20:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25086 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 25086-submit@debbugs.gnu.org id=B25086.148200739025932 (code B ref 25086); Sat, 17 Dec 2016 20:44:01 +0000 Original-Received: (at 25086) by debbugs.gnu.org; 17 Dec 2016 20:43:10 +0000 Original-Received: from localhost ([127.0.0.1]:45212 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cILoz-0006kB-Ik for submit@debbugs.gnu.org; Sat, 17 Dec 2016 15:43:09 -0500 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21406) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cILox-0006k3-Un for 25086@debbugs.gnu.org; Sat, 17 Dec 2016 15:43:08 -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 1482007381310407.7253015250884; Sat, 17 Dec 2016 12:43:01 -0800 (PST) In-reply-to: <837f6y7gch.fsf@gnu.org> X-Zoho-Virus-Status: 1 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:127114 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain On 2016-12-17 Sat 06:58 GMT-0800, Eli Zaretskii wrote: >> From: Hong Xu >> Date: Thu, 01 Dec 2016 20:04:00 -0800 >> >> +;;;###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'." > > Why did you want to autoload this? The log message doesn't mention > this change at all. The attached new version now fixes this issue in the log message. It autoloads because parse-time-string autoloads -- If parse-time-string is useful for autoloading, there is no reason that parse-iso8601-time-string is not useful for that. > >> + '(42 35 19 22 2 2016 1 t -25200))) >> + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-0200") >> + '(13818 33666))) >> + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-02:00") >> + '(13818 33666))) >> + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-02") >> + '(13818 33666))) >> + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54+02") >> + '(13818 19266)))) > > Does this also test this part of your changes: > >> @@ -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))) > > If not, could you please add tests for that? > I've added the tests now. And indeed, it exposes a bug in the original patch. Again, I decomposed the patch to two different parts, one for the stable branch and the other (with only test files) for the master branch. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-the-timezone-detection-of-parse-iso8601-time-str.patch Content-Transfer-Encoding: quoted-printable From=2039e4d94da9b8806871cb2c9145cd1f14233526f5 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Sat, 17 Dec 2016 12:07:45 -0800 Subject: [PATCH] Fix the timezone detection of parse-iso8601-time-string. * parse-time.el (parse-iso8601-time-string): Fix its timezone parsing and make it autoload. * parse-time.el: Add doc for parse-iso8601-time-string and make it autoload. * editfns.c (Fdecode-time): Minor doc improvement for decode-time. * emacs-mime.texi (time-date): Add an example for parse-iso8601-time-string. =2D-- doc/misc/emacs-mime.texi | 3 +++ lisp/calendar/parse-time.el | 19 ++++++++++++------- src/editfns.c | 5 ++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi index 4d68246bba4b..8d6536265416 100644 =2D-- 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) =20 +(parse-iso8601-time-string "1998-09-12T12:21:54+0200") +@result{} (13818 19266) + (float-time '(13818 19266)) @result{} 905595714.0 =20 diff --git a/lisp/calendar/parse-time.el b/lisp/calendar/parse-time.el index 6ba26a4a00d0..6bd748cbe0d9 100644 =2D-- 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]+\\)?") =2D (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,19 +204,24 @@ parse-time-iso8601-regexp (date-time (concat full-date "T" full-time))) (list (concat "^" full-date) (concat "T" partial-time) =2D (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.") =20 +;;;###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)) =2D re-start =2D time seconds minute hour fractional-seconds =2D day month year day-of-week dst tz) + (tz 0) + re-start + time seconds minute hour fractional-seconds + day month year day-of-week dst) ;; We need to populate 'time' with ;; (SEC MIN HOUR DAY MON YEAR DOW DST TZ) =20 @@ -235,10 +240,10 @@ parse-iso8601-time-string "0")) re-start (match-end 0)) (when (string-match tz-re date-string re-start) =2D (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)))) =20 =2D ;; 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))) =20 diff --git a/src/editfns.c b/src/editfns.c index 5cc4a67ab19b..2f1f412d9e4e 100644 =2D-- a/src/editfns.c +++ b/src/editfns.c @@ -2101,9 +2101,8 @@ format_time_string (char const *format, ptrdiff_t for= matlen, =20 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). =2DThe optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED), =2Das from `current-time' and `file-attributes', or nil to use the =2Dcurrent 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 =2D-=20 2.1.4 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-tests-for-parse-iso8601-time-string.patch Content-Transfer-Encoding: quoted-printable From=209f06f66c4d5970c4cf692956544456ab4458f3b1 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Sat, 17 Dec 2016 12:38:26 -0800 Subject: [PATCH] Add tests for parse-iso8601-time-string. * parse-time-tests.el (parse-time-tests): Add tests for parse-iso8601-time-string. =2D-- test/lisp/calendar/parse-time-tests.el | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/lisp/calendar/parse-time-tests.el b/test/lisp/calendar/pa= rse-time-tests.el index 9bcf2b4a53c7..7a087d0f0bee 100644 =2D-- a/test/lisp/calendar/parse-time-tests.el +++ b/test/lisp/calendar/parse-time-tests.el @@ -42,7 +42,19 @@ (should (equal (parse-time-string "Monday, 22 february 2016 19:35:42 +01= 00") '(42 35 19 22 2 2016 1 nil 3600))) (should (equal (parse-time-string "Monday, 22 february 2016 19:35:42 PDT= ") =2D '(42 35 19 22 2 2016 1 t -25200)))) + '(42 35 19 22 2 2016 1 t -25200))) + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-0200") + '(13818 33666))) + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-02:00") + '(13818 33666))) + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54-02") + '(13818 33666))) + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54+02") + '(13818 19266))) + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54Z") + '(13818 26466))) + (should (equal (parse-iso8601-time-string "1998-09-12T12:21:54") + '(13818 26466)))) =20 (provide 'parse-time-tests) =20 =2D-=20 2.1.4 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJYVaNRAAoJECZsfTOCL4R4uy4P/iM+/EZExBNGLYRuUm2BN+o7 ZqEsCP51tbz4elGydZB0H1TH8j2C4b1fnw62VMWuTupD/qmZRF3oS5ZQnL64TiQT tt3poIEpBxSFOQsWmHWSUg3EpgDmXbA6zDLanE+eUhTTszbyuAzEQacHh3jEeB2P /C20/QvznDSDu2qC9Cq3U8iA3SLl+jIgtH29ktaLyXJsp+0RtmmEkVRZXY9UsTvX Lad/g8hhoWv5Ud7fMRGdsT8FXYPay/R2aftdcu5upEKK1WkAW6kfhymVBU16RWd4 Bj94eCgkBjTJ/jMklCUydnw2MfWM5E9Aryy7iLoJpK88lBwFR234RSdKDHFLec7c WSfSwz2JRVhcXnUV2ge+ADgTNWt2/FEqPWK8ATYz9Iy4njOtJTaiurEoYOVUQawH LBMYM/o2i0uxpdyFdMwF6bBB1rmTew+iZn8+4iYWp60zBgq8yQr1ws4RiOjhgoNS VM+U5SoGBzMEpWCJAqlOF59qUwkmgY1aQU8jKf+l1xE25v+IC7lwvJq4vFuKu6zL 3kSLHHZNIuHkuiVl2/mwtKHsEyTIppI8/nBjyO+aID8rv4Os9Cm5eEN7Lnq6/kXA aYNjsvtc1A081bDI+7EDXDq9YVAIo08epvp/Yp8eQNHsoxfzdVeENhQ8PxZko7AJ tU9Bi/1FatVMyWQufQJk =ZnOk -----END PGP SIGNATURE----- --==-=-=--