GNU bug report logs - #25086
[PATCH] Fix the timezone detection of parse-iso8601-time-string.

Previous Next

Package: emacs;

Reported by: Hong Xu <hong <at> topbug.net>

Date: Fri, 2 Dec 2016 03:48:02 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#25086: closed ([PATCH] Fix the timezone detection of
 parse-iso8601-time-string.)
Date: Sat, 24 Dec 2016 12:42:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Sat, 24 Dec 2016 14:41:09 +0200
with message-id <834m1tzehm.fsf <at> gnu.org>
and subject line Re: bug#25086: [PATCH] Fix the timezone detection of parse-iso8601-time-string.
has caused the debbugs.gnu.org bug report #25086,
regarding [PATCH] Fix the timezone detection of parse-iso8601-time-string.
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
25086: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=25086
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Hong Xu <hong <at> topbug.net>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Fix the timezone detection of parse-iso8601-time-string.
Date: Thu,  1 Dec 2016 19:46:48 -0800
	* 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




[Message part 3 (message/rfc822, inline)]
From: Eli Zaretskii <eliz <at> gnu.org>
To: Hong Xu <hong <at> topbug.net>
Cc: 25086-done <at> debbugs.gnu.org
Subject: Re: bug#25086: [PATCH] Fix the timezone detection of
 parse-iso8601-time-string.
Date: Sat, 24 Dec 2016 14:41:09 +0200
> From: Hong Xu <hong <at> topbug.net>
> Cc: 25086 <at> debbugs.gnu.org
> Date: Sat, 17 Dec 2016 19:11:58 -0800
> 
> On 2016-12-17 Sat 12:42 GMT-0800, Hong Xu <hong <at> topbug.net> wrote:
> >
> > 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.
> 
> Attached is a newer version which has fixed a few edge cases.

Thanks, pushed to master.

I didn't make parse-iso8601-time-string autoloaded.  I don't think
it's needed; if you think it is, please tell why.

Also, a minor not about log messages:

>         * 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.

These are changes in the same function and the same source file.  So
they should be written together, like this:

	* parse-time.el (parse-iso8601-time-string): Fix timezone
	parsing.  Add a doc string.

Thank you for your contribution and for your patience.


This bug report was last modified 8 years and 201 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.