0

The documentation suggests that parse-time-string can be fed ISO 8601 string, such as "1998-09-12T12:21:54-0200". However, (parse-time-string "1998-09-12T12:21:54-0200") returns (nil nil nil nil nil nil nil nil nil).

— Function: parse-time-string string

This function parses the time-string string into a list of the following form:

(sec min hour day mon year dow dst tz)

The format of this list is the same as what decode-time accepts (see Time Conversion), and is described in more detail there. Any element that cannot be determined from the input will be set to nil. The argument string should resemble an RFC 822 (or later) or ISO 8601 string, like “Fri, 25 Mar 2016 16:24:56 +0100” or “1998-09-12T12:21:54-0200”, but this function will attempt to parse less well-formed time strings as well.

Related question: Parsing formatted time string (inverse of format-time-string)

EDIT:

GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.8, cairo version 1.16.0) of 2020-01-13

4
  • 1
    That does seem like a bug! :-)
    – amitp
    Aug 16 '20 at 17:41
  • 1
    It is fixed in upstream emacs: it works fine in GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.13, cairo version 1.16.0) of 2020-04-23
    – NickD
    Aug 16 '20 at 18:58
  • 1
    @NickD: Please consider adding that to an existing answer or adding it as another answer. (Comments can be deleted at any time.)
    – Drew
    Aug 16 '20 at 19:01
  • 1
    @Drew: PTAL....
    – NickD
    Aug 16 '20 at 19:36
1

EDIT:

This bug was reported as bug 39001 and fixed in this commit in upstream emacs. The patch to apply can be found here.

Workaround:

The function parse-iso8601-time-string does parse ISO8601 string but eventually encode it with encode-time. The following snippet does what parse-time-string was supposed to do.

(decode-time 
    (parse-iso8601-time-string "1998-09-12T12:21:54-0200"))

returns

(54 21 16 12 9 1998 6 t 7200)

Note:

The value returned is partially wrong (the last three fields) because

(format-time-string "%Y" (decode-time 
    (parse-iso8601-time-string "1998-09-12T12:21:54-0200")))

is evaluated as 1970.

TODO:

advice parse-time-string to check if its argument string matches parse-time-iso8601-regexp, if it does, apply the snippet above.

1
  • 1
    I hope you don't mind my adding the upstream emacs fix info to your answer. Let me know if you object.
    – NickD
    Aug 16 '20 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.