diff options
| author | Eli Zaretskii | 2024-08-14 11:35:48 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2024-08-14 11:35:48 +0300 |
| commit | 9bedb957bebdca99b1bb96f58ea790e20ed48dee (patch) | |
| tree | 3dd7dbd21b40a87cf2550afa5450026c1ab6b94e | |
| parent | 7c588a00655f70d4a6405642a384f34a6478628d (diff) | |
| download | emacs-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.texi | 46 | ||||
| -rw-r--r-- | lisp/calendar/iso8601.el | 10 | ||||
| -rw-r--r-- | lisp/calendar/parse-time.el | 6 |
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 | |||
| 1800 | resemble an RFC 822 (or later) or ISO 8601 string, like ``Fri, 25 Mar | 1800 | resemble an RFC 822 (or later) or ISO 8601 string, like ``Fri, 25 Mar |
| 1801 | 2016 16:24:56 +0100'' or ``1998-09-12T12:21:54-0200'', but this | 1801 | 2016 16:24:56 +0100'' or ``1998-09-12T12:21:54-0200'', but this |
| 1802 | function will attempt to parse less well-formed time strings as well. | 1802 | function will attempt to parse less well-formed time strings as well. |
| 1803 | |||
| 1804 | Note that, unlike @code{decode-time} (@pxref{Time Conversion}), this | ||
| 1805 | function does not interpret the time string, and in particular the | ||
| 1806 | values 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, | ||
| 1808 | they only affect the last two members of the returned decoded time | ||
| 1809 | structure. For example, if the time-zone information is present in | ||
| 1810 | @var{string}, the decoded time structure will include it; otherwise the | ||
| 1811 | time-zone member of the returned value will be @code{nil}. In other | ||
| 1812 | words, this function simply parses the textual representation of date | ||
| 1813 | and time into separate numerical values, and doesn't care whether the | ||
| 1814 | input time is local or UTC. | ||
| 1815 | |||
| 1816 | If a Lisp program passes the return value of this function to some other | ||
| 1817 | time-related API, it should make sure the @code{nil} members of the | ||
| 1818 | decoded time structure are interpreted correctly, and in particular the | ||
| 1819 | lack of time-zone information is interpreted as UTC or local time, | ||
| 1820 | according 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 |
| 1807 | For a more strict function (that will error out upon invalid input), | 1825 | For a more strict function (that will error out upon invalid input), |
| 1808 | this function can be used instead. It can parse all variants of | 1826 | Lisp programs can use this function instead. It can parse all variants |
| 1809 | the ISO 8601 standard, so in addition to the formats mentioned above, | 1827 | of the ISO 8601 standard, so in addition to the formats mentioned above, |
| 1810 | it also parses things like ``1998W45-3'' (week number) and | 1828 | it 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 |
| 1814 | time structures, except the final one, which returns three of them | 1832 | structures, except the final one, which returns three of them (the |
| 1815 | (the start, the end, and the duration). | 1833 | start, the end, and the duration). |
| 1834 | |||
| 1835 | Like @code{parse-time-string}, this function does not interpret the time | ||
| 1836 | string, and in particular the time-zone designator or UTC offset that is | ||
| 1837 | part of the @var{string} argument does not affect the returned value of | ||
| 1838 | date and time, it only affects the last two members of the returned | ||
| 1839 | decoded time structure. The ISO 8601 standard specifies that date/time | ||
| 1840 | strings that do not include information about UTC relation are assumed | ||
| 1841 | to be in local time, but this function does not do that, because it | ||
| 1842 | doesn't interpret the time values. For example, if the time-zone | ||
| 1843 | information is present in @var{string}, the decoded time structure will | ||
| 1844 | include it; otherwise the time-zone member of the returned value will be | ||
| 1845 | @code{nil}. In other words, this function simply parses the textual | ||
| 1846 | representation of date and time into separate numerical values, and | ||
| 1847 | doesn'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 | ||
| 125 | The ISO 8601 date/time strings look like \"2008-03-02T13:47:30\", | 125 | The ISO 8601 date/time strings look like \"2008-03-02T13:47:30\" |
| 126 | or \"2024-04-05T14:30Z\" or \"2024-04-05T12:30−02:00\", | ||
| 126 | but shorter, incomplete strings like \"2008-03-02\" are valid, as | 127 | but shorter, incomplete strings like \"2008-03-02\" are valid, as |
| 127 | well as variants like \"2008W32\" (week number) and | 128 | well as variants like \"2008W32\" (week number) and |
| 128 | \"2008-234\" (ordinal day number). | 129 | \"2008-234\" (ordinal day number). |
| 130 | Note that, unlike `decode-time', this function does not interpret | ||
| 131 | the time string, and in particular the time-zone designator or UTC | ||
| 132 | offset that is part of STRING does not affect the returned value of | ||
| 133 | date and time, it only affects the last two members of the returned | ||
| 134 | value. This function simply parses the textual representation of | ||
| 135 | date and time into separate numerical values, and doesn't care | ||
| 136 | whether the time is local or UTC. | ||
| 129 | 137 | ||
| 130 | See `decode-time' for the meaning of FORM." | 138 | See `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. | |||
| 157 | The values returned are identical to those of `decode-time', but | 157 | The values returned are identical to those of `decode-time', but |
| 158 | any unknown values other than DST are returned as nil, and an | 158 | any unknown values other than DST are returned as nil, and an |
| 159 | unknown DST value is returned as -1. | 159 | unknown DST value is returned as -1. |
| 160 | Note that, unlike `decode-time', this function does not interpret | ||
| 161 | the time string, and in particular the values of DST and TZ do not | ||
| 162 | affect the returned value of date and time, they only affect the | ||
| 163 | last two members of the returned value. This function simply | ||
| 164 | parses the textual representation of date and time into separate | ||
| 165 | numerical values, and doesn't care whether the time is local or UTC. | ||
| 160 | 166 | ||
| 161 | See `decode-time' for the meaning of FORM." | 167 | See `decode-time' for the meaning of FORM." |
| 162 | (condition-case () | 168 | (condition-case () |