From 93241242537ad18b08486d4abd00e16c225a6a30 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Feb 2019 23:46:24 -0800 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20assume=20CURRENT=5FTIME=5FLIST?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use timestamp accessors instead of delving into a timestamp format that is planned to change in a future version. * lisp/find-lisp.el (find-lisp-format-time): * lisp/gnus/gnus-group.el (gnus-group-set-timestamp): * lisp/gnus/gnus-icalendar.el (gnus-icalendar-show-org-agenda): Use encode-time instead of delving into timestamp format. * lisp/gnus/gnus-group.el (gnus-group-timestamp-delta): Use float-time instead of delving into timestamp format. * lisp/gnus/nnmaildir.el (nnmaildir-request-accept-article): Use format-time-string instead of delving into timestamp format. * lisp/gnus/nnmaildir.el (nnmaildir-request-expire-articles): Use time-less-p instead of delving into timestamp format. * lisp/ido.el (ido-wash-history, ido-file-name-all-completions): Use time-equal-p instead of delving into timestamp format. * lisp/net/tramp-adb.el (tramp-adb-handle-set-file-times): Use format-time-string to generate POSIX ‘test -t’ format instead of timestamp-format-dependent code along with shell arithmetic that can’t possibly do the right thing on a POSIX platform. --- lisp/find-lisp.el | 11 +++-------- lisp/gnus/gnus-group.el | 11 +++++------ lisp/gnus/gnus-icalendar.el | 5 +---- lisp/gnus/nnmaildir.el | 15 ++++----------- lisp/ido.el | 31 +++++++++++++++---------------- lisp/net/tramp-adb.el | 5 ++--- lisp/woman.el | 6 ++---- 7 files changed, 32 insertions(+), 52 deletions(-) diff --git a/lisp/find-lisp.el b/lisp/find-lisp.el index c5febee6f5c..073e2bc573f 100644 --- a/lisp/find-lisp.el +++ b/lisp/find-lisp.el @@ -342,16 +342,11 @@ list of ls option letters of which c and u are recognized). Use the same method as \"ls\" to decide whether to show time-of-day or year, depending on distance between file date and NOW." (let* ((time (nth (find-lisp-time-index switches) file-attr)) - (diff16 (- (car time) (car now))) - (diff (+ (ash diff16 16) (- (car (cdr time)) (car (cdr now))))) - (past-cutoff (- (* 6 30 24 60 60))) ; 6 30-day months + (diff (encode-time (time-subtract time now) 'integer)) + (past-cutoff -15778476) ; 1/2 of a Gregorian year (future-cutoff (* 60 60))) ; 1 hour (format-time-string - (if (and - (<= past-cutoff diff) (<= diff future-cutoff) - ;; Sanity check in case `diff' computation overflowed. - (<= (1- (ash past-cutoff -16)) diff16) - (<= diff16 (1+ (ash future-cutoff -16)))) + (if (<= past-cutoff diff future-cutoff) "%b %e %H:%M" "%b %e %Y") time))) diff --git a/lisp/gnus/gnus-group.el b/lisp/gnus/gnus-group.el index 510bd7415d9..cf8423b2db1 100644 --- a/lisp/gnus/gnus-group.el +++ b/lisp/gnus/gnus-group.el @@ -4578,8 +4578,7 @@ and the second element is the address." This function can be used in hooks like `gnus-select-group-hook' or `gnus-group-catchup-group-hook'." (when gnus-newsgroup-name - (let ((time (current-time))) - (setcdr (cdr time) nil) + (let ((time (encode-time nil 'integer))) (gnus-group-set-parameter gnus-newsgroup-name 'timestamp time)))) (defsubst gnus-group-timestamp (group) @@ -4588,11 +4587,11 @@ or `gnus-group-catchup-group-hook'." (defun gnus-group-timestamp-delta (group) "Return the offset in seconds from the timestamp for GROUP to the current time, as a floating point number." - (let* ((time (or (gnus-group-timestamp group) - (list 0 0))) + ;; FIXME: This should return a Lisp integer, not a Lisp float, + ;; since it is always an integer. + (let* ((time (or (gnus-group-timestamp group) 0)) (delta (time-subtract nil time))) - (+ (* (nth 0 delta) 65536.0) - (nth 1 delta)))) + (float-time delta))) (defun gnus-group-timestamp-string (group) "Return a string of the timestamp for GROUP." diff --git a/lisp/gnus/gnus-icalendar.el b/lisp/gnus/gnus-icalendar.el index 06f09271647..a9d15f92262 100644 --- a/lisp/gnus/gnus-icalendar.el +++ b/lisp/gnus/gnus-icalendar.el @@ -655,10 +655,7 @@ is searched." (defun gnus-icalendar-show-org-agenda (event) (let* ((time-delta (time-subtract (gnus-icalendar-event:end-time event) (gnus-icalendar-event:start-time event))) - (duration-days (1+ (/ (+ (* (car time-delta) (expt 2 16)) - (cadr time-delta)) - 86400)))) - + (duration-days (1+ (floor (encode-time time-delta 'integer) 86400)))) (org-agenda-list nil (gnus-icalendar-event:start event) duration-days))) (cl-defmethod gnus-icalendar-event:sync-to-org ((event gnus-icalendar-event-request) reply-status) diff --git a/lisp/gnus/nnmaildir.el b/lisp/gnus/nnmaildir.el index afaf3dcfcff..9df2292e783 100644 --- a/lisp/gnus/nnmaildir.el +++ b/lisp/gnus/nnmaildir.el @@ -1467,7 +1467,7 @@ This variable is set by `nnmaildir-request-article'.") (unless (string-equal nnmaildir--delivery-time file) (setq nnmaildir--delivery-time file nnmaildir--delivery-count 0)) - (setq file (concat file "M" (number-to-string (caddr time)))) + (setq file (concat file (format-time-string "M%6N" time))) (setq file (concat file nnmaildir--delivery-pid) file (concat file "Q" (number-to-string nnmaildir--delivery-count)) file (concat file "." (nnmaildir--system-name)) @@ -1553,7 +1553,7 @@ This variable is set by `nnmaildir-request-article'.") (defun nnmaildir-request-expire-articles (ranges &optional gname server force) (let ((no-force (not force)) (group (nnmaildir--prepare server gname)) - pgname time boundary bound-iter high low target dir nlist + pgname time boundary high low target dir nlist didnt nnmaildir--file nnmaildir-article-file-name deactivate-mark) (catch 'return @@ -1602,15 +1602,8 @@ This variable is set by `nnmaildir-request-article'.") ((null time) (nnmaildir--expired-article group article)) ((and no-force - (progn - (setq time (file-attribute-modification-time time) - bound-iter boundary) - (while (and bound-iter time - (= (car bound-iter) (car time))) - (setq bound-iter (cdr bound-iter) - time (cdr time))) - (and bound-iter time - (car-less-than-car bound-iter time)))) + (time-less-p boundary + (file-attribute-modification-time time))) (setq didnt (cons (nnmaildir--art-num article) didnt))) (t (setq nnmaildir-article-file-name nnmaildir--file diff --git a/lisp/ido.el b/lisp/ido.el index b32cacce750..8078d184db7 100644 --- a/lisp/ido.el +++ b/lisp/ido.el @@ -1515,20 +1515,20 @@ Removes badly formatted data and ignored directories." (files (cdr (cdr (car l))))) (and (stringp dir) - (consp time) - (cond - ((integerp (car time)) - (and (not (zerop (float-time time))) - (ido-may-cache-directory dir))) - ((eq (car time) 'ftp) - (and (numberp (cdr time)) - (ido-is-ftp-directory dir) - (ido-cache-ftp-valid (cdr time)))) - ((eq (car time) 'unc) - (and (numberp (cdr time)) - (ido-is-unc-host dir) - (ido-cache-unc-valid (cdr time)))) - (t nil)) + (if (condition-case nil + (not (time-equal-p time 0)) + (error)) + (ido-may-cache-directory dir) + (and + (consp time) + (numberp (cdr time)) + (cond + ((eq (car time) 'ftp) + (and (ido-is-ftp-directory dir) + (ido-cache-ftp-valid (cdr time)))) + ((eq (car time) 'unc) + (and (ido-is-unc-host dir) + (ido-cache-unc-valid (cdr time))))))) (let ((s files) (ok t)) (while s (if (stringp (car s)) @@ -3621,8 +3621,7 @@ Uses and updates `ido-dir-file-cache'." (ido-cache-unc-valid (cdr ctime))))) (t (if attr - (setq valid (and (= (car ctime) (car mtime)) - (= (car (cdr ctime)) (car (cdr mtime)))))))) + (setq valid (time-equal-p ctime mtime))))) (unless valid (setq ido-dir-file-cache (delq cached ido-dir-file-cache) cached nil))) diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 34faf4ce280..f8b0505b41b 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -679,9 +679,8 @@ But handle the case, if the \"test\" command is not available." (current-time) time))) (tramp-adb-send-command-and-check - ;; Use shell arithmetic because of Emacs integer size limit. - v (format "touch -t $(( %d * 65536 + %d )) %s" - (car time) (cadr time) + v (format "touch -t %s %s" + (format-time-string "%Y%m%d%H%M.%S" time) (tramp-shell-quote-argument localname)))))) (defun tramp-adb-handle-copy-file diff --git a/lisp/woman.el b/lisp/woman.el index 9548fdc6b3a..110069335c8 100644 --- a/lisp/woman.el +++ b/lisp/woman.el @@ -2010,10 +2010,8 @@ Optional argument REDRAW, if non-nil, forces mode line to be updated." ;; (after Man-bgproc-sentinel-advice activate) ;; ;; Terminates man processing ;; "Report formatting time." -;; (let* ((time (current-time)) -;; (time (+ (* (- (car time) (car WoMan-Man-start-time)) 65536) -;; (- (cadr time) (cadr WoMan-Man-start-time))))) -;; (message "Man formatting done in %d seconds" time))) +;; (message "Man formatting done in %s seconds" +;; (float-time (time-subtract nil WoMan-Man-start-time)))) ;;; Buffer handling: -- 2.39.5