/[emacs]/emacs/lisp/ls-lisp.el
ViewVC logotype

Diff of /emacs/lisp/ls-lisp.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38 by pj, Sun Jul 15 16:15:34 2001 UTC revision 1.39 by eggert, Tue Nov 6 01:56:02 2001 UTC
# Line 515  Return nil if no time switch found." Line 515  Return nil if no time switch found."
515          ((memq ?t switches) 5)          ; last modtime          ((memq ?t switches) 5)          ; last modtime
516          ((memq ?u switches) 4)))        ; last access          ((memq ?u switches) 4)))        ; last access
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    
524  (defun ls-lisp-format-time (file-attr time-index now)  (defun ls-lisp-format-time (file-attr time-index now)
525    "Format time for file with attributes FILE-ATTR according to TIME-INDEX.    "Format time for file with attributes FILE-ATTR according to TIME-INDEX.
526  Use the same method as ls to decide whether to show time-of-day or year,  Use the same method as ls to decide whether to show time-of-day or year,
527  depending on distance between file date and NOW.  depending on distance between file date and NOW.
528  All ls time options, namely c, t and u, are handled."  All ls time options, namely c, t and u, are handled."
529    (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime    (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime
530           (diff16 (- (car time) (car now)))           (diff (- (ls-lisp-time-to-seconds time)
531           (diff (+ (ash diff16 16) (- (car (cdr time)) (car (cdr now)))))                    (ls-lisp-time-to-seconds now)))
532           (past-cutoff (- (* 6 30 24 60 60)))    ; 6 30-day months           ;; Consider a time to be recent if it is within the past six
533           (future-cutoff (* 60 60)))             ; 1 hour           ;; 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
537      (condition-case nil      (condition-case nil
538          (format-time-string          ;; Use traditional time format in the C or POSIX locale,
539           (if (and          ;; ISO-style time format otherwise, so columns line up.
540                (<= past-cutoff diff) (<= diff future-cutoff)          (let ((locale system-time-locale))
541                ;; Sanity check in case `diff' computation overflowed.            (if (not locale)
542                (<= (1- (ash past-cutoff -16)) diff16)                (let ((vars '("LC_ALL" "LC_TIME" "LANG")))
543                (<= diff16 (1+ (ash future-cutoff -16))))                  (while (and vars (not (setq locale (getenv (car vars)))))
544               "%b %e %H:%M"                    (setq vars (cdr vars)))))
545             "%b %e  %Y")            (if (member locale '("C" "POSIX"))
546           time)                (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))
552        (error "Unk  0  0000"))))        (error "Unk  0  0000"))))
553    
554  (provide 'ls-lisp)  (provide 'ls-lisp)

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26