aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2024-08-14 11:35:48 +0300
committerEli Zaretskii2024-08-14 11:35:48 +0300
commit9bedb957bebdca99b1bb96f58ea790e20ed48dee (patch)
tree3dd7dbd21b40a87cf2550afa5450026c1ab6b94e
parent7c588a00655f70d4a6405642a384f34a6478628d (diff)
downloademacs-9bedb957bebdca99b1bb96f58ea790e20ed48dee.tar.gz
emacs-9bedb957bebdca99b1bb96f58ea790e20ed48dee.zip
Improve documentation of time-parsing functions
* doc/lispref/os.texi (Time Parsing): * lisp/calendar/iso8601.el (iso8601-parse): * lisp/calendar/parse-time.el (parse-time-string): Document that these functions don't care about the distinction between local time and UTC. (Bug#72570)
-rw-r--r--doc/lispref/os.texi46
-rw-r--r--lisp/calendar/iso8601.el10
-rw-r--r--lisp/calendar/parse-time.el6
3 files changed, 54 insertions, 8 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 3ba3da459bf..3ab4b66ba30 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1800,19 +1800,51 @@ structure (@pxref{Time Conversion}). The argument @var{string} should
1800resemble an RFC 822 (or later) or ISO 8601 string, like ``Fri, 25 Mar 1800resemble an RFC 822 (or later) or ISO 8601 string, like ``Fri, 25 Mar
18012016 16:24:56 +0100'' or ``1998-09-12T12:21:54-0200'', but this 18012016 16:24:56 +0100'' or ``1998-09-12T12:21:54-0200'', but this
1802function will attempt to parse less well-formed time strings as well. 1802function will attempt to parse less well-formed time strings as well.
1803
1804Note that, unlike @code{decode-time} (@pxref{Time Conversion}), this
1805function does not interpret the time string, and in particular the
1806values of daylight-saving and timezone or UTC offset parts of the
1807@var{string} argument do not affect the returned value of date and time,
1808they only affect the last two members of the returned decoded time
1809structure. For example, if the time-zone information is present in
1810@var{string}, the decoded time structure will include it; otherwise the
1811time-zone member of the returned value will be @code{nil}. In other
1812words, this function simply parses the textual representation of date
1813and time into separate numerical values, and doesn't care whether the
1814input time is local or UTC.
1815
1816If a Lisp program passes the return value of this function to some other
1817time-related API, it should make sure the @code{nil} members of the
1818decoded time structure are interpreted correctly, and in particular the
1819lack of time-zone information is interpreted as UTC or local time,
1820according to the needs of the calling program.
1803@end defun 1821@end defun
1804 1822
1805@vindex ISO 8601 date/time strings 1823@vindex ISO 8601 date/time strings
1806@defun iso8601-parse string 1824@defun iso8601-parse string
1807For a more strict function (that will error out upon invalid input), 1825For a more strict function (that will error out upon invalid input),
1808this function can be used instead. It can parse all variants of 1826Lisp programs can use this function instead. It can parse all variants
1809the ISO 8601 standard, so in addition to the formats mentioned above, 1827of the ISO 8601 standard, so in addition to the formats mentioned above,
1810it also parses things like ``1998W45-3'' (week number) and 1828it also parses things like ``1998W45-3'' (week number) and ``1998-245''
1811``1998-245'' (ordinal day number). To parse durations, there's 1829(ordinal day number). To parse durations, there's
1812@code{iso8601-parse-duration}, and to parse intervals, there's 1830@code{iso8601-parse-duration}, and to parse intervals, there's
1813@code{iso8601-parse-interval}. All these functions return decoded 1831@code{iso8601-parse-interval}. All these functions return decoded time
1814time structures, except the final one, which returns three of them 1832structures, except the final one, which returns three of them (the
1815(the start, the end, and the duration). 1833start, the end, and the duration).
1834
1835Like @code{parse-time-string}, this function does not interpret the time
1836string, and in particular the time-zone designator or UTC offset that is
1837part of the @var{string} argument does not affect the returned value of
1838date and time, it only affects the last two members of the returned
1839decoded time structure. The ISO 8601 standard specifies that date/time
1840strings that do not include information about UTC relation are assumed
1841to be in local time, but this function does not do that, because it
1842doesn't interpret the time values. For example, if the time-zone
1843information is present in @var{string}, the decoded time structure will
1844include it; otherwise the time-zone member of the returned value will be
1845@code{nil}. In other words, this function simply parses the textual
1846representation of date and time into separate numerical values, and
1847doesn't care whether the input time is local or UTC.
1816@end defun 1848@end defun
1817 1849
1818@defun format-time-string format-string &optional time zone 1850@defun format-time-string format-string &optional time zone
diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el
index a32b52564c9..bb319d54c8c 100644
--- a/lisp/calendar/iso8601.el
+++ b/lisp/calendar/iso8601.el
@@ -122,10 +122,18 @@
122(defun iso8601-parse (string &optional form) 122(defun iso8601-parse (string &optional form)
123 "Parse an ISO 8601 date/time string and return a `decode-time' structure. 123 "Parse an ISO 8601 date/time string and return a `decode-time' structure.
124 124
125The ISO 8601 date/time strings look like \"2008-03-02T13:47:30\", 125The ISO 8601 date/time strings look like \"2008-03-02T13:47:30\"
126or \"2024-04-05T14:30Z\" or \"2024-04-05T12:30−02:00\",
126but shorter, incomplete strings like \"2008-03-02\" are valid, as 127but shorter, incomplete strings like \"2008-03-02\" are valid, as
127well as variants like \"2008W32\" (week number) and 128well as variants like \"2008W32\" (week number) and
128\"2008-234\" (ordinal day number). 129\"2008-234\" (ordinal day number).
130Note that, unlike `decode-time', this function does not interpret
131the time string, and in particular the time-zone designator or UTC
132offset that is part of STRING does not affect the returned value of
133date and time, it only affects the last two members of the returned
134value. This function simply parses the textual representation of
135date and time into separate numerical values, and doesn't care
136whether the time is local or UTC.
129 137
130See `decode-time' for the meaning of FORM." 138See `decode-time' for the meaning of FORM."
131 (if (not (iso8601-valid-p string)) 139 (if (not (iso8601-valid-p string))
diff --git a/lisp/calendar/parse-time.el b/lisp/calendar/parse-time.el
index c34329a4002..f6fc7a8c162 100644
--- a/lisp/calendar/parse-time.el
+++ b/lisp/calendar/parse-time.el
@@ -157,6 +157,12 @@ return a \"likely\" value even for somewhat malformed strings.
157The values returned are identical to those of `decode-time', but 157The values returned are identical to those of `decode-time', but
158any unknown values other than DST are returned as nil, and an 158any unknown values other than DST are returned as nil, and an
159unknown DST value is returned as -1. 159unknown DST value is returned as -1.
160Note that, unlike `decode-time', this function does not interpret
161the time string, and in particular the values of DST and TZ do not
162affect the returned value of date and time, they only affect the
163last two members of the returned value. This function simply
164parses the textual representation of date and time into separate
165numerical values, and doesn't care whether the time is local or UTC.
160 166
161See `decode-time' for the meaning of FORM." 167See `decode-time' for the meaning of FORM."
162 (condition-case () 168 (condition-case ()