comparison lisp/calendar/timeclock.el @ 77671:693e049fff70

(timeclock-in): Fix non-interactive workday specifications. (timeclock-log): Don't kill the log buffer if it already existed.
author Richard M. Stallman <rms@gnu.org>
date Thu, 10 May 2007 16:32:30 +0000
parents 7a3f13e2dd57
children 2e526dc9c6b6
comparison
equal deleted inserted replaced
77670:a7056aafb66a 77671:693e049fff70
373 (run-hooks 'timeclock-first-in-hook) 373 (run-hooks 'timeclock-first-in-hook)
374 ;; settle the discrepancy for the new day 374 ;; settle the discrepancy for the new day
375 (setq timeclock-discrepancy 375 (setq timeclock-discrepancy
376 (- (or timeclock-discrepancy 0) workday)) 376 (- (or timeclock-discrepancy 0) workday))
377 (if (not (= workday timeclock-workday)) 377 (if (not (= workday timeclock-workday))
378 (timeclock-log "h" (and (numberp arg) 378 (timeclock-log "h" (number-to-string
379 (number-to-string arg)))))) 379 (/ workday (if (zerop (% workday (* 60 60)))
380 60 60.0) 60))))))
380 (timeclock-log "i" (or project 381 (timeclock-log "i" (or project
381 (and timeclock-get-project-function 382 (and timeclock-get-project-function
382 (or find-project (interactive-p)) 383 (or find-project (interactive-p))
383 (funcall timeclock-get-project-function)))) 384 (funcall timeclock-get-project-function))))
384 (run-hooks 'timeclock-in-hook))) 385 (run-hooks 'timeclock-in-hook)))
649 650
650 (defun timeclock-log (code &optional project) 651 (defun timeclock-log (code &optional project)
651 "Log the event CODE to the timeclock log, at the time of call. 652 "Log the event CODE to the timeclock log, at the time of call.
652 If PROJECT is a string, it represents the project which the event is 653 If PROJECT is a string, it represents the project which the event is
653 being logged for. Normally only \"in\" events specify a project." 654 being logged for. Normally only \"in\" events specify a project."
654 (with-current-buffer (find-file-noselect timeclock-file) 655 (let ((extant-timelog (find-buffer-visiting timeclock-file)))
655 (goto-char (point-max)) 656 (with-current-buffer (find-file-noselect timeclock-file)
656 (if (not (bolp)) 657 (save-excursion
657 (insert "\n")) 658 (save-restriction
658 (let ((now (current-time))) 659 (widen)
659 (insert code " " 660 (goto-char (point-max))
660 (format-time-string "%Y/%m/%d %H:%M:%S" now) 661 (if (not (bolp))
661 (or (and project 662 (insert "\n"))
662 (stringp project) 663 (let ((now (current-time)))
663 (> (length project) 0) 664 (insert code " "
664 (concat " " project)) 665 (format-time-string "%Y/%m/%d %H:%M:%S" now)
665 "") 666 (or (and project
666 "\n") 667 (stringp project)
667 (if (equal (downcase code) "o") 668 (> (length project) 0)
668 (setq timeclock-last-period 669 (concat " " project))
669 (- (timeclock-time-to-seconds now) 670 "")
670 (timeclock-time-to-seconds 671 "\n")
671 (cadr timeclock-last-event))) 672 (if (equal (downcase code) "o")
672 timeclock-discrepancy 673 (setq timeclock-last-period
673 (+ timeclock-discrepancy 674 (- (timeclock-time-to-seconds now)
674 timeclock-last-period))) 675 (timeclock-time-to-seconds
675 (setq timeclock-last-event (list code now project))) 676 (cadr timeclock-last-event)))
676 (save-buffer) 677 timeclock-discrepancy
677 (run-hooks 'timeclock-event-hook) 678 (+ timeclock-discrepancy
678 (kill-buffer (current-buffer)))) 679 timeclock-last-period)))
680 (setq timeclock-last-event (list code now project)))))
681 (save-buffer)
682 (run-hooks 'timeclock-event-hook)
683 (unless extant-timelog (kill-buffer (current-buffer))))))
679 684
680 (defvar timeclock-moment-regexp 685 (defvar timeclock-moment-regexp
681 (concat "\\([bhioO]\\)\\s-+" 686 (concat "\\([bhioO]\\)\\s-+"
682 "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)\\s-+" 687 "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)\\s-+"
683 "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)[ \t]*" "\\([^\n]*\\)")) 688 "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)[ \t]*" "\\([^\n]*\\)"))