aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2018-10-03 09:10:01 -0700
committerPaul Eggert2018-10-06 23:31:04 -0700
commit3cc452327eff056f17637566aaf05a877e61d69a (patch)
treee702e883dab66b2a63cf1b728c3bd7ca0faabd70 /src
parent93fe420942c08111a6048af7c4d7807c61d80a09 (diff)
downloademacs-3cc452327eff056f17637566aaf05a877e61d69a.tar.gz
emacs-3cc452327eff056f17637566aaf05a877e61d69a.zip
Improvements on (TICKS . HZ)
This patch is in response to Eli's review (Bug#32902#10). * src/systime.c: Doc strings of affected functions now refer to format-time-string instead of to Lisp manual, and format-time-string's doc string covers time values. * test/src/systime-tests.el (format-time-string-with-zone): Check decode-time too. (decode-then-encode-time, time-arith-tests): New tests.
Diffstat (limited to 'src')
-rw-r--r--src/timefns.c79
1 files changed, 43 insertions, 36 deletions
diff --git a/src/timefns.c b/src/timefns.c
index 72cb54d3a0c..7bce3b1e500 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1035,8 +1035,8 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
1035} 1035}
1036 1036
1037DEFUN ("time-add", Ftime_add, Stime_add, 2, 2, 0, 1037DEFUN ("time-add", Ftime_add, Stime_add, 2, 2, 0,
1038 doc: /* Return the sum of two time values A and B, as a timestamp. 1038 doc: /* Return the sum of two time values A and B, as a time value.
1039See Info node `(elisp)Time of Day' for time value formats. 1039See `format-time-string' for the various forms of a time value.
1040For example, nil stands for the current time. */) 1040For example, nil stands for the current time. */)
1041 (Lisp_Object a, Lisp_Object b) 1041 (Lisp_Object a, Lisp_Object b)
1042{ 1042{
@@ -1044,9 +1044,9 @@ For example, nil stands for the current time. */)
1044} 1044}
1045 1045
1046DEFUN ("time-subtract", Ftime_subtract, Stime_subtract, 2, 2, 0, 1046DEFUN ("time-subtract", Ftime_subtract, Stime_subtract, 2, 2, 0,
1047 doc: /* Return the difference between two time values A and B, as a timestamp. 1047 doc: /* Return the difference between two time values A and B, as a time value.
1048You can use `float-time' to convert the difference into elapsed seconds. 1048You can use `float-time' to convert the difference into elapsed seconds.
1049See Info node `(elisp)Time of Day' for time value formats. 1049See `format-time-string' for the various forms of a time value.
1050For example, nil stands for the current time. */) 1050For example, nil stands for the current time. */)
1051 (Lisp_Object a, Lisp_Object b) 1051 (Lisp_Object a, Lisp_Object b)
1052{ 1052{
@@ -1092,7 +1092,7 @@ time_cmp (Lisp_Object a, Lisp_Object b)
1092 1092
1093DEFUN ("time-less-p", Ftime_less_p, Stime_less_p, 2, 2, 0, 1093DEFUN ("time-less-p", Ftime_less_p, Stime_less_p, 2, 2, 0,
1094 doc: /* Return non-nil if time value A is less than time value B. 1094 doc: /* Return non-nil if time value A is less than time value B.
1095See Info node `(elisp)Time of Day' for time value formats. 1095See `format-time-string' for the various forms of a time value.
1096For example, nil stands for the current time. */) 1096For example, nil stands for the current time. */)
1097 (Lisp_Object a, Lisp_Object b) 1097 (Lisp_Object a, Lisp_Object b)
1098{ 1098{
@@ -1101,7 +1101,7 @@ For example, nil stands for the current time. */)
1101 1101
1102DEFUN ("time-equal-p", Ftime_equal_p, Stime_equal_p, 2, 2, 0, 1102DEFUN ("time-equal-p", Ftime_equal_p, Stime_equal_p, 2, 2, 0,
1103 doc: /* Return non-nil if A and B are equal time values. 1103 doc: /* Return non-nil if A and B are equal time values.
1104See Info node `(elisp)Time of Day' for time value formats. */) 1104See `format-time-string' for the various forms of a time value. */)
1105 (Lisp_Object a, Lisp_Object b) 1105 (Lisp_Object a, Lisp_Object b)
1106{ 1106{
1107 return time_cmp (a, b) == 0 ? Qt : Qnil; 1107 return time_cmp (a, b) == 0 ? Qt : Qnil;
@@ -1110,12 +1110,12 @@ See Info node `(elisp)Time of Day' for time value formats. */)
1110 1110
1111DEFUN ("float-time", Ffloat_time, Sfloat_time, 0, 1, 0, 1111DEFUN ("float-time", Ffloat_time, Sfloat_time, 0, 1, 0,
1112 doc: /* Return the current time, as a float number of seconds since the epoch. 1112 doc: /* Return the current time, as a float number of seconds since the epoch.
1113If SPECIFIED-TIME is given, it is a Lisp time value to convert to 1113If SPECIFIED-TIME is given, it is a time value to convert to float
1114float instead of the current time. See Info node `(elisp)Time of Day' 1114instead of the current time. See `format-time-string' for the various
1115for time value formats. 1115forms of a time value.
1116 1116
1117WARNING: Since the result is floating point, it may not be exact. 1117WARNING: Since the result is floating point, it may not be exact.
1118If precise time stamps are required, use either `current-time', 1118If precise time stamps are required, use either `encode-time',
1119or (if you need time as a string) `format-time-string'. */) 1119or (if you need time as a string) `format-time-string'. */)
1120 (Lisp_Object specified_time) 1120 (Lisp_Object specified_time)
1121{ 1121{
@@ -1226,8 +1226,12 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1226} 1226}
1227 1227
1228DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0, 1228DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
1229 doc: /* Use FORMAT-STRING to format the time TIME, or now if omitted or nil. 1229 doc: /* Use FORMAT-STRING to format the time value TIME.
1230TIME is a Lisp time value; see Info node `(elisp)Time of Day'. 1230A time value that is omitted or nil stands for the current time,
1231a number stands for that many seconds, an integer pair (TICKS . HZ)
1232stands for TICKS/HZ seconds, and an integer list (HI LO US PS) stands
1233for HI*2**16 + LO + US/10**6 + PS/10**12 seconds. This function
1234treats seconds as time since the epoch of 1970-01-01 00:00:00 UTC.
1231 1235
1232The optional ZONE is omitted or nil for Emacs local time, t for 1236The optional ZONE is omitted or nil for Emacs local time, t for
1233Universal Time, `wall' for system wall clock time, or a string as in 1237Universal Time, `wall' for system wall clock time, or a string as in
@@ -1300,8 +1304,8 @@ usage: (format-time-string FORMAT-STRING &optional TIME ZONE) */)
1300 1304
1301DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 2, 0, 1305DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 2, 0,
1302 doc: /* Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST UTCOFF). 1306 doc: /* Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST UTCOFF).
1303The optional TIME is the Lisp time value to convert. See Info node 1307The optional TIME is the time value to convert. See
1304`(elisp)Time of Day' for time value formats. 1308`format-time-string' for the various forms of a time value.
1305 1309
1306The optional ZONE is omitted or nil for Emacs local time, t for 1310The optional ZONE is omitted or nil for Emacs local time, t for
1307Universal Time, `wall' for system wall clock time, or a string as in 1311Universal Time, `wall' for system wall clock time, or a string as in
@@ -1381,22 +1385,23 @@ check_tm_member (Lisp_Object obj, int offset)
1381} 1385}
1382 1386
1383DEFUN ("encode-time", Fencode_time, Sencode_time, 1, MANY, 0, 1387DEFUN ("encode-time", Fencode_time, Sencode_time, 1, MANY, 0,
1384 doc: /* Convert TIME to a timestamp. 1388 doc: /* Convert optional TIME to a timestamp.
1385Optional FORM specifies how the returned value should be encoded. 1389Optional FORM specifies how the returned value should be encoded.
1386This can act as the reverse operation of `decode-time', which see. 1390This can act as the reverse operation of `decode-time', which see.
1387 1391
1388If TIME is a list (SECOND MINUTE HOUR DAY MONTH YEAR IGNORED DST ZONE) 1392If TIME is a list (SECOND MINUTE HOUR DAY MONTH YEAR IGNORED DST ZONE)
1389it a decoded time in the style of `decode-time', so that (encode-time 1393it is a decoded time in the style of `decode-time', so that (encode-time
1390(decode-time ...)) works. TIME can also be a Lisp time value; see 1394(decode-time ...)) works. TIME can also be a time value.
1391Info node `(elisp)Time of Day'. 1395See `format-time-string' for the various forms of a time value.
1396For example, an omitted TIME stands for the current time.
1392 1397
1393If FORM is a positive integer, the time is returned as a pair of 1398If FORM is a positive integer, the time is returned as a pair of
1394integers (TICKS . FORM), where TICKS is the number of clock ticks and FORM 1399integers (TICKS . FORM), where TICKS is the number of clock ticks and FORM
1395is the clock frequency in ticks per second. (Currently the positive 1400is the clock frequency in ticks per second. (Currently the positive
1396integer should be at least 65536 if the returned value is expected to 1401integer should be at least 65536 if the returned value is expected to
1397be given to standard functions expecting Lisp timestamps.) If FORM is 1402be given to standard functions expecting Lisp timestamps.) If FORM is
1398t, the time is returned as (TICKS . PHZ), where PHZ is a 1403t, the time is returned as (TICKS . PHZ), where PHZ is a platform dependent
1399platform-dependent clock frequency. If FORM is `integer', the time is 1404clock frequency in ticks per second. If FORM is `integer', the time is
1400returned as an integer count of seconds. If FORM is `list', the time is 1405returned as an integer count of seconds. If FORM is `list', the time is
1401returned as an integer list (HIGH LOW USEC PSEC), where HIGH has the 1406returned as an integer list (HIGH LOW USEC PSEC), where HIGH has the
1402most significant bits of the seconds, LOW has the least significant 16 1407most significant bits of the seconds, LOW has the least significant 16
@@ -1405,11 +1410,12 @@ Returned values are rounded toward minus infinity. Although an
1405omitted or nil FORM currently acts like `list', this is planned to 1410omitted or nil FORM currently acts like `list', this is planned to
1406change, so callers requiring list timestamps should specify `list'. 1411change, so callers requiring list timestamps should specify `list'.
1407 1412
1408As an obsolescent calling convention, the first 6 arguments SECOND, 1413As an obsolescent calling convention, if this function is called with
1409MINUTE, HOUR, DAY, MONTH, and YEAR specify the components of a decoded 14146 or more arguments, the first 6 arguments are SECOND, MINUTE, HOUR,
1410time, where DST assumed to be -1 and FORM is omitted. If there are more 1415DAY, MONTH, and YEAR, and specify the components of a decoded time,
1416where DST assumed to be -1 and FORM is omitted. If there are more
1411than 6 arguments the *last* argument is used as ZONE and any other 1417than 6 arguments the *last* argument is used as ZONE and any other
1412extra arguments are ignored, so that (apply \\='encode-time 1418extra arguments are ignored, so that (apply #\\='encode-time
1413(decode-time ...)) works; otherwise ZONE is assumed to be nil. 1419(decode-time ...)) works; otherwise ZONE is assumed to be nil.
1414 1420
1415If the input is a decoded time, ZONE is nil for Emacs local time, t 1421If the input is a decoded time, ZONE is nil for Emacs local time, t
@@ -1430,7 +1436,7 @@ If you want them to stand for years in this century, you must do that yourself.
1430Years before 1970 are not guaranteed to work. On some systems, 1436Years before 1970 are not guaranteed to work. On some systems,
1431year values as low as 1901 do work. 1437year values as low as 1901 do work.
1432 1438
1433usage: (encode-time TIME &optional FORM) */) 1439usage: (encode-time &optional TIME FORM &rest OBSOLESCENT-ARGUMENTS) */)
1434 (ptrdiff_t nargs, Lisp_Object *args) 1440 (ptrdiff_t nargs, Lisp_Object *args)
1435{ 1441{
1436 time_t value; 1442 time_t value;
@@ -1490,13 +1496,13 @@ usage: (encode-time TIME &optional FORM) */)
1490} 1496}
1491 1497
1492DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0, 1498DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
1493 doc: /* Return the current time, counting the number of seconds since the epoch. 1499 doc: /* Return the current time, as the number of seconds since 1970-01-01 00:00:00.
1494 1500The time is returned as a list of integers (HIGH LOW USEC PSEC).
1495See Info node `(elisp)Time of Day' for the format of the returned 1501HIGH has the most significant bits of the seconds, while LOW has the
1496timestamp. Although this is currently list format, it may change in 1502least significant 16 bits. USEC and PSEC are the microsecond and
1497future versions of Emacs. Use `encode-time' if you need a particular 1503picosecond counts. Use `encode-time' if you need a particular
1498form; for example, (encode-time nil \\='list) returns the current time 1504timestamp form; for example, (encode-time nil \\='integer) returns the
1499in list form. */) 1505current time in seconds. */)
1500 (void) 1506 (void)
1501{ 1507{
1502 return make_lisp_time (current_timespec ()); 1508 return make_lisp_time (current_timespec ());
@@ -1512,9 +1518,9 @@ The format is `Sun Sep 16 01:03:52 1973'.
1512However, see also the functions `decode-time' and `format-time-string' 1518However, see also the functions `decode-time' and `format-time-string'
1513which provide a much more powerful and general facility. 1519which provide a much more powerful and general facility.
1514 1520
1515If SPECIFIED-TIME is given, it is the Lisp time value to format 1521If SPECIFIED-TIME is given, it is the time value to format instead of
1516instead of the current time. See Info node `(elisp)Time of Day' for 1522the current time. See `format-time-string' for the various forms of a
1517time value formats. 1523time value.
1518 1524
1519The optional ZONE is omitted or nil for Emacs local time, t for 1525The optional ZONE is omitted or nil for Emacs local time, t for
1520Universal Time, `wall' for system wall clock time, or a string as in 1526Universal Time, `wall' for system wall clock time, or a string as in
@@ -1559,7 +1565,8 @@ OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).
1559NAME is a string giving the name of the time zone. 1565NAME is a string giving the name of the time zone.
1560If SPECIFIED-TIME is given, the time zone offset is determined from it 1566If SPECIFIED-TIME is given, the time zone offset is determined from it
1561instead of using the current time. The argument should be a Lisp 1567instead of using the current time. The argument should be a Lisp
1562time value; see Info node `(elisp)Time of Day'. 1568time value; see `format-time-string' for the various forms of a time
1569value.
1563 1570
1564The optional ZONE is omitted or nil for Emacs local time, t for 1571The optional ZONE is omitted or nil for Emacs local time, t for
1565Universal Time, `wall' for system wall clock time, or a string as in 1572Universal Time, `wall' for system wall clock time, or a string as in