aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref
diff options
context:
space:
mode:
authorPaul Eggert2014-11-16 20:38:15 -0800
committerPaul Eggert2014-11-16 20:41:22 -0800
commit0921dbc3ab4dcc6b291ef45e46a24b322bbcb885 (patch)
tree0e320978c7d30af415bb7de6e0b8f6735a3ca3d1 /doc/lispref
parent058f56d24f776bdc25bcac86fe1f8969a78374e9 (diff)
downloademacs-0921dbc3ab4dcc6b291ef45e46a24b322bbcb885.tar.gz
emacs-0921dbc3ab4dcc6b291ef45e46a24b322bbcb885.zip
Improve time stamp handling, and be more consistent about it.
This implements a suggestion made in: http://lists.gnu.org/archive/html/emacs-devel/2014-10/msg00587.html Among other things, this means timer.el no longer needs to autoload the time-date module. * doc/lispref/os.texi (Time of Day, Time Conversion, Time Parsing) (Processor Run Time, Time Calculations): Document the new behavior, plus be clearer about the old behavior. (Idle Timers): Take advantage of new functionality. * etc/NEWS: Document the changes. * lisp/allout-widgets.el (allout-elapsed-time-seconds): Doc fix. * lisp/arc-mode.el (archive-ar-summarize): * lisp/calendar/time-date.el (seconds-to-time, days-to-time, time-since): * lisp/emacs-lisp/timer.el (timer-relative-time, timer-event-handler) (run-at-time, with-timeout-suspend, with-timeout-unsuspend): * lisp/net/tramp.el (tramp-time-less-p, tramp-time-subtract): * lisp/proced.el (proced-time-lessp): * lisp/timezone.el (timezone-time-from-absolute): * lisp/type-break.el (type-break-schedule, type-break-time-sum): Simplify by using new functionality. * lisp/calendar/cal-dst.el (calendar-next-time-zone-transition): Do not return time values in obsolete and undocumented (HI . LO) format; use (HI LO) instead. * lisp/calendar/time-date.el (with-decoded-time-value): Treat 'nil' as current time. This is mostly for XEmacs. (encode-time-value, with-decoded-time-value): Obsolete. (time-add, time-subtract, time-less-p): Use no-op autoloads, for XEmacs. Define only if XEmacs, as they're now C builtins in Emacs. * lisp/ldefs-boot.el: Update to match new time-date.el * lisp/proced.el: Do not require time-date. * src/editfns.c (invalid_time): New function. Use it instead of 'error ("Invalid time specification")'. (time_add, time_subtract, time_arith, Ftime_add, Ftime_less_p) (decode_float_time, lisp_to_timespec, lisp_time_struct): New functions. (make_time_tail, make_time): Remove. All uses changed to use new functions or plain list4i. (disassemble_lisp_time): Return effective length if successful. Check that LOW is an integer, if it's combined with other components. (decode_time_components): Decode into struct lisp_time, not struct timespec, so that we can support a wide set of times regardless of whether time_t is signed. Decode plain numbers as seconds since the Epoch, and nil as the current time. (lisp_time_argument, lisp_seconds_argument, Ffloat_time): Reimplement in terms of new functions. (Fencode_time): Just use list2i. (syms_of_editfns): Add time-add, time-subtract, time-less-p. * src/keyboard.c (decode_timer): Don't allow the new formats (floating point or nil) in timers. * src/systime.h (LO_TIME_BITS): New constant. Use it everywhere in place of the magic number '16'. (struct lisp_time): New type. (decode_time_components): Use it. (lisp_to_timespec): New decl.
Diffstat (limited to 'doc/lispref')
-rw-r--r--doc/lispref/ChangeLog8
-rw-r--r--doc/lispref/os.texi133
2 files changed, 75 insertions, 66 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index b7423af07ba..0a8a0a88cce 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,11 @@
12014-11-17 Paul Eggert <eggert@cs.ucla.edu>
2
3 Improve time stamp handling, and be more consistent about it.
4 * os.texi (Time of Day, Time Conversion, Time Parsing)
5 (Processor Run Time, Time Calculations):
6 Document the new behavior, plus be clearer about the old behavior.
7 (Idle Timers): Take advantage of new functionality.
8
12014-11-16 Lars Magne Ingebrigtsen <larsi@gnus.org> 92014-11-16 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 10
3 * text.texi (Special Properties): Mention `inhibit-read-only'. 11 * text.texi (Special Properties): Mention `inhibit-read-only'.
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 167ecb372b5..b7094479db2 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1213,37 +1213,34 @@ return value is @code{nil}.
1213zone. 1213zone.
1214 1214
1215@cindex epoch 1215@cindex epoch
1216 Most of these functions represent time as a list of either four 1216 Most of these functions represent time as a list of four integers
1217integers, @code{(@var{sec-high} @var{sec-low} @var{microsec} 1217@code{(@var{sec-high} @var{sec-low} @var{microsec} @var{picosec})}.
1218@var{picosec})}, or of three 1218This represents the number of seconds from the @dfn{epoch} (January
1219integers, @code{(@var{sec-high} @var{sec-low} @var{microsec})}, or of 12191, 1970 at 00:00 UTC), using the formula:
1220two integers, @code{(@var{sec-high} @var{sec-low})}. The integers
1221@var{sec-high} and @var{sec-low} give the high and low bits of an
1222integer number of seconds. This integer,
1223@ifnottex 1220@ifnottex
1224@var{high} * 2**16 + @var{low}, 1221@var{high} * 2**16 + @var{low} + @var{micro} * 10**@minus{}6 +
1222@var{pico} * 10**@minus{}12.
1225@end ifnottex 1223@end ifnottex
1226@tex 1224@tex
1227$high*2^{16}+low$, 1225$high*2^{16} + low + micro*10^{-6} + pico*10^{-12}$.
1228@end tex 1226@end tex
1229is the number of seconds from the @dfn{epoch} (January 1, 1970 at 00:00 1227The return value of @code{current-time} represents time using this
1230UTC) to the specified time. The third list element @var{microsec}, if 1228form, as do the timestamps in the return values of other functions
1231present, gives the number of microseconds from the start of that 1229such as @code{file-attributes} (@pxref{Definition of
1232second to the specified time. 1230file-attributes}). In some cases, functions may return two- or
1233Similarly, the fourth list element @var{picosec}, if present, gives 1231three-element lists, with omitted @var{microsec} and @var{picosec}
1234the number of picoseconds from the start of that microsecond to the 1232components defaulting to zero.
1235specified time. 1233
1236 1234@cindex time value
1237 The return value of @code{current-time} represents time using four 1235 Function arguments, e.g., the @var{time-value} argument to
1238integers, as do the timestamps in the return value of 1236@code{current-time-string}, accept a more-general @dfn{time value}
1239@code{file-attributes} (@pxref{Definition of 1237format, which can be a list of integers as above, or a single number
1240file-attributes}). In function arguments, e.g., the @var{time-value} 1238for seconds since the epoch, or @code{nil} for the current time. You
1241argument to @code{current-time-string}, two-, three-, and four-integer 1239can convert a time value into a human-readable string using
1242lists are accepted. You can convert times from the list 1240@code{current-time-string} and @code{format-time-string}, into a list
1243representation into standard human-readable strings using 1241of integers using @code{seconds-to-time}, and into other forms using
1244@code{current-time-string}, or to other forms using the 1242@code{decode-time} and @code{float-time}. These functions are
1245@code{decode-time} and @code{format-time-string} functions documented 1243described in the following sections.
1246in the following sections.
1247 1244
1248@defun current-time-string &optional time-value 1245@defun current-time-string &optional time-value
1249This function returns the current time and date as a human-readable 1246This function returns the current time and date as a human-readable
@@ -1256,8 +1253,8 @@ characters from the beginning of the string rather than from the end,
1256as the year might not have exactly four digits, and additional 1253as the year might not have exactly four digits, and additional
1257information may some day be added at the end. 1254information may some day be added at the end.
1258 1255
1259The argument @var{time-value}, if given, specifies a time to format 1256The argument @var{time-value}, if given, specifies a time to format,
1260(represented as a list of integers), instead of the current time. 1257instead of the current time.
1261 1258
1262@example 1259@example
1263@group 1260@group
@@ -1279,11 +1276,19 @@ become available.
1279@defun float-time &optional time-value 1276@defun float-time &optional time-value
1280This function returns the current time as a floating-point number of 1277This function returns the current time as a floating-point number of
1281seconds since the epoch. The optional argument @var{time-value}, if 1278seconds since the epoch. The optional argument @var{time-value}, if
1282given, specifies a time (represented as a list of integers) to convert 1279given, specifies a time to convert instead of the current time.
1283instead of the current time.
1284 1280
1285@emph{Warning}: Since the result is floating point, it may not be 1281@emph{Warning}: Since the result is floating point, it may not be
1286exact. Do not use this function if precise time stamps are required. 1282exact. Do not use this function if precise time stamps are required.
1283
1284@code{time-to-seconds} is an alias for this function.
1285@end defun
1286
1287@defun seconds-to-time time-value
1288This function converts a time value to list-of-integer form.
1289For example, if @var{time-value} is a number, @code{(time-to-seconds
1290(seconds-to-time @var{time-value}))} equals the number unless overflow
1291or rounding errors occur.
1287@end defun 1292@end defun
1288 1293
1289@defun current-time-zone &optional time-value 1294@defun current-time-zone &optional time-value
@@ -1302,8 +1307,8 @@ adjustment, then the value is constant through time.
1302If the operating system doesn't supply all the information necessary to 1307If the operating system doesn't supply all the information necessary to
1303compute the value, the unknown elements of the list are @code{nil}. 1308compute the value, the unknown elements of the list are @code{nil}.
1304 1309
1305The argument @var{time-value}, if given, specifies a time (represented 1310The argument @var{time-value}, if given, specifies a time value to
1306as a list of integers) to analyze instead of the current time. 1311analyze instead of the current time.
1307@end defun 1312@end defun
1308 1313
1309The current time zone is determined by the @env{TZ} environment 1314The current time zone is determined by the @env{TZ} environment
@@ -1316,15 +1321,15 @@ time zone.
1316@section Time Conversion 1321@section Time Conversion
1317@cindex calendrical information 1322@cindex calendrical information
1318 1323
1319 These functions convert time values (lists of two to four integers, 1324 These functions convert time values (@pxref{Time of Day}) into
1320as explained in the previous section) into calendrical information and 1325calendrical information and vice versa.
1321vice versa.
1322 1326
1323 Many 32-bit operating systems are limited to time values containing 1327 Many 32-bit operating systems are limited to system times containing
132432 bits of information; these systems typically handle only the times 132832 bits of information in their seconds component; these systems
1325from 1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC@. 1329typically handle only the times from 1901-12-13 20:45:52 UTC through
1326However, 64-bit and some 32-bit operating systems have larger time 13302038-01-19 03:14:07 UTC@. However, 64-bit and some 32-bit operating
1327values, and can represent times far in the past or future. 1331systems have larger seconds components, and can represent times far in
1332the past or future.
1328 1333
1329 Time conversion functions always use the Gregorian calendar, even 1334 Time conversion functions always use the Gregorian calendar, even
1330for dates before the Gregorian calendar was introduced. Year numbers 1335for dates before the Gregorian calendar was introduced. Year numbers
@@ -1332,9 +1337,9 @@ count the number of years since the year 1 B.C., and do not skip zero
1332as traditional Gregorian years do; for example, the year number 1337as traditional Gregorian years do; for example, the year number
1333@minus{}37 represents the Gregorian year 38 B.C@. 1338@minus{}37 represents the Gregorian year 38 B.C@.
1334 1339
1335@defun decode-time &optional time 1340@defun decode-time &optional time-value
1336This function converts a time value into calendrical information. If 1341This function converts a time value into calendrical information. If
1337you don't specify @var{time}, it decodes the current time. The return 1342you don't specify @var{time-value}, it decodes the current time. The return
1338value is a list of nine elements, as follows: 1343value is a list of nine elements, as follows:
1339 1344
1340@example 1345@example
@@ -1373,8 +1378,9 @@ Greenwich.
1373 1378
1374@defun encode-time seconds minutes hour day month year &optional zone 1379@defun encode-time seconds minutes hour day month year &optional zone
1375This function is the inverse of @code{decode-time}. It converts seven 1380This function is the inverse of @code{decode-time}. It converts seven
1376items of calendrical data into a time value. For the meanings of the 1381items of calendrical data into a list-of-integer time value. For the
1377arguments, see the table above under @code{decode-time}. 1382meanings of the arguments, see the table above under
1383@code{decode-time}.
1378 1384
1379Year numbers less than 100 are not treated specially. If you want them 1385Year numbers less than 100 are not treated specially. If you want them
1380to stand for years above 1900, or years above 2000, you must alter them 1386to stand for years above 1900, or years above 2000, you must alter them
@@ -1418,9 +1424,11 @@ This function parses the time-string @var{string} and returns the
1418corresponding time value. 1424corresponding time value.
1419@end defun 1425@end defun
1420 1426
1421@defun format-time-string format-string &optional time universal 1427@defun format-time-string format-string &optional time-value universal
1422This function converts @var{time} (or the current time, if @var{time} is 1428
1423omitted) to a string according to @var{format-string}. The argument 1429This function converts @var{time-value} (or the current time, if
1430@var{time-value} is omitted) to a string according to
1431@var{format-string}. The argument
1424@var{format-string} may contain @samp{%}-sequences which say to 1432@var{format-string} may contain @samp{%}-sequences which say to
1425substitute parts of the time. Here is a table of what the 1433substitute parts of the time. Here is a table of what the
1426@samp{%}-sequences mean: 1434@samp{%}-sequences mean:
@@ -1540,12 +1548,6 @@ specified by @code{locale-coding-system} (@pxref{Locales}); after
1540system. 1548system.
1541@end defun 1549@end defun
1542 1550
1543@defun seconds-to-time seconds
1544This function converts @var{seconds}, the number of seconds since the
1545epoch, to a time value and returns that. To convert back, use
1546@code{float-time} (@pxref{Time of Day}).
1547@end defun
1548
1549@defun format-seconds format-string seconds 1551@defun format-seconds format-string seconds
1550This function converts its argument @var{seconds} into a string of 1552This function converts its argument @var{seconds} into a string of
1551years, days, hours, etc., according to @var{format-string}. The 1553years, days, hours, etc., according to @var{format-string}. The
@@ -1619,7 +1621,7 @@ When called interactively, it prints the uptime in the echo area.
1619 1621
1620@defun get-internal-run-time 1622@defun get-internal-run-time
1621This function returns the processor run time used by Emacs as a list 1623This function returns the processor run time used by Emacs as a list
1622of four integers: @code{(@var{high} @var{low} @var{microsec} 1624of four integers: @code{(@var{sec-high} @var{sec-low} @var{microsec}
1623@var{picosec})}, using the same format as @code{current-time} 1625@var{picosec})}, using the same format as @code{current-time}
1624(@pxref{Time of Day}). 1626(@pxref{Time of Day}).
1625 1627
@@ -1643,7 +1645,7 @@ interactively, it prints the duration in the echo area.
1643@section Time Calculations 1645@section Time Calculations
1644 1646
1645 These functions perform calendrical computations using time values 1647 These functions perform calendrical computations using time values
1646(the kind of list that @code{current-time} returns). 1648(@pxref{Time of Day}).
1647 1649
1648@defun time-less-p t1 t2 1650@defun time-less-p t1 t2
1649This returns @code{t} if time value @var{t1} is less than time value 1651This returns @code{t} if time value @var{t1} is less than time value
@@ -1652,26 +1654,26 @@ This returns @code{t} if time value @var{t1} is less than time value
1652 1654
1653@defun time-subtract t1 t2 1655@defun time-subtract t1 t2
1654This returns the time difference @var{t1} @minus{} @var{t2} between 1656This returns the time difference @var{t1} @minus{} @var{t2} between
1655two time values, in the same format as a time value. 1657two time values, as a time value.
1656@end defun 1658@end defun
1657 1659
1658@defun time-add t1 t2 1660@defun time-add t1 t2
1659This returns the sum of two time values, one of which ought to 1661This returns the sum of two time values, as a time value.
1660represent a time difference rather than a point in time. 1662One argument should represent a time difference rather than a point in time.
1661Here is how to add a number of seconds to a time value: 1663Here is how to add a number of seconds to a time value:
1662 1664
1663@example 1665@example
1664(time-add @var{time} (seconds-to-time @var{seconds})) 1666(time-add @var{time} @var{seconds})
1665@end example 1667@end example
1666@end defun 1668@end defun
1667 1669
1668@defun time-to-days time 1670@defun time-to-days time-value
1669This function returns the number of days between the beginning of year 1671This function returns the number of days between the beginning of year
16701 and @var{time}. 16721 and @var{time-value}.
1671@end defun 1673@end defun
1672 1674
1673@defun time-to-day-in-year time 1675@defun time-to-day-in-year time-value
1674This returns the day number within the year corresponding to @var{time}. 1676This returns the day number within the year corresponding to @var{time-value}.
1675@end defun 1677@end defun
1676 1678
1677@defun date-leap-year-p year 1679@defun date-leap-year-p year
@@ -1915,8 +1917,7 @@ idleness. Here's an example:
1915 (run-with-idle-timer 1917 (run-with-idle-timer
1916 ;; Compute an idle time @var{break-length} 1918 ;; Compute an idle time @var{break-length}
1917 ;; more than the current value. 1919 ;; more than the current value.
1918 (time-add (current-idle-time) 1920 (time-add (current-idle-time) @var{break-length})
1919 (seconds-to-time @var{break-length}))
1920 nil 1921 nil
1921 'my-timer-function)))) 1922 'my-timer-function))))
1922@end example 1923@end example