comparison lispref/os.texi @ 43037:2f863ec2724c

Document date-to-time and seconds-to-time. New node Time Calculations.
author Richard M. Stallman <rms@gnu.org>
date Fri, 01 Feb 2002 04:28:28 +0000
parents a3a9223b152f
children 340b4384f4ac
comparison
equal deleted inserted replaced
43036:60308a81bc07 43037:2f863ec2724c
21 * System Environment:: Distinguish the name and kind of system. 21 * System Environment:: Distinguish the name and kind of system.
22 * User Identification:: Finding the name and user id of the user. 22 * User Identification:: Finding the name and user id of the user.
23 * Time of Day:: Getting the current time. 23 * Time of Day:: Getting the current time.
24 * Time Conversion:: Converting a time from numeric form to a string, or 24 * Time Conversion:: Converting a time from numeric form to a string, or
25 to calendrical data (or vice versa). 25 to calendrical data (or vice versa).
26 * Time Calculations:: Adding, subtracting, comparing times, etc.
26 * Timers:: Setting a timer to call a function at a certain time. 27 * Timers:: Setting a timer to call a function at a certain time.
27 * Terminal Input:: Recording terminal input for debugging. 28 * Terminal Input:: Recording terminal input for debugging.
28 * Terminal Output:: Recording terminal output for debugging. 29 * Terminal Output:: Recording terminal output for debugging.
29 * Sound Output:: Playing sounds on the computer's speaker. 30 * Sound Output:: Playing sounds on the computer's speaker.
30 * Special Keysyms:: Defining system-specific key symbols for X. 31 * Special Keysyms:: Defining system-specific key symbols for X.
1029 Time conversion functions always use the Gregorian calendar, even for 1030 Time conversion functions always use the Gregorian calendar, even for
1030 dates before the Gregorian calendar was introduced. Year numbers count 1031 dates before the Gregorian calendar was introduced. Year numbers count
1031 the number of years since the year 1 B.C., and do not skip zero as 1032 the number of years since the year 1 B.C., and do not skip zero as
1032 traditional Gregorian years do; for example, the year number @minus{}37 1033 traditional Gregorian years do; for example, the year number @minus{}37
1033 represents the Gregorian year 38 B.C@. 1034 represents the Gregorian year 38 B.C@.
1035
1036 @defun date-to-time string
1037 This function parses the time-string @var{string} and returns the
1038 corresponding time value.
1039 @end defun
1034 1040
1035 @defun format-time-string format-string &optional time universal 1041 @defun format-time-string format-string &optional time universal
1036 This function converts @var{time} (or the current time, if @var{time} is 1042 This function converts @var{time} (or the current time, if @var{time} is
1037 omitted) to a string according to @var{format-string}. The argument 1043 omitted) to a string according to @var{format-string}. The argument
1038 @var{format-string} may contain @samp{%}-sequences which say to 1044 @var{format-string} may contain @samp{%}-sequences which say to
1144 @code{locale-coding-system} (@pxref{Locales}); after @code{strftime} 1150 @code{locale-coding-system} (@pxref{Locales}); after @code{strftime}
1145 returns the resulting string, @code{format-time-string} decodes the 1151 returns the resulting string, @code{format-time-string} decodes the
1146 string using that same coding system. 1152 string using that same coding system.
1147 @end defun 1153 @end defun
1148 1154
1155 @defun seconds-to-time seconds
1156 This function converts @var{seconds}, a floating point number of
1157 seconds since the epoch, to a time value and returns that. To perform
1158 the inverse conversion, use @code{float-time}.
1159 @end defun
1160
1149 @defun decode-time time 1161 @defun decode-time time
1150 This function converts a time value into calendrical information. The 1162 This function converts a time value into calendrical information. The
1151 return value is a list of nine elements, as follows: 1163 return value is a list of nine elements, as follows:
1152 1164
1153 @example 1165 @example
1215 1227
1216 The operating system puts limits on the range of possible time values; 1228 The operating system puts limits on the range of possible time values;
1217 if you try to encode a time that is out of range, an error results. 1229 if you try to encode a time that is out of range, an error results.
1218 @end defun 1230 @end defun
1219 1231
1232 @node Time Calculations
1233 @section Time Calculations
1234
1235 These functions perform calendrical computations using time values
1236 (the kind of list that @code{current-time} returns).
1237
1238 @defun time-less-p t1 t2
1239 This returns @code{t} if time value @var{t1} is less than time value
1240 @var{t2}.
1241 @end defun
1242
1243 @defun time-subtract t1 t2
1244 This returns the time difference @var{t1} @minus{} @var{t2} between
1245 two time values, in the same format as a time value.
1246 @end defun
1247
1248 @defun time-add t1 t2
1249 This returns the sum of two time values, one of which ought to
1250 represent a time difference rather than a point in time.
1251 Here is how to add a number of seconds to a time value:
1252
1253 @example
1254 (time-add @var{time} (seconds-to-time @var{seconds}))
1255 @end example
1256 @end defun
1257
1258 @defun time-to-days time
1259 This function returns the number of days between the beginning of year
1260 1 and @var{time}.
1261 @end defun
1262
1263 @defun time-to-day-in-year time
1264 This returns the day number within the year corresponding to @var{time}.
1265 @end defun
1266
1267 @defun date-leap-year-p year
1268 This function returns @code{t} if @var{year} is a leap year.
1269 @end defun
1270
1220 @node Timers 1271 @node Timers
1221 @section Timers for Delayed Execution 1272 @section Timers for Delayed Execution
1222 @cindex timer 1273 @cindex timer
1223 1274
1224 You can set up a @dfn{timer} to call a function at a specified future time or 1275 You can set up a @dfn{timer} to call a function at a specified future time or