emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/calendar/timeclock.el, v [EMACS_22_B


From: Chong Yidong
Subject: [Emacs-diffs] Changes to emacs/lisp/calendar/timeclock.el, v [EMACS_22_BASE]
Date: Mon, 04 Jun 2007 23:49:26 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Branch:         EMACS_22_BASE
Changes by:     Chong Yidong <cyd>      07/06/04 23:49:26

Index: timeclock.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/calendar/timeclock.el,v
retrieving revision 1.38.2.1
retrieving revision 1.38.2.2
diff -u -b -r1.38.2.1 -r1.38.2.2
--- timeclock.el        10 May 2007 16:32:30 -0000      1.38.2.1
+++ timeclock.el        4 Jun 2007 23:49:26 -0000       1.38.2.2
@@ -5,7 +5,7 @@
 
 ;; Author: John Wiegley <address@hidden>
 ;; Created: 25 Mar 1999
-;; Version: 2.6
+;; Version: 2.6.1
 ;; Keywords: calendar data
 
 ;; This file is part of GNU Emacs.
@@ -304,8 +304,8 @@
                 ;; Update immediately so there is a visible change
                 ;; on calling this function.
                 (if display-time-mode (timeclock-update-modeline)
-                  (message "Activate `display-time-mode' to see \
-timeclock information"))
+                  (message "Activate `display-time-mode' or turn off \
+`timeclock-use-display-time' to see timeclock information"))
                 (add-hook 'display-time-hook 'timeclock-update-modeline))
            (setq timeclock-update-timer
                  (run-at-time nil 60 'timeclock-update-modeline))))
@@ -589,6 +589,38 @@
        (message "%s" string)
       string)))
 
+(defun timeclock-make-hours-explicit (old-default)
+  "Specify all workday lengths in `timeclock-file'.
+OLD-DEFAULT hours are set for every day that has no number indicated."
+  (interactive "P")
+  (if old-default (setq old-default (prefix-numeric-value old-default))
+    (error "timelog-make-hours-explicit requires an explicit argument"))
+  (let ((extant-timelog (find-buffer-visiting timeclock-file))
+       current-date)
+    (with-current-buffer (find-file-noselect timeclock-file t)
+      (unwind-protect
+         (save-excursion
+           (save-restriction
+             (widen)
+             (goto-char (point-min))
+             (while (progn (skip-chars-forward "\n") (not (eobp)))
+               ;; This is just a variant of `timeclock-moment-regexp'.
+               (unless (looking-at
+                        (concat "^\\([bhioO]\\) \\([0-9]+/[0-9]+/[0-9]+\\) "
+                                "\\([0-9]+:[0-9]+:[0-9]+\\)"))
+                 (error "Can't parse `%s'" timeclock-file))
+               (let ((this-date (match-string 2)))
+                 (unless (or (and current-date
+                                  (string= this-date current-date))
+                             (string= (match-string 1) "h"))
+                   (insert (format "h %s %s %s\n" (match-string 2)
+                                   (match-string 3) old-default)))
+                 (if (string-match "^[ih]" (match-string 1)) ; ignore logouts
+                     (setq current-date this-date)))
+               (forward-line))
+             (save-buffer)))
+       (unless extant-timelog (kill-buffer (current-buffer)))))))
+
 ;;; Internal Functions:
 
 (defvar timeclock-project-list nil)
@@ -653,7 +685,7 @@
 If PROJECT is a string, it represents the project which the event is
 being logged for.  Normally only \"in\" events specify a project."
   (let ((extant-timelog (find-buffer-visiting timeclock-file)))
-    (with-current-buffer (find-file-noselect timeclock-file)
+    (with-current-buffer (find-file-noselect timeclock-file t)
       (save-excursion
        (save-restriction
          (widen)
@@ -663,8 +695,7 @@
          (let ((now (current-time)))
            (insert code " "
                    (format-time-string "%Y/%m/%d %H:%M:%S" now)
-                   (or (and project
-                            (stringp project)
+                   (or (and (stringp project)
                             (> (length project) 0)
                             (concat " " project))
                        "")
@@ -679,8 +710,8 @@
                         timeclock-last-period)))
            (setq timeclock-last-event (list code now project)))))
       (save-buffer)
-      (run-hooks 'timeclock-event-hook)
-      (unless extant-timelog (kill-buffer (current-buffer))))))
+      (unless extant-timelog (kill-buffer (current-buffer)))))
+  (run-hooks 'timeclock-event-hook))
 
 (defvar timeclock-moment-regexp
   (concat "\\([bhioO]\\)\\s-+"
@@ -1152,8 +1183,8 @@
     (setcar (nthcdr 2 decoded) 0)
     (apply 'encode-time decoded)))
 
-(defun timeclock-geometric-mean (l)
-  "Compute the geometric mean of the values in the list L."
+(defun timeclock-mean (l)
+  "Compute the arithmetic mean of the values in the list L."
   (let ((total 0)
        (count 0))
     (while l
@@ -1168,7 +1199,7 @@
   "Generate a summary report based on the current timelog file.
 By default, the report is in plain text, but if the optional argument
 HTML-P is non-nil, HTML markup is added."
-  (interactive)
+  (interactive "P")
   (let ((log (timeclock-log-data))
        (today (timeclock-day-base)))
     (if html-p (insert "<p>"))
@@ -1300,14 +1331,10 @@
          ;; average statistics
          (let ((i 0) (l 5))
            (while (< i l)
-             (aset time-in i (timeclock-geometric-mean
-                              (cdr (aref time-in i))))
-             (aset time-out i (timeclock-geometric-mean
-                               (cdr (aref time-out i))))
-             (aset breaks i (timeclock-geometric-mean
-                             (cdr (aref breaks i))))
-             (aset workday i (timeclock-geometric-mean
-                              (cdr (aref workday i))))
+             (aset time-in i (timeclock-mean (cdr (aref time-in i))))
+             (aset time-out i (timeclock-mean (cdr (aref time-out i))))
+             (aset breaks i (timeclock-mean (cdr (aref breaks i))))
+             (aset workday i (timeclock-mean (cdr (aref workday i))))
              (setq i (1+ i))))
          ;; Output the HTML table
          (insert "<tr>\n")




reply via email to

[Prev in Thread] Current Thread [Next in Thread]