emacs-wiki-discuss
[Top][All Lists]
Advanced

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

[emacs-wiki-discuss] Patch to planner-timeclock-summary.el: Allow date r


From: Chris Parsons
Subject: [emacs-wiki-discuss] Patch to planner-timeclock-summary.el: Allow date ranges
Date: Wed, 15 Dec 2004 10:24:39 +0000
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (windows-nt)

Hi Planner types

I've make a fairly large change to planner-timeclock-summary.el to allow
date ranges when summarising data.

To use, call planner-timeclock-summary-show-range and supply a start and
end date.

All the existing functions signatures are still intact, but some of the
internals have changed in order to generalise the code for ranges.

This is the first part of my work on getting planner-timeclock-summary
to output timesheets for my clients. Next step is to filter the data by
plan-page prefix, and then to allow grouping of time by matching
plan-page prefixes of a minimum number of characters (customizable).

(Sacha: I've cleaned this up as you suggested since the first submission
to you - figured you were busy with your MIT application :)

Any thoughts and suggestions would be most welcome - I'm a lisp newbie
so bear with me.

Chris

diff -u "c:/Program 
Files/emacs-21.3/site-lisp/planner/planner-timeclock-summary.el.orig" 
"c:/Program Files/emacs-21.3/site-lisp/planner/planner-timeclock-summary.el"
--- c:/Program 
Files/emacs-21.3/site-lisp/planner/planner-timeclock-summary.el.orig     
2004-12-13 10:31:20.328180800 +0000
+++ c:/Program Files/emacs-21.3/site-lisp/planner/planner-timeclock-summary.el  
2004-12-15 10:20:01.204580800 +0000
@@ -151,13 +151,22 @@
   "Display a buffer with the timeclock summary for DATE.
 
 Date is a string in the form YYYY.MM.DD."
-  (interactive (list (planner-read-date)))
+
+       (interactive (list (planner-read-date)))
+       (planner-timeclock-summary-show-range date date))
+
+(defun planner-timeclock-summary-show-range (start-date end-date)
+  "Display a buffer with the timeclock summary for the DATE range START-DATE 
to END-DATE.
+
+Dates are strings in the form YYYY.MM.DD."
+  (interactive (list (planner-read-date "Start") (planner-read-date "End")))
   (switch-to-buffer (get-buffer-create planner-timeclock-summary-buffer))
   (erase-buffer)
   (let ((emacs-wiki-project planner-project))
-    (insert "Timeclock summary report for " date "\n\n"
+    (insert "Timeclock summary report for " (if (string-equal start-date 
end-date) start-date (concat start-date " - " end-date)) "\n\n"
            (planner-timeclock-summary-make-text-table-day
-            (replace-in-string date "\\." "/" t)))
+            (replace-in-string start-date "\\." "/" t)
+                        (replace-in-string end-date "\\." "/" t)))
     (planner-mode))
   (goto-char (point-min)))
 
@@ -169,8 +178,10 @@
                                             (p1t2time p1t2ratio p1t2name)
                                            ...)
    ((p2name p2time p2ratio) ...)))"
-  (let ((data-list (planner-timeclock-one-day-alist date))
-       (target-data))
+       (planner-timeclock-summary-extract-data 
(planner-timeclock-one-day-alist date)))
+
+(defun planner-timeclock-summary-extract-data (data-list)
+  (let ((target-data))
     (while data-list
       (setq entry (pop data-list))
       (setq task-data (planner-timeclock-summary-extract-task-data entry))
@@ -229,9 +240,12 @@
                                                    entry-task-name)) t)))))
     target-data))
 
-(defun planner-timeclock-summary-calculate-ratio-day (date)
+(defun planner-timeclock-summary-calculate-ratio-day (start-date &optional 
end-date)
   "calculate time ratio for DATE."
-  (setq target-data (planner-timeclock-summary-extract-data-day date))
+       (when (not end-date)
+               (setq end-date start-date))
+  (setq target-data (planner-timeclock-summary-extract-data 
+                                                                               
 (cdr (planner-timeclock-day-range-entry start-date end-date))))
   (let ((total (car target-data))
        (projects (cdr target-data)))
     (while projects
@@ -245,10 +259,12 @@
        (setq projects (cdr projects)))))
   target-data)
 
-(defun planner-timeclock-summary-make-text-table-day (date)
+(defun planner-timeclock-summary-make-text-table-day (start-date &optional 
end-date)
   "Make the summary table for DATE using plain text."
+       (when (not end-date)
+               (setq end-date start-date))
   (setq source-list (planner-timeclock-summary-calculate-ratio-day
-                    date))
+                    start-date end-date))
   (let ((projects (cdr source-list))
        (total (car source-list)))
     (if total
@@ -297,20 +313,23 @@
                            (length planner-timeclock-summary-empty-cell-string)
                            (aref " " 0))))
          (goto-char (point-max))
