aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2001-11-06 01:56:02 +0000
committerPaul Eggert2001-11-06 01:56:02 +0000
commitd81a647cd1023be19d2870abbebc7b53f5a765af (patch)
tree5e289bb8e769ba9532f4110fde5f29004f2b2344
parent96238a5ae743901ccc692df055219a110b74beee (diff)
downloademacs-d81a647cd1023be19d2870abbebc7b53f5a765af.tar.gz
emacs-d81a647cd1023be19d2870abbebc7b53f5a765af.zip
(ls-lisp-time-to-seconds): New function.
(ls-lisp-format-time): Emulate GNU fileutils 4.1.1 ls, whose time stamps always line up by default. Also, it uses a slightly different window to determine whether files are "recent".
-rw-r--r--lisp/ls-lisp.el40
1 files changed, 27 insertions, 13 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index aeada6ef886..dca1ebbd89c 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -515,26 +515,40 @@ Return nil if no time switch found."
515 ((memq ?t switches) 5) ; last modtime 515 ((memq ?t switches) 5) ; last modtime
516 ((memq ?u switches) 4))) ; last access 516 ((memq ?u switches) 4))) ; last access
517 517
518(defun ls-lisp-time-to-seconds (time)
519 "Convert TIME to a floating point number."
520 (+ (* (car time) 65536.0)
521 (cadr time)
522 (/ (or (nth 2 time) 0) 1000000.0)))
523
518(defun ls-lisp-format-time (file-attr time-index now) 524(defun ls-lisp-format-time (file-attr time-index now)
519 "Format time for file with attributes FILE-ATTR according to TIME-INDEX. 525 "Format time for file with attributes FILE-ATTR according to TIME-INDEX.
520Use the same method as ls to decide whether to show time-of-day or year, 526Use the same method as ls to decide whether to show time-of-day or year,
521depending on distance between file date and NOW. 527depending on distance between file date and NOW.
522All ls time options, namely c, t and u, are handled." 528All ls time options, namely c, t and u, are handled."
523 (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime 529 (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime
524 (diff16 (- (car time) (car now))) 530 (diff (- (ls-lisp-time-to-seconds time)
525 (diff (+ (ash diff16 16) (- (car (cdr time)) (car (cdr now))))) 531 (ls-lisp-time-to-seconds now)))
526 (past-cutoff (- (* 6 30 24 60 60))) ; 6 30-day months 532 ;; Consider a time to be recent if it is within the past six
527 (future-cutoff (* 60 60))) ; 1 hour 533 ;; months. A Gregorian year has 365.2425 * 24 * 60 * 60 ==
534 ;; 31556952 seconds on the average, and half of that is 15778476.
535 ;; Write the constant explicitly to avoid roundoff error.
536 (past-cutoff -15778476)) ; half a Gregorian year
528 (condition-case nil 537 (condition-case nil
529 (format-time-string 538 ;; Use traditional time format in the C or POSIX locale,
530 (if (and 539 ;; ISO-style time format otherwise, so columns line up.
531 (<= past-cutoff diff) (<= diff future-cutoff) 540 (let ((locale system-time-locale))
532 ;; Sanity check in case `diff' computation overflowed. 541 (if (not locale)
533 (<= (1- (ash past-cutoff -16)) diff16) 542 (let ((vars '("LC_ALL" "LC_TIME" "LANG")))
534 (<= diff16 (1+ (ash future-cutoff -16)))) 543 (while (and vars (not (setq locale (getenv (car vars)))))
535 "%b %e %H:%M" 544 (setq vars (cdr vars)))))
536 "%b %e %Y") 545 (if (member locale '("C" "POSIX"))
537 time) 546 (setq locale nil))
547 (format-time-string
548 (if (and (<= past-cutoff diff) (<= diff 0))
549 (if locale "%m-%d %H:%M" "%b %e %H:%M")
550 (if locale "%Y-%m-%d " "%b %e %Y"))
551 time))
538 (error "Unk 0 0000")))) 552 (error "Unk 0 0000"))))
539 553
540(provide 'ls-lisp) 554(provide 'ls-lisp)