Function: timeclock-find-discrep
timeclock-find-discrep is a byte-compiled function defined in
timeclock.el.gz.
Signature
(timeclock-find-discrep)
Documentation
Calculate time discrepancies, in seconds.
The result is a three element list, containing the total time discrepancy, today's discrepancy, and the time worked today.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/timeclock.el.gz
(defun timeclock-find-discrep ()
"Calculate time discrepancies, in seconds.
The result is a three element list, containing the total time
discrepancy, today's discrepancy, and the time worked today."
;; This is not implemented in terms of the functions above, because
;; it's a bit wasteful to read all of that data in, just to throw
;; away more than 90% of the information afterwards.
;;
;; If it were implemented using those functions, it would look
;; something like this:
;; (let ((days (timeclock-day-alist (timeclock-log-data)))
;; (total 0.0))
;; (while days
;; (setq total (+ total (- (timeclock-day-length (cdar days))
;; (timeclock-day-required (cdar days))))
;; days (cdr days)))
;; total)
(let* ((now (current-time))
(todays-date (timeclock-time-to-date now))
(first t) (accum 0) (elapsed 0)
event beg last-date
last-date-limited last-date-seconds)
(when (or (not timeclock-discrepancy)
;; The length of the workday has changed, so recompute.
(not (equal timeclock-workday timeclock--previous-workday)))
(when (file-readable-p timeclock-file)
(setq timeclock-project-list nil
timeclock-last-project nil
timeclock-reason-list nil
timeclock-elapsed 0)
(with-temp-buffer
(insert-file-contents timeclock-file)
(goto-char (point-max))
(unless (re-search-backward "^b\\s-+" nil t)
(goto-char (point-min)))
(while (setq event (timeclock-read-moment))
(cond ((equal (car event) "b")
(setq accum (string-to-number (nth 2 event))))
((equal (car event) "h")
(setq last-date-limited
(timeclock-time-to-date (cadr event))
last-date-seconds
(* (string-to-number (nth 2 event)) 3600.0)))
((equal (car event) "i")
(when (and (nth 2 event)
(> (length (nth 2 event)) 0))
(add-to-list 'timeclock-project-list (nth 2 event))
(setq timeclock-last-project (nth 2 event)))
(let ((date (timeclock-time-to-date (cadr event))))
(if (if last-date
(not (equal date last-date))
first)
(setq first nil
accum (- accum (if last-date-limited
last-date-seconds
timeclock-workday))))
(setq last-date date
last-date-limited nil)
(if beg
(error "Error in format of timelog file!")
(setq beg (cadr event)))))
((equal (downcase (car event)) "o")
(if (and (nth 2 event)
(> (length (nth 2 event)) 0))
(add-to-list 'timeclock-reason-list (nth 2 event)))
(if (not beg)
(error "Error in format of timelog file!")
(setq timeclock-last-period
(float-time (time-subtract (cadr event) beg))
accum (+ timeclock-last-period accum)
beg nil))
(if (equal last-date todays-date)
(setq timeclock-elapsed
(+ timeclock-last-period timeclock-elapsed)))))
(setq timeclock-last-event event
timeclock-last-event-workday
(if (equal todays-date last-date-limited)
last-date-seconds
timeclock-workday))
(forward-line))
(setq timeclock-discrepancy accum
timeclock--previous-workday timeclock-workday))))
(unless timeclock-last-event-workday
(setq timeclock-last-event-workday timeclock-workday))
(setq accum (or timeclock-discrepancy 0)
elapsed (or timeclock-elapsed elapsed))
(if timeclock-last-event
(if (equal (car timeclock-last-event) "i")
(let ((last-period (timeclock-last-period now)))
(setq accum (+ accum last-period)
elapsed (+ elapsed last-period)))
(if (not (equal (timeclock-time-to-date
(cadr timeclock-last-event))
(timeclock-time-to-date now)))
(setq accum (- accum timeclock-last-event-workday)))))
(list accum (- elapsed timeclock-last-event-workday)
elapsed)))