-         (insert (planner-timeclock-summary-make-summary-string date total))
+         (insert (planner-timeclock-summary-make-summary-string-range 
start-date end-date total))
          (buffer-string))
       "")))
 
 (defun planner-timeclock-summary-make-summary-string (date total)
+       (planner-timeclock-summary-make-summary-string-range date date total))
+
+(defun planner-timeclock-summary-make-summary-string-range (start-date 
end-date total)
   "Use `planner-timeclock-summary-summary-string' to make the summary for DATE.
 Date is in format YYYY/MM/DD. TOTAL is the total time clocked
 today, in seconds."
   (let ((target-string planner-timeclock-summary-summary-string)
-       (data (planner-timeclock-one-day-entry-no-date date))
+       (data (planner-timeclock-day-range-entry start-date end-date))
        begin end last Span span)
     (setq begin (timeclock-day-begin data))
     (setq end (timeclock-day-end data))
-    (if (string-equal date (format-time-string "%Y/%m/%d"))
+    (if (string-equal end-date (format-time-string "%Y/%m/%d"))
        (setq last (current-time))
       (setq last end))
     (setq span (timeclock-time-to-seconds (time-subtract last begin)))
@@ -366,30 +385,53 @@
        (setq task-name task-fullname)))
     (list project-name task-name task-length)))
 
-(defun planner-timeclock-one-day-entry (date)
-  "Return the data associated with DATE.
-DATE should be a string of the form YYYY/MM/DD.
+(defun planner-timeclock-day-range-entry (start-date end-date)
+  "Return the data between START-DATE and END-DATE (inclusive)
+START-DATE and END-DATE should be strings of the form YYYY/MM/DD.
 Use the format specified in timeclock.el."
   (let ((day-list (timeclock-day-alist))
        entry-list)
     (while day-list
       (let ((theday (pop day-list)))
-       (if (string-match date (car theday))
-           (progn
-             (setq entry-list theday)
-             (setq day-list nil)))))
-    entry-list))
+                               (when (planner-timeclock-within-date-range 
start-date end-date (car theday))
+                                       (setq entry-list (append (cddr theday) 
entry-list)))))
+    (if (string= start-date end-date)
+                               (cons start-date entry-list)
+                       (cons (concat start-date " - " end-date) entry-list))))
+
+(defun planner-timeclock-within-date-range (start-date end-date test-date)
+       "Return non-nil if DATE-TEST is within the date range START-DATE to 
END-DATE."
+       (let ((start-list (split-string start-date "/"))
+                               (end-list (split-string end-date "/"))
+                               (test-list (split-string test-date "/")))
+                                        (if (and (<= (string-to-int (nth 0 
start-list)) (string-to-int (nth 0 test-list)))
+                                                       (>= (string-to-int (nth 
0 end-list)) (string-to-int (nth 0 test-list)))
+                                                       (<= (string-to-int (nth 
1 start-list)) (string-to-int (nth 1 test-list)))
+                                                       (>= (string-to-int (nth 
1 end-list)) (string-to-int (nth 1 test-list)))
+                                                       (<= (string-to-int (nth 
2 start-list)) (string-to-int (nth 2 test-list)))
+                                                       (>= (string-to-int (nth 
2 end-list)) (string-to-int (nth 2 test-list)))) t nil)))
+
+(defun planner-timeclock-one-day-entry (date)
+  "Return the data associated with DATE.
+DATE should be a string of the form YYYY/MM/DD."
+  (planner-timeclock-day-range-entry date date))
 
 (defun planner-timeclock-one-day-entry-no-date (date)
   "Return the entries for DATE.
 DATE should be a string of the form YYYY/MM/DD."
-  (let ((entry-list (planner-timeclock-one-day-entry date)))
+  (let ((entry-list (planner-timeclock-day-range-entry date date)))
     (cdr entry-list)))
 
 (defun planner-timeclock-one-day-alist (date)
   "Return the entries for DATE as an alist.
 DATE should be a string of the form YYYY/MM/DD."
-  (let ((entry-list (planner-timeclock-one-day-entry date)))
+  (let ((entry-list (planner-timeclock-day-range-entry date date)))
+    (cddr entry-list)))
+
+(defun planner-timeclock-day-range-alist (start-date end-date)
+  "Return the entries between START-DATE and END-DATE (inclusive) as an alist.
+START-DATE and END-DATE should be strings of the form YYYY/MM/DD."
+  (let ((entry-list (planner-timeclock-day-range-entry start-date end-date)))
     (cddr entry-list)))
 
 ;; XEmacs has `replace-in-string', Gnu Emacs has

Diff finished at Wed Dec 15 10:20:45

-- 
Chris Parsons
address@hidden





reply via email to

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