diff options
| author | Paul Eggert | 2019-08-16 22:09:04 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-08-16 23:25:07 -0700 |
| commit | 37257d6acadff17bd1e52cfa460950bcb684c5c3 (patch) | |
| tree | ab7088cfa725561c8456f388cff79466948b3532 /doc | |
| parent | d7c9ed8445d13de7350be3360d68717362f89929 (diff) | |
| download | emacs-37257d6acadff17bd1e52cfa460950bcb684c5c3.tar.gz emacs-37257d6acadff17bd1e52cfa460950bcb684c5c3.zip | |
More-compatible subsecond calendrical timestamps
Instead of appending a subseconds member to the result of
‘decode-time’, this keeps the format unchanged unless you give
a new optional argument to ‘decode-time’. Also, the augmented
format now puts the subsecond info in the SECONDS element, so
the total number of elements is unchanged; this is more
compatible with code that expects the traditional 9 elements,
such as ‘(pcase decoded-time (`(,SEC ,MIN ,HOUR ,DAY ,MON
,YEAR ,DOW ,DST ,ZONE) ...) ...)’.
* doc/lispref/os.texi, doc/misc/emacs-mime.texi, etc/NEWS:
* lisp/net/soap-client.el (soap-decode-date-time):
* lisp/simple.el (decoded-time):
Document the new behavior.
* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
* lisp/calendar/iso8601.el (iso8601-parse)
(iso8601-parse-time, iso8601-parse-duration)
(iso8601--decoded-time):
* lisp/calendar/parse-time.el (parse-time-string):
* lisp/calendar/time-date.el (decoded-time-add)
(decoded-time--alter-second):
* lisp/org/org.el (org-parse-time-string):
* lisp/simple.el (decoded-time):
* src/timefns.c (Fdecode_time, Fencode_time):
* test/lisp/calendar/icalendar-tests.el:
(icalendar--decode-isodatetime):
* test/lisp/calendar/iso8601-tests.el (test-iso8601-date-years)
(test-iso8601-date-dates, test-iso8601-date-obsolete)
(test-iso8601-date-weeks, test-iso8601-date-ordinals)
(test-iso8601-time, test-iso8601-combined)
(test-iso8601-duration, test-iso8601-intervals)
(standard-test-dates, standard-test-time-of-day-fractions)
(standard-test-time-of-day-beginning-of-day)
(standard-test-time-of-day-utc)
(standard-test-time-of-day-zone)
(standard-test-date-and-time-of-day, standard-test-interval):
* test/lisp/calendar/parse-time-tests.el (parse-time-tests):
* test/src/timefns-tests.el (format-time-string-with-zone)
(encode-time-dst-numeric-zone):
Revert recent changes that added a SUBSECS member to
calendrical timestamps, since that component is no longer
present (the info, if any, is now in the SECONDS member).
* lisp/calendar/time-date.el (decoded-time-add)
(decoded-time--alter-second):
Support fractional seconds in the new form. Simplify.
* src/timefns.c (Fdecode_time): Support new arg FORM.
(Fencode_time): Support subsecond resolution.
* test/src/timefns-tests.el (format-time-string-with-zone)
(decode-then-encode-time): Test subsecond calendrical timestamps.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/os.texi | 65 | ||||
| -rw-r--r-- | doc/misc/emacs-mime.texi | 2 |
2 files changed, 38 insertions, 29 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index 70ae39e6ab6..49c07380c5f 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -1478,23 +1478,23 @@ Although @code{(time-convert nil nil)} is equivalent to | |||
| 1478 | @end example | 1478 | @end example |
| 1479 | @end defun | 1479 | @end defun |
| 1480 | 1480 | ||
| 1481 | @defun decode-time &optional time zone | 1481 | @defun decode-time &optional time zone form |
| 1482 | This function converts a time value into calendrical information. If | 1482 | This function converts a time value into calendrical information. If |
| 1483 | you don't specify @var{time}, it decodes the current time, and similarly | 1483 | you don't specify @var{time}, it decodes the current time, and similarly |
| 1484 | @var{zone} defaults to the current time zone rule. @xref{Time Zone Rules}. | 1484 | @var{zone} defaults to the current time zone rule. @xref{Time Zone Rules}. |
| 1485 | The return value is a list of ten elements, as follows: | 1485 | The @var{form} argument controls the form of the returned |
| 1486 | @var{seconds} element, as described below. | ||
| 1487 | The return value is a list of nine elements, as follows: | ||
| 1486 | 1488 | ||
| 1487 | @example | 1489 | @example |
| 1488 | (@var{seconds} @var{minutes} @var{hour} @var{day} @var{month} @var{year} | 1490 | (@var{seconds} @var{minutes} @var{hour} @var{day} @var{month} @var{year} @var{dow} @var{dst} @var{utcoff}) |
| 1489 | @var{dow} @var{dst} @var{utcoff} @var{subsec}) | ||
| 1490 | @end example | 1491 | @end example |
| 1491 | 1492 | ||
| 1492 | Here is what the elements mean: | 1493 | Here is what the elements mean: |
| 1493 | 1494 | ||
| 1494 | @table @var | 1495 | @table @var |
| 1495 | @item seconds | 1496 | @item seconds |
| 1496 | The number of seconds past the minute, as an integer between 0 and 59. | 1497 | The number of seconds past the minute, with form described below. |
| 1497 | On some operating systems, this is 60 for leap seconds. | ||
| 1498 | @item minutes | 1498 | @item minutes |
| 1499 | The number of minutes past the hour, as an integer between 0 and 59. | 1499 | The number of minutes past the hour, as an integer between 0 and 59. |
| 1500 | @item hour | 1500 | @item hour |
| @@ -1514,22 +1514,33 @@ in effect, and @minus{}1 if this information is not available. | |||
| 1514 | @item utcoff | 1514 | @item utcoff |
| 1515 | An integer indicating the Universal Time offset in seconds, i.e., the number of | 1515 | An integer indicating the Universal Time offset in seconds, i.e., the number of |
| 1516 | seconds east of Greenwich. | 1516 | seconds east of Greenwich. |
| 1517 | @item subsec | ||
| 1518 | The number of subseconds past the second, as either 0 or a Lisp | ||
| 1519 | timestamp @code{(@var{ticks} . @var{hz})} representing a nonnegative | ||
| 1520 | fraction less than 1. | ||
| 1521 | @end table | 1517 | @end table |
| 1522 | 1518 | ||
| 1519 | The @var{seconds} element is a Lisp timestamp that is nonnegative and | ||
| 1520 | less than 61; it is less than 60 except during positive leap seconds | ||
| 1521 | (assuming the operating system supports leap seconds). If the | ||
| 1522 | optional @var{form} argument is @code{t}, @var{seconds} uses the same | ||
| 1523 | precision as @var{time}; if @var{form} is @code{integer}, | ||
| 1524 | @var{seconds} is truncated to an integer. For example, if @var{time} | ||
| 1525 | is the timestamp @code{(1566009571321 . 1000)}, which represents | ||
| 1526 | 2019-08-17 02:39:31.321 UTC on typical systems that lack leap seconds, | ||
| 1527 | then @code{(decode-time @var{time} t t)} returns @code{((31321 . 1000) | ||
| 1528 | 39 2 17 8 2019 6 nil 0)}, whereas @code{(decode-time @var{time} t | ||
| 1529 | 'integer)} returns @code{(31 39 2 17 8 2019 6 nil 0)}. If @var{form} | ||
| 1530 | is omitted or @code{nil}, it currently defaults to @code{integer} but | ||
| 1531 | this default may change in future Emacs releases, so callers requiring | ||
| 1532 | a particular form should specify @var{form}. | ||
| 1533 | |||
| 1523 | @strong{Common Lisp Note:} Common Lisp has different meanings for | 1534 | @strong{Common Lisp Note:} Common Lisp has different meanings for |
| 1524 | @var{dow} and @var{utcoff}, and lacks @var{subsec}. | 1535 | @var{dow} and @var{utcoff}, and its @var{second} is an integer between |
| 1536 | 0 and 59 inclusive. | ||
| 1525 | 1537 | ||
| 1526 | To access (or alter) the elements in the time value, the | 1538 | To access (or alter) the elements in the time value, the |
| 1527 | @code{decoded-time-second}, @code{decoded-time-minute}, | 1539 | @code{decoded-time-second}, @code{decoded-time-minute}, |
| 1528 | @code{decoded-time-hour}, @code{decoded-time-day}, | 1540 | @code{decoded-time-hour}, @code{decoded-time-day}, |
| 1529 | @code{decoded-time-month}, @code{decoded-time-year}, | 1541 | @code{decoded-time-month}, @code{decoded-time-year}, |
| 1530 | @code{decoded-time-weekday}, @code{decoded-time-dst}, | 1542 | @code{decoded-time-weekday}, @code{decoded-time-dst} and |
| 1531 | @code{decoded-time-zone} and @code{decoded-time-subsec} | 1543 | @code{decoded-time-zone} accessors can be used. |
| 1532 | accessors can be used. | ||
| 1533 | 1544 | ||
| 1534 | For instance, to increase the year in a decoded time, you could say: | 1545 | For instance, to increase the year in a decoded time, you could say: |
| 1535 | 1546 | ||
| @@ -1551,7 +1562,7 @@ For instance, if you want ``same time next month'', you | |||
| 1551 | could say: | 1562 | could say: |
| 1552 | 1563 | ||
| 1553 | @lisp | 1564 | @lisp |
| 1554 | (let ((time (decode-time)) | 1565 | (let ((time (decode-time nil nil t)) |
| 1555 | (delta (make-decoded-time :month 2))) | 1566 | (delta (make-decoded-time :month 2))) |
| 1556 | (encode-time (decoded-time-add time delta))) | 1567 | (encode-time (decoded-time-add time delta))) |
| 1557 | @end lisp | 1568 | @end lisp |
| @@ -1585,22 +1596,21 @@ It can act as the inverse of @code{decode-time}. | |||
| 1585 | 1596 | ||
| 1586 | Ordinarily the first argument is a list | 1597 | Ordinarily the first argument is a list |
| 1587 | @code{(@var{second} @var{minute} @var{hour} @var{day} @var{month} | 1598 | @code{(@var{second} @var{minute} @var{hour} @var{day} @var{month} |
| 1588 | @var{year} @var{ignored} @var{dst} @var{zone} @var{subsec})} that specifies a | 1599 | @var{year} @var{ignored} @var{dst} @var{zone})} that specifies a |
| 1589 | decoded time in the style of @code{decode-time}, so that | 1600 | decoded time in the style of @code{decode-time}, so that |
| 1590 | @code{(encode-time (decode-time ...))} works. For the meanings of | 1601 | @code{(encode-time (decode-time ...))} works. For the meanings of |
| 1591 | these list members, see the table under @code{decode-time}. | 1602 | these list members, see the table under @code{decode-time}. |
| 1592 | 1603 | ||
| 1593 | As an obsolescent calling convention, this function can be given six | 1604 | As an obsolescent calling convention, this function can be given six |
| 1594 | through ten arguments. The first six arguments @var{second}, | 1605 | or more arguments. The first six arguments @var{second}, |
| 1595 | @var{minute}, @var{hour}, @var{day}, @var{month}, and @var{year} | 1606 | @var{minute}, @var{hour}, @var{day}, @var{month}, and @var{year} |
| 1596 | specify most of the components of a decoded time. If there are seven | 1607 | specify most of the components of a decoded time. If there are more |
| 1597 | through nine arguments the @emph{last} argument is used as @var{zone}, | 1608 | than six arguments the @emph{last} argument is used as @var{zone} and |
| 1598 | and if there are ten arguments the ninth specifies @var{zone} and the | 1609 | any other extra arguments are ignored, so that @code{(apply |
| 1599 | tenth specifies @var{subsec}; in either case any other extra arguments | 1610 | #'encode-time (decode-time ...))} works. In this obsolescent |
| 1600 | are ignored, so that @code{(apply #'encode-time (decode-time ...))} | 1611 | convention, @var{zone} defaults to the current time zone rule |
| 1601 | works. In this obsolescent convention, @var{zone} defaults to the | 1612 | (@pxref{Time Zone Rules}), and @var{dst} is treated as if it was |
| 1602 | current time zone rule (@pxref{Time Zone Rules}), @var{subsec} | 1613 | @minus{}1. |
| 1603 | defaults to 0, and @var{dst} is treated as if it was @minus{}1. | ||
| 1604 | 1614 | ||
| 1605 | Year numbers less than 100 are not treated specially. If you want them | 1615 | Year numbers less than 100 are not treated specially. If you want them |
| 1606 | to stand for years above 1900, or years above 2000, you must alter them | 1616 | to stand for years above 1900, or years above 2000, you must alter them |
| @@ -1615,9 +1625,8 @@ the latter to the former as follows: | |||
| 1615 | @end example | 1625 | @end example |
| 1616 | 1626 | ||
| 1617 | You can perform simple date arithmetic by using out-of-range values for | 1627 | You can perform simple date arithmetic by using out-of-range values for |
| 1618 | @var{seconds}, @var{minutes}, @var{hour}, @var{day}, @var{month}, and | 1628 | @var{seconds}, @var{minutes}, @var{hour}, @var{day}, and @var{month}; |
| 1619 | @var{subsec}; for example, day 0 means the day preceding the given | 1629 | for example, day 0 means the day preceding the given month. |
| 1620 | month. | ||
| 1621 | 1630 | ||
| 1622 | The operating system puts limits on the range of possible time values; | 1631 | The operating system puts limits on the range of possible time values; |
| 1623 | if the limits are exceeded while encoding the time, an error results. | 1632 | if the limits are exceeded while encoding the time, an error results. |
diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi index c411bf3d681..eb829b06124 100644 --- a/doc/misc/emacs-mime.texi +++ b/doc/misc/emacs-mime.texi | |||
| @@ -1535,7 +1535,7 @@ Here's a bunch of time/date/second/day examples: | |||
| 1535 | 1535 | ||
| 1536 | @example | 1536 | @example |
| 1537 | (parse-time-string "Sat Sep 12 12:21:54 1998 +0200") | 1537 | (parse-time-string "Sat Sep 12 12:21:54 1998 +0200") |
| 1538 | @result{} (54 21 12 12 9 1998 6 -1 7200 0) | 1538 | @result{} (54 21 12 12 9 1998 6 -1 7200) |
| 1539 | 1539 | ||
| 1540 | (time-convert | 1540 | (time-convert |
| 1541 | (date-to-time "Sat Sep 12 12:21:54 1998 +0200") | 1541 | (date-to-time "Sat Sep 12 12:21:54 1998 +0200") |