Function: f--date-compare

f--date-compare is a byte-compiled function defined in f.el.

Signature

(f--date-compare FILE OTHER METHOD)

Documentation

Three-way comparison of the date of FILE and OTHER.

This function can return three values:
* 1 means FILE is newer than OTHER
* 0 means FILE and NEWER share the same date
* -1 means FILE is older than OTHER

The statistics used for the date comparison depends on METHOD. When METHOD is null, compare their modification time. Otherwise, compare their change time when METHOD is 'change, or compare their last access time when METHOD is 'access.

Source Code

;; Defined in ~/.emacs.d/elpa/f-20241003.1131/f.el
;; TODO: How to properly test this function?
(defun f--date-compare (file other method)
  "Three-way comparison of the date of FILE and OTHER.

This function can return three values:
* 1 means FILE is newer than OTHER
* 0 means FILE and NEWER share the same date
* -1 means FILE is older than OTHER

The statistics used for the date comparison depends on METHOD.
When METHOD is null, compare their modification time.  Otherwise,
compare their change time when METHOD is \\='change, or compare
their last access time when METHOD is \\='access."
  (let* ((fn-method (cond
                     ((eq 'change method) #'f-change-time)
                     ((eq 'access method) #'f-access-time)
                     ((null method)       #'f-modification-time)
                     (t (error "Unknown method %S" method))))
         (date-file (apply fn-method (list file)))
         (date-other (apply fn-method (list other)))
         (dates      (-zip-pair date-file date-other)))
    (-reduce-from (lambda (acc elt)
                    (if (= acc 0)
                        (f--three-way-compare (car elt) (cdr elt))
                      acc))
                  0
                  dates)))