diff options
| author | Richard M. Stallman | 2005-08-11 19:47:10 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-08-11 19:47:10 +0000 |
| commit | 4bdbd317857c6c49ae1e87f5e1ba91a7e120a6d0 (patch) | |
| tree | 1ad11b6dd41a59c5b7a1dd9ecabf002cc98f1003 | |
| parent | 088767cbda69d1d0d52297fafe145c36d8b006a2 (diff) | |
| download | emacs-4bdbd317857c6c49ae1e87f5e1ba91a7e120a6d0.tar.gz emacs-4bdbd317857c6c49ae1e87f5e1ba91a7e120a6d0.zip | |
(Time Parsing): New node split out of Time Conversion.
| -rw-r--r-- | lispref/os.texi | 179 |
1 files changed, 93 insertions, 86 deletions
diff --git a/lispref/os.texi b/lispref/os.texi index 52108907e9c..3f00ae99cf0 100644 --- a/lispref/os.texi +++ b/lispref/os.texi | |||
| @@ -21,8 +21,10 @@ pertaining to the terminal and the screen. | |||
| 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 |
| 25 | to calendrical data (or vice versa). | 25 | to calendrical data, and vice versa). |
| 26 | * Time Parsing:: Converting a time from numeric form to text | ||
| 27 | and vice versa. | ||
| 26 | * Processor Run Time:: Getting the run time used by Emacs. | 28 | * Processor Run Time:: Getting the run time used by Emacs. |
| 27 | * Time Calculations:: Adding, subtracting, comparing times, etc. | 29 | * Time Calculations:: Adding, subtracting, comparing times, etc. |
| 28 | * Timers:: Setting a timer to call a function at a certain time. | 30 | * Timers:: Setting a timer to call a function at a certain time. |
| @@ -1071,22 +1073,102 @@ exact. Do not use this function if precise time stamps are required. | |||
| 1071 | @section Time Conversion | 1073 | @section Time Conversion |
| 1072 | 1074 | ||
| 1073 | These functions convert time values (lists of two or three integers) | 1075 | These functions convert time values (lists of two or three integers) |
| 1074 | to strings or to calendrical information. There is also a function to | 1076 | to calendrical information and vice versa. You can get time values |
| 1075 | convert calendrical information to a time value. You can get time | 1077 | from the functions @code{current-time} (@pxref{Time of Day}) and |
| 1076 | values from the functions @code{current-time} (@pxref{Time of Day}) and | ||
| 1077 | @code{file-attributes} (@pxref{Definition of file-attributes}). | 1078 | @code{file-attributes} (@pxref{Definition of file-attributes}). |
| 1078 | 1079 | ||
| 1079 | Many operating systems are limited to time values that contain 32 bits | 1080 | Many operating systems are limited to time values that contain 32 bits |
| 1080 | of information; these systems typically handle only the times from | 1081 | of information; these systems typically handle only the times from |
| 1081 | 1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC. However, some | 1082 | 1901-12-13 20:45:52 UTC through 2038-01-19 03:14:07 UTC. However, some |
| 1082 | operating systems have larger time values, and can represent times far | 1083 | operating systems have larger time values, and can represent times far |
| 1083 | in the past or future. | 1084 | in the past or future. |
| 1084 | 1085 | ||
| 1085 | Time conversion functions always use the Gregorian calendar, even for | 1086 | Time conversion functions always use the Gregorian calendar, even |
| 1086 | dates before the Gregorian calendar was introduced. Year numbers count | 1087 | for dates before the Gregorian calendar was introduced. Year numbers |
| 1087 | the number of years since the year 1 B.C., and do not skip zero as | 1088 | count the number of years since the year 1 B.C., and do not skip zero |
| 1088 | traditional Gregorian years do; for example, the year number @minus{}37 | 1089 | as traditional Gregorian years do; for example, the year number |
| 1089 | represents the Gregorian year 38 B.C@. | 1090 | @minus{}37 represents the Gregorian year 38 B.C@. |
| 1091 | |||
| 1092 | @defun decode-time &optional time | ||
| 1093 | This function converts a time value into calendrical information. If | ||
| 1094 | you don't specify @var{time}, it decodes the current time. The return | ||
| 1095 | value is a list of nine elements, as follows: | ||
| 1096 | |||
| 1097 | @example | ||
| 1098 | (@var{seconds} @var{minutes} @var{hour} @var{day} @var{month} @var{year} @var{dow} @var{dst} @var{zone}) | ||
| 1099 | @end example | ||
| 1100 | |||
| 1101 | Here is what the elements mean: | ||
| 1102 | |||
| 1103 | @table @var | ||
| 1104 | @item seconds | ||
| 1105 | The number of seconds past the minute, as an integer between 0 and 59. | ||
| 1106 | On some operating systems, this is 60 for leap seconds. | ||
| 1107 | @item minutes | ||
| 1108 | The number of minutes past the hour, as an integer between 0 and 59. | ||
| 1109 | @item hour | ||
| 1110 | The hour of the day, as an integer between 0 and 23. | ||
| 1111 | @item day | ||
| 1112 | The day of the month, as an integer between 1 and 31. | ||
| 1113 | @item month | ||
| 1114 | The month of the year, as an integer between 1 and 12. | ||
| 1115 | @item year | ||
| 1116 | The year, an integer typically greater than 1900. | ||
| 1117 | @item dow | ||
| 1118 | The day of week, as an integer between 0 and 6, where 0 stands for | ||
| 1119 | Sunday. | ||
| 1120 | @item dst | ||
| 1121 | @code{t} if daylight savings time is effect, otherwise @code{nil}. | ||
| 1122 | @item zone | ||
| 1123 | An integer indicating the time zone, as the number of seconds east of | ||
| 1124 | Greenwich. | ||
| 1125 | @end table | ||
| 1126 | |||
| 1127 | @strong{Common Lisp Note:} Common Lisp has different meanings for | ||
| 1128 | @var{dow} and @var{zone}. | ||
| 1129 | @end defun | ||
| 1130 | |||
| 1131 | @defun encode-time seconds minutes hour day month year &optional zone | ||
| 1132 | This function is the inverse of @code{decode-time}. It converts seven | ||
| 1133 | items of calendrical data into a time value. For the meanings of the | ||
| 1134 | arguments, see the table above under @code{decode-time}. | ||
| 1135 | |||
| 1136 | Year numbers less than 100 are not treated specially. If you want them | ||
| 1137 | to stand for years above 1900, or years above 2000, you must alter them | ||
| 1138 | yourself before you call @code{encode-time}. | ||
| 1139 | |||
| 1140 | The optional argument @var{zone} defaults to the current time zone and | ||
| 1141 | its daylight savings time rules. If specified, it can be either a list | ||
| 1142 | (as you would get from @code{current-time-zone}), a string as in the | ||
| 1143 | @code{TZ} environment variable, @code{t} for Universal Time, or an | ||
| 1144 | integer (as you would get from @code{decode-time}). The specified | ||
| 1145 | zone is used without any further alteration for daylight savings time. | ||
| 1146 | |||
| 1147 | If you pass more than seven arguments to @code{encode-time}, the first | ||
| 1148 | six are used as @var{seconds} through @var{year}, the last argument is | ||
| 1149 | used as @var{zone}, and the arguments in between are ignored. This | ||
| 1150 | feature makes it possible to use the elements of a list returned by | ||
| 1151 | @code{decode-time} as the arguments to @code{encode-time}, like this: | ||
| 1152 | |||
| 1153 | @example | ||
| 1154 | (apply 'encode-time (decode-time @dots{})) | ||
| 1155 | @end example | ||
| 1156 | |||
| 1157 | You can perform simple date arithmetic by using out-of-range values for | ||
| 1158 | the @var{seconds}, @var{minutes}, @var{hour}, @var{day}, and @var{month} | ||
| 1159 | arguments; for example, day 0 means the day preceding the given month. | ||
| 1160 | |||
| 1161 | The operating system puts limits on the range of possible time values; | ||
| 1162 | if you try to encode a time that is out of range, an error results. | ||
| 1163 | For instance, years before 1970 do not work on some systems; | ||
| 1164 | on others, years as early as 1901 do work. | ||
| 1165 | @end defun | ||
| 1166 | |||
| 1167 | @node Time Parsing | ||
| 1168 | @section Parsing and Formatting Times | ||
| 1169 | |||
| 1170 | These functions convert time values (lists of two or three integers) | ||
| 1171 | to text in a string, and vice versa. | ||
| 1090 | 1172 | ||
| 1091 | @defun date-to-time string | 1173 | @defun date-to-time string |
| 1092 | This function parses the time-string @var{string} and returns the | 1174 | This function parses the time-string @var{string} and returns the |
| @@ -1213,81 +1295,6 @@ seconds since the epoch, to a time value and returns that. To perform | |||
| 1213 | the inverse conversion, use @code{float-time}. | 1295 | the inverse conversion, use @code{float-time}. |
| 1214 | @end defun | 1296 | @end defun |
| 1215 | 1297 | ||
| 1216 | @defun decode-time &optional time | ||
| 1217 | This function converts a time value into calendrical information. If | ||
| 1218 | you don't specify @var{time}, it decodes the current time. The return | ||
| 1219 | value is a list of nine elements, as follows: | ||
| 1220 | |||
| 1221 | @example | ||
| 1222 | (@var{seconds} @var{minutes} @var{hour} @var{day} @var{month} @var{year} @var{dow} @var{dst} @var{zone}) | ||
| 1223 | @end example | ||
| 1224 | |||
| 1225 | Here is what the elements mean: | ||
| 1226 | |||
| 1227 | @table @var | ||
| 1228 | @item seconds | ||
| 1229 | The number of seconds past the minute, as an integer between 0 and 59. | ||
| 1230 | On some operating systems, this is 60 for leap seconds. | ||
| 1231 | @item minutes | ||
| 1232 | The number of minutes past the hour, as an integer between 0 and 59. | ||
| 1233 | @item hour | ||
| 1234 | The hour of the day, as an integer between 0 and 23. | ||
| 1235 | @item day | ||
| 1236 | The day of the month, as an integer between 1 and 31. | ||
| 1237 | @item month | ||
| 1238 | The month of the year, as an integer between 1 and 12. | ||
| 1239 | @item year | ||
| 1240 | The year, an integer typically greater than 1900. | ||
| 1241 | @item dow | ||
| 1242 | The day of week, as an integer between 0 and 6, where 0 stands for | ||
| 1243 | Sunday. | ||
| 1244 | @item dst | ||
| 1245 | @code{t} if daylight savings time is effect, otherwise @code{nil}. | ||
| 1246 | @item zone | ||
| 1247 | An integer indicating the time zone, as the number of seconds east of | ||
| 1248 | Greenwich. | ||
| 1249 | @end table | ||
| 1250 | |||
| 1251 | @strong{Common Lisp Note:} Common Lisp has different meanings for | ||
| 1252 | @var{dow} and @var{zone}. | ||
| 1253 | @end defun | ||
| 1254 | |||
| 1255 | @defun encode-time seconds minutes hour day month year &optional zone | ||
| 1256 | This function is the inverse of @code{decode-time}. It converts seven | ||
| 1257 | items of calendrical data into a time value. For the meanings of the | ||
| 1258 | arguments, see the table above under @code{decode-time}. | ||
| 1259 | |||
| 1260 | Year numbers less than 100 are not treated specially. If you want them | ||
| 1261 | to stand for years above 1900, or years above 2000, you must alter them | ||
| 1262 | yourself before you call @code{encode-time}. | ||
| 1263 | |||
| 1264 | The optional argument @var{zone} defaults to the current time zone and | ||
| 1265 | its daylight savings time rules. If specified, it can be either a list | ||
| 1266 | (as you would get from @code{current-time-zone}), a string as in the | ||
| 1267 | @code{TZ} environment variable, @code{t} for Universal Time, or an | ||
| 1268 | integer (as you would get from @code{decode-time}). The specified | ||
| 1269 | zone is used without any further alteration for daylight savings time. | ||
| 1270 | |||
| 1271 | If you pass more than seven arguments to @code{encode-time}, the first | ||
| 1272 | six are used as @var{seconds} through @var{year}, the last argument is | ||
| 1273 | used as @var{zone}, and the arguments in between are ignored. This | ||
| 1274 | feature makes it possible to use the elements of a list returned by | ||
| 1275 | @code{decode-time} as the arguments to @code{encode-time}, like this: | ||
| 1276 | |||
| 1277 | @example | ||
| 1278 | (apply 'encode-time (decode-time @dots{})) | ||
| 1279 | @end example | ||
| 1280 | |||
| 1281 | You can perform simple date arithmetic by using out-of-range values for | ||
| 1282 | the @var{seconds}, @var{minutes}, @var{hour}, @var{day}, and @var{month} | ||
| 1283 | arguments; for example, day 0 means the day preceding the given month. | ||
| 1284 | |||
| 1285 | The operating system puts limits on the range of possible time values; | ||
| 1286 | if you try to encode a time that is out of range, an error results. | ||
| 1287 | For instance, years before 1970 do not work on some systems; | ||
| 1288 | on others, years as early as 1901 do work. | ||
| 1289 | @end defun | ||
| 1290 | |||
| 1291 | @node Processor Run Time | 1298 | @node Processor Run Time |
| 1292 | @section Processor Run time | 1299 | @section Processor Run time |
| 1293 | 1300 | ||