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

Firmin Martin
  • 1,265
  • 7
  • 23

1 Answers1

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.

NickD
  • 27,023
  • 3
  • 23
  • 42
Firmin Martin
  • 1,265
  • 7
  • 23
  • 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
  • It appears that `(format-time-string "%Y" (decode-time (parse-iso8601-time-string "1998-09-12T12:21:54-0200")))` still evaluates to 1970. Emacs 28.1. – Linus Arver Sep 01 '22 at 06:50