diff options
| author | Lars Ingebrigtsen | 2019-07-29 14:15:03 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-07-29 14:22:38 +0200 |
| commit | 6cfda69d72cb9debefc48d0d95e341d389e7303a (patch) | |
| tree | 031f4d820ab5a0113f25a4d9096c0c5fde98499d /doc/lispref | |
| parent | e4f957fb0794b5616deb0abf792e11132c06e3a9 (diff) | |
| download | emacs-6cfda69d72cb9debefc48d0d95e341d389e7303a.tar.gz emacs-6cfda69d72cb9debefc48d0d95e341d389e7303a.zip | |
Add support for dealing with decoded time structures
* doc/lispref/os.texi (Time Conversion): Document the new
functions that work on decoded time.
(Time Calculations): Document new date/time functions.
* lisp/simple.el (decoded-time-second, decoded-time-minute)
(decoded-time-hour, decoded-time-day, decoded-time-month)
(decoded-time-year, decoded-time-weekday, decoded-time-dst)
(decoded-time-zone): New accessor functions for decoded time values.
* lisp/calendar/time-date.el (date-days-in-month)
(date-ordinal-to-time): New functions.
(decoded-time--alter-month, decoded-time--alter-day)
(decoded-time--alter-second, make-decoded-time): New functions
added to manipulate decoded time structures.
* src/timefns.c (Fdecode_time): Mention the new accessors.
* test/lisp/calendar/time-date-tests.el: New file to test the
decoded time functions and the other new functions.
Diffstat (limited to 'doc/lispref')
| -rw-r--r-- | doc/lispref/os.texi | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index fef954eb7a3..d397a125738 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -1466,6 +1466,60 @@ seconds east of Greenwich. | |||
| 1466 | 1466 | ||
| 1467 | @strong{Common Lisp Note:} Common Lisp has different meanings for | 1467 | @strong{Common Lisp Note:} Common Lisp has different meanings for |
| 1468 | @var{dow} and @var{utcoff}. | 1468 | @var{dow} and @var{utcoff}. |
| 1469 | |||
| 1470 | To access (or alter) the elements in the time value, the | ||
| 1471 | @code{decoded-time-second}, @code{decoded-time-minute}, | ||
| 1472 | @code{decoded-time-hour}, @code{decoded-time-day}, | ||
| 1473 | @code{decoded-time-month}, @code{decoded-time-year}, | ||
| 1474 | @code{decoded-time-weekday}, @code{decoded-time-dst} and | ||
| 1475 | @code{decoded-time-zone} accessors can be used. | ||
| 1476 | |||
| 1477 | For instance, to increase the year in a decoded time, you could say: | ||
| 1478 | |||
| 1479 | @lisp | ||
| 1480 | (setf (decoded-time-year decoded-time) | ||
| 1481 | (+ (decoded-time-year decoded-time) 4)) | ||
| 1482 | @end lisp | ||
| 1483 | |||
| 1484 | Also see the following function. | ||
| 1485 | |||
| 1486 | @end defun | ||
| 1487 | |||
| 1488 | @defun decoded-time-add time delta | ||
| 1489 | This function takes a decoded time structure and adds @var{delta} | ||
| 1490 | (also a decoded time structure) to it. Elements in @var{delta} that | ||
| 1491 | are @code{nil} are ignored. | ||
| 1492 | |||
| 1493 | For instance, if you want ``same time next month'', you | ||
| 1494 | could say: | ||
| 1495 | |||
| 1496 | @lisp | ||
| 1497 | (let ((time (decode-time)) | ||
| 1498 | (delta (make-decoded-time :month 2))) | ||
| 1499 | (encode-time (decoded-time-add time delta))) | ||
| 1500 | @end lisp | ||
| 1501 | |||
| 1502 | If this date doesn't exist (if you're running this on January 31st, | ||
| 1503 | for instance), then the date will be shifted back until you get a | ||
| 1504 | valid date (which will be February 28th or 29th, depending). | ||
| 1505 | |||
| 1506 | Fields are added in a most to least significant order, so if the | ||
| 1507 | adjustment described above happens, it happens before adding days, | ||
| 1508 | hours, minutes or seconds. | ||
| 1509 | |||
| 1510 | The values in @var{delta} can be negative to subtract values instead. | ||
| 1511 | |||
| 1512 | The return value is a decoded time structure. | ||
| 1513 | @end defun | ||
| 1514 | |||
| 1515 | @defun make-decoded-time &key second minute hour day month year dst zone | ||
| 1516 | Return a decoded time structure with only the given keywords filled | ||
| 1517 | out, leaving the rest @code{nil}. For instance, to get a structure | ||
| 1518 | that represents ``two months'', you could say: | ||
| 1519 | |||
| 1520 | @lisp | ||
| 1521 | (make-decoded-time :month 2) | ||
| 1522 | @end lisp | ||
| 1469 | @end defun | 1523 | @end defun |
| 1470 | 1524 | ||
| 1471 | @defun encode-time &optional time form &rest obsolescent-arguments | 1525 | @defun encode-time &optional time form &rest obsolescent-arguments |
| @@ -1867,6 +1921,16 @@ This returns the day number within the year corresponding to @var{time-value}. | |||
| 1867 | This function returns @code{t} if @var{year} is a leap year. | 1921 | This function returns @code{t} if @var{year} is a leap year. |
| 1868 | @end defun | 1922 | @end defun |
| 1869 | 1923 | ||
| 1924 | @defun date-days-in-month year month | ||
| 1925 | Return the number of days in @var{month} in @var{year}. For instance, | ||
| 1926 | there's 29 days in February 2004. | ||
| 1927 | @end defun | ||
| 1928 | |||
| 1929 | @defun date-ordinal-to-time year ordinal | ||
| 1930 | Return the date of @var{ordinal} in @var{year} as a decoded time | ||
| 1931 | structure. For instance, the 120th day in 2004 is April 29th. | ||
| 1932 | @end defun | ||
| 1933 | |||
| 1870 | @node Timers | 1934 | @node Timers |
| 1871 | @section Timers for Delayed Execution | 1935 | @section Timers for Delayed Execution |
| 1872 | @cindex timers | 1936 | @cindex timers |