aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2018-12-19 12:57:25 -0800
committerPaul Eggert2018-12-19 13:01:42 -0800
commit5bd6074415e8d572931ee51112d9b70b70e2ba55 (patch)
tree197616a9cf72bd188a9201274f0840afac93fac2
parent3fa8bdca88153ff442ca22d8c298525c1b716e7e (diff)
downloademacs-5bd6074415e8d572931ee51112d9b70b70e2ba55.tar.gz
emacs-5bd6074415e8d572931ee51112d9b70b70e2ba55.zip
Minor fixes/simplifications to time functions
* doc/lispintro/emacs-lisp-intro.texi (Files List): Simplify. * doc/lispref/os.texi (Time of Day): Mention format-time-string as an alternative to current-time-string. * lisp/arc-mode.el (archive-unixdate, archive-unixtime): Port better to future versions of Emacs where (COUNT . HZ) will take precedence to (HI . LO). * lisp/arc-mode.el (archive-unixtime): * lisp/calendar/todo-mode.el (todo-insert-item--basic) (todo-item-done, todo-read-time): Prefer format-time-string to substringing current-time-string. * lisp/calc/calc-forms.el (calc-time, calcFunc-now): Prefer decode-time to parsing the output of current-time-string. * lisp/emacs-lisp/cl-extra.el (cl--random-time): Prefer encode-time to hashing the output of current-time-string. * lisp/gnus/gnus-score.el (gnus-score-headers) (gnus-score-adaptive): Avoid stringifying and then reparsing timestamp. * src/timefns.c (Fencode_time): Omit redundant assignment.
-rw-r--r--doc/lispintro/emacs-lisp-intro.texi2
-rw-r--r--doc/lispref/os.texi7
-rw-r--r--lisp/arc-mode.el5
-rw-r--r--lisp/calc/calc-forms.el25
-rw-r--r--lisp/calendar/todo-mode.el7
-rw-r--r--lisp/emacs-lisp/cl-extra.el4
-rw-r--r--lisp/gnus/gnus-score.el4
-rw-r--r--src/timefns.c1
8 files changed, 24 insertions, 31 deletions
diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi
index 0b0c0a167d9..1a1518b2c51 100644
--- a/doc/lispintro/emacs-lisp-intro.texi
+++ b/doc/lispintro/emacs-lisp-intro.texi
@@ -15599,7 +15599,7 @@ like this:
15599 (recursive-lengths-list-many-files 15599 (recursive-lengths-list-many-files
15600 (files-in-below-directory "/usr/local/src/emacs/lisp/")) 15600 (files-in-below-directory "/usr/local/src/emacs/lisp/"))
15601 '<) 15601 '<)
15602 (insert (format "%s" (current-time-string)))) 15602 (insert (current-time-string)))
15603@end ignore 15603@end ignore
15604 15604
15605@node Counting function definitions 15605@node Counting function definitions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 41753859e50..60697f2e29f 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1313,9 +1313,10 @@ This function returns the current time and date as a human-readable
1313string. The format does not vary for the initial part of the string, 1313string. The format does not vary for the initial part of the string,
1314which contains the day of week, month, day of month, and time of day 1314which contains the day of week, month, day of month, and time of day
1315in that order: the number of characters used for these fields is 1315in that order: the number of characters used for these fields is
1316always the same, so you can reliably 1316always the same, although (unless you require English weekday or
1317use @code{substring} to extract them. You should count 1317month abbreviations regardless of locale) it is typically more
1318characters from the beginning of the string rather than from the end, 1318convenient to use @code{format-time-string} than to extract
1319fields from the output of @code{current-time-string},
1319as the year might not have exactly four digits, and additional 1320as the year might not have exactly four digits, and additional
1320information may some day be added at the end. 1321information may some day be added at the end.
1321 1322
diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index 068702bc71b..9d63a2a579a 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -637,7 +637,7 @@ the mode is invalid. If ERROR is nil then nil will be returned."
637 637
638(defun archive-unixdate (low high) 638(defun archive-unixdate (low high)
639 "Stringify Unix (LOW HIGH) date." 639 "Stringify Unix (LOW HIGH) date."
640 (let* ((time (cons high low)) 640 (let* ((time (list high low))
641 (str (current-time-string time))) 641 (str (current-time-string time)))
642 (format "%s-%s-%s" 642 (format "%s-%s-%s"
643 (substring str 8 10) 643 (substring str 8 10)
@@ -646,8 +646,7 @@ the mode is invalid. If ERROR is nil then nil will be returned."
646 646
647(defun archive-unixtime (low high) 647(defun archive-unixtime (low high)
648 "Stringify Unix (LOW HIGH) time." 648 "Stringify Unix (LOW HIGH) time."
649 (let ((str (current-time-string (cons high low)))) 649 (format-time-string "%H:%M:%S" (list high low)))
650 (substring str 11 19)))
651 650
652(defun archive-get-lineno () 651(defun archive-get-lineno ()
653 (if (>= (point) archive-file-list-start) 652 (if (>= (point) archive-file-list-start)
diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el
index f7586288ca2..ccd52d370d1 100644
--- a/lisp/calc/calc-forms.el
+++ b/lisp/calc/calc-forms.el
@@ -37,13 +37,11 @@
37(defun calc-time () 37(defun calc-time ()
38 (interactive) 38 (interactive)
39 (calc-wrapper 39 (calc-wrapper
40 (let ((time (current-time-string))) 40 (let ((time (decode-time)))
41 (calc-enter-result 0 "time" 41 (calc-enter-result 0 "time"
42 (list 'mod 42 (list 'mod
43 (list 'hms 43 (list 'hms
44 (string-to-number (substring time 11 13)) 44 (nth 2 time) (nth 1 time) (nth 0 time))
45 (string-to-number (substring time 14 16))
46 (string-to-number (substring time 17 19)))
47 (list 'hms 24 0 0)))))) 45 (list 'hms 24 0 0))))))
48 46
49(defun calc-to-hms (arg) 47(defun calc-to-hms (arg)
@@ -1341,16 +1339,15 @@ as measured in the integer number of days before December 31, 1 BC (Gregorian)."
1341 (math-parse-iso-date-validate isoyear isoweek isoweekday hour minute second))))) 1339 (math-parse-iso-date-validate isoyear isoweek isoweekday hour minute second)))))
1342 1340
1343(defun calcFunc-now (&optional zone) 1341(defun calcFunc-now (&optional zone)
1344 (let ((date (let ((calc-date-format nil)) 1342 (let ((date (let ((now (decode-time)))
1345 (math-parse-date (current-time-string))))) 1343 (list 'date (math-dt-to-date
1346 (if (consp date) 1344 (list (nth 5 now) (nth 4 now) (nth 3 now)
1347 (if zone 1345 (nth 2 now) (nth 1 now) (nth 0 now)))))))
1348 (math-add date (math-div (math-sub (calcFunc-tzone nil date) 1346 (if zone
1349 (calcFunc-tzone zone date)) 1347 (math-add date (math-div (math-sub (calcFunc-tzone nil date)
1350 '(float 864 2))) 1348 (calcFunc-tzone zone date))
1351 date) 1349 '(float 864 2)))
1352 (calc-record-why "*Unable to interpret current date from system") 1350 date)))
1353 (append (list 'calcFunc-now) (and zone (list zone))))))
1354 1351
1355(defun calcFunc-year (date) 1352(defun calcFunc-year (date)
1356 (car (math-date-to-dt date))) 1353 (car (math-date-to-dt date)))
diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el
index 41fe57e60ce..145cf78e6de 100644
--- a/lisp/calendar/todo-mode.el
+++ b/lisp/calendar/todo-mode.el
@@ -1931,7 +1931,7 @@ their associated keys and their effects."
1931 (calendar-current-date) t t)))) 1931 (calendar-current-date) t t))))
1932 (time-string (or (and time (todo-read-time)) 1932 (time-string (or (and time (todo-read-time))
1933 (and todo-always-add-time-string 1933 (and todo-always-add-time-string
1934 (substring (current-time-string) 11 16))))) 1934 (format-time-string "%H:%M")))))
1935 (setq todo-date-from-calendar nil) 1935 (setq todo-date-from-calendar nil)
1936 (find-file-noselect file 'nowarn) 1936 (find-file-noselect file 'nowarn)
1937 (set-window-buffer (selected-window) 1937 (set-window-buffer (selected-window)
@@ -2881,8 +2881,7 @@ visible."
2881 (not marked)) 2881 (not marked))
2882 (let* ((date-string (calendar-date-string (calendar-current-date) t t)) 2882 (let* ((date-string (calendar-date-string (calendar-current-date) t t))
2883 (time-string (if todo-always-add-time-string 2883 (time-string (if todo-always-add-time-string
2884 (concat " " (substring (current-time-string) 2884 (format-time-string " %H:%M")
2885 11 16))
2886 "")) 2885 ""))
2887 (done-prefix (concat "[" todo-done-string date-string time-string 2886 (done-prefix (concat "[" todo-done-string date-string time-string
2888 "] ")) 2887 "] "))
@@ -6091,7 +6090,7 @@ the empty string (i.e., no time string)."
6091 (while (not valid) 6090 (while (not valid)
6092 (setq answer (read-string "Enter a clock time: " nil nil 6091 (setq answer (read-string "Enter a clock time: " nil nil
6093 (when todo-always-add-time-string 6092 (when todo-always-add-time-string
6094 (substring (current-time-string) 11 16)))) 6093 (format-time-string "%H:%M"))))
6095 (when (or (string= "" answer) 6094 (when (or (string= "" answer)
6096 (string-match diary-time-regexp answer)) 6095 (string-match diary-time-regexp answer))
6097 (setq valid t))) 6096 (setq valid t)))
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index 13988db9a86..78484fcfa3f 100644
--- a/lisp/emacs-lisp/cl-extra.el
+++ b/lisp/emacs-lisp/cl-extra.el
@@ -438,9 +438,7 @@ as an integer unless JUNK-ALLOWED is non-nil."
438;; Random numbers. 438;; Random numbers.
439 439
440(defun cl--random-time () 440(defun cl--random-time ()
441 (let* ((time (copy-sequence (current-time-string))) (i (length time)) (v 0)) 441 (car (encode-time nil t)))
442 (while (>= (cl-decf i) 0) (setq v (+ (* v 3) (aref time i))))
443 v))
444 442
445;;;###autoload (autoload 'cl-random-state-p "cl-extra") 443;;;###autoload (autoload 'cl-random-state-p "cl-extra")
446(cl-defstruct (cl--random-state 444(cl-defstruct (cl--random-state
diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el
index 327cc69392d..f777163cc31 100644
--- a/lisp/gnus/gnus-score.el
+++ b/lisp/gnus/gnus-score.el
@@ -1501,7 +1501,7 @@ If FORMAT, also format the current score file."
1501 (when (and gnus-summary-default-score 1501 (when (and gnus-summary-default-score
1502 scores) 1502 scores)
1503 (let* ((entries gnus-header-index) 1503 (let* ((entries gnus-header-index)
1504 (now (date-to-day (current-time-string))) 1504 (now (time-to-days (current-time)))
1505 (expire (and gnus-score-expiry-days 1505 (expire (and gnus-score-expiry-days
1506 (- now gnus-score-expiry-days))) 1506 (- now gnus-score-expiry-days)))
1507 (headers gnus-newsgroup-headers) 1507 (headers gnus-newsgroup-headers)
@@ -2380,7 +2380,7 @@ score in `gnus-newsgroup-scored' by SCORE."
2380 (memq 'word gnus-newsgroup-adaptive)) 2380 (memq 'word gnus-newsgroup-adaptive))
2381 (with-temp-buffer 2381 (with-temp-buffer
2382 (let* ((hashtb (gnus-make-hashtable 1000)) 2382 (let* ((hashtb (gnus-make-hashtable 1000))
2383 (date (date-to-day (current-time-string))) 2383 (date (time-to-days (current-time)))
2384 (data gnus-newsgroup-data) 2384 (data gnus-newsgroup-data)
2385 word d score val) 2385 word d score val)
2386 (with-syntax-table gnus-adaptive-word-syntax-table 2386 (with-syntax-table gnus-adaptive-word-syntax-table
diff --git a/src/timefns.c b/src/timefns.c
index f527d5ed7fd..58dda1c7061 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1475,7 +1475,6 @@ usage: (encode-time &optional TIME FORM &rest OBSOLESCENT-ARGUMENTS) */)
1475 { 1475 {
1476 if (6 < nargs) 1476 if (6 < nargs)
1477 zone = args[nargs - 1]; 1477 zone = args[nargs - 1];
1478 form = Qnil;
1479 tm.tm_sec = check_tm_member (a, 0); 1478 tm.tm_sec = check_tm_member (a, 0);
1480 tm.tm_min = check_tm_member (args[1], 0); 1479 tm.tm_min = check_tm_member (args[1], 0);
1481 tm.tm_hour = check_tm_member (args[2], 0); 1480 tm.tm_hour = check_tm_member (args[2], 0);