diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2019-07-29 14:15:03 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2019-07-29 14:22:38 +0200 |
commit | 6cfda69d72cb9debefc48d0d95e341d389e7303a (patch) | |
tree | 031f4d820ab5a0113f25a4d9096c0c5fde98499d /doc/lispref | |
parent | e4f957fb0794b5616deb0abf792e11132c06e3a9 (diff) | |
download | emacs-6cfda69d72cb9debefc48d0d95e341d389e7303a.tar.gz |
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. @strong{Common Lisp Note:} Common Lisp has different meanings for @var{dow} and @var{utcoff}. + +To access (or alter) the elements in the time value, the +@code{decoded-time-second}, @code{decoded-time-minute}, +@code{decoded-time-hour}, @code{decoded-time-day}, +@code{decoded-time-month}, @code{decoded-time-year}, +@code{decoded-time-weekday}, @code{decoded-time-dst} and +@code{decoded-time-zone} accessors can be used. + +For instance, to increase the year in a decoded time, you could say: + +@lisp +(setf (decoded-time-year decoded-time) + (+ (decoded-time-year decoded-time) 4)) +@end lisp + +Also see the following function. + +@end defun + +@defun decoded-time-add time delta +This function takes a decoded time structure and adds @var{delta} +(also a decoded time structure) to it. Elements in @var{delta} that +are @code{nil} are ignored. + +For instance, if you want ``same time next month'', you +could say: + +@lisp +(let ((time (decode-time)) + (delta (make-decoded-time :month 2))) + (encode-time (decoded-time-add time delta))) +@end lisp + +If this date doesn't exist (if you're running this on January 31st, +for instance), then the date will be shifted back until you get a +valid date (which will be February 28th or 29th, depending). + +Fields are added in a most to least significant order, so if the +adjustment described above happens, it happens before adding days, +hours, minutes or seconds. + +The values in @var{delta} can be negative to subtract values instead. + +The return value is a decoded time structure. +@end defun + +@defun make-decoded-time &key second minute hour day month year dst zone +Return a decoded time structure with only the given keywords filled +out, leaving the rest @code{nil}. For instance, to get a structure +that represents ``two months'', you could say: + +@lisp +(make-decoded-time :month 2) +@end lisp @end defun @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}. This function returns @code{t} if @var{year} is a leap year. @end defun +@defun date-days-in-month year month +Return the number of days in @var{month} in @var{year}. For instance, +there's 29 days in February 2004. +@end defun + +@defun date-ordinal-to-time year ordinal +Return the date of @var{ordinal} in @var{year} as a decoded time +structure. For instance, the 120th day in 2004 is April 29th. +@end defun + @node Timers @section Timers for Delayed Execution @cindex timers |