Mercurial > emacs
annotate lisp/calendar/timeclock.el @ 94381:0a65cf8b9e03
(quoted-insert, zap-to-char): Revert previous change.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 26 Apr 2008 20:13:00 +0000 |
parents | c3b09ba22de9 |
children | e49abd957e81 |
rev | line source |
---|---|
30781 | 1 ;;; timeclock.el --- mode for keeping track of how much you work |
2 | |
92600 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4 ;; 2008 Free Software Foundation, Inc. | |
30781 | 5 |
6 ;; Author: John Wiegley <johnw@gnu.org> | |
7 ;; Created: 25 Mar 1999 | |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
8 ;; Version: 2.6.1 |
30781 | 9 ;; Keywords: calendar data |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
78216
93e11478c954
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77900
diff
changeset
|
15 ;; the Free Software Foundation; either version 3, or (at your option) |
30781 | 16 ;; any later version. |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
30781 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; This mode is for keeping track of time intervals. You can use it | |
31 ;; for whatever purpose you like, but the typical scenario is to keep | |
32 ;; track of how much time you spend working on certain projects. | |
33 ;; | |
34 ;; Use `timeclock-in' when you start on a project, and `timeclock-out' | |
35 ;; when you're done. Once you've collected some data, you can use | |
36 ;; `timeclock-workday-remaining' to see how much time is left to be | |
51871 | 37 ;; worked today (where `timeclock-workday' specifies the length of the |
38 ;; working day), and `timeclock-when-to-leave' to calculate when you're free. | |
30781 | 39 |
40 ;; You'll probably want to bind the timeclock commands to some handy | |
51871 | 41 ;; keystrokes. At the moment, C-x t is unused: |
30781 | 42 ;; |
43 ;; (require 'timeclock) | |
44 ;; | |
45 ;; (define-key ctl-x-map "ti" 'timeclock-in) | |
46 ;; (define-key ctl-x-map "to" 'timeclock-out) | |
47 ;; (define-key ctl-x-map "tc" 'timeclock-change) | |
48 ;; (define-key ctl-x-map "tr" 'timeclock-reread-log) | |
49 ;; (define-key ctl-x-map "tu" 'timeclock-update-modeline) | |
50 ;; (define-key ctl-x-map "tw" 'timeclock-when-to-leave-string) | |
51 | |
52 ;; If you want Emacs to display the amount of time "left" to your | |
53 ;; workday in the modeline, you can either set the value of | |
54 ;; `timeclock-modeline-display' to t using M-x customize, or you | |
55 ;; can add this code to your .emacs file: | |
56 ;; | |
57 ;; (require 'timeclock) | |
58 ;; (timeclock-modeline-display) | |
59 ;; | |
60 ;; To cancel this modeline display at any time, just call | |
61 ;; `timeclock-modeline-display' again. | |
62 | |
63 ;; You may also want Emacs to ask you before exiting, if you are | |
54704 | 64 ;; currently working on a project. This can be done either by setting |
30781 | 65 ;; `timeclock-ask-before-exiting' to t using M-x customize (this is |
66 ;; the default), or by adding the following to your .emacs file: | |
67 ;; | |
51263 | 68 ;; (add-hook 'kill-emacs-query-functions 'timeclock-query-out) |
30781 | 69 |
70 ;; NOTE: If you change your .timelog file without using timeclock's | |
71 ;; functions, or if you change the value of any of timeclock's | |
72 ;; customizable variables, you should run the command | |
73 ;; `timeclock-reread-log'. This will recompute any discrepancies in | |
74 ;; your average working time, and will make sure that the various | |
75 ;; display functions return the correct value. | |
76 | |
77 ;;; History: | |
78 | |
79 ;;; Code: | |
80 | |
81 (defgroup timeclock nil | |
61327 | 82 "Keeping track of the time that gets spent." |
30781 | 83 :group 'data) |
84 | |
85 ;;; User Variables: | |
86 | |
30795
5b4027fef808
(timeclock-file): Run .timelog through convert-standard-filename.
Eli Zaretskii <eliz@gnu.org>
parents:
30781
diff
changeset
|
87 (defcustom timeclock-file (convert-standard-filename "~/.timelog") |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
88 "The file used to store timeclock data in." |
30781 | 89 :type 'file |
90 :group 'timeclock) | |
91 | |
92 (defcustom timeclock-workday (* 8 60 60) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
93 "The length of a work period in seconds." |
30781 | 94 :type 'integer |
95 :group 'timeclock) | |
96 | |
97 (defcustom timeclock-relative t | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
98 "Whether to make reported time relative to `timeclock-workday'. |
30781 | 99 For example, if the length of a normal workday is eight hours, and you |
100 work four hours on Monday, then the amount of time \"remaining\" on | |
101 Tuesday is twelve hours -- relative to an averaged work period of | |
102 eight hours -- or eight hours, non-relative. So relative time takes | |
51871 | 103 into account any discrepancy of time under-worked or over-worked on |
104 previous days. This only affects the timeclock modeline display." | |
30781 | 105 :type 'boolean |
106 :group 'timeclock) | |
107 | |
108 (defcustom timeclock-get-project-function 'timeclock-ask-for-project | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
109 "The function used to determine the name of the current project. |
30781 | 110 When clocking in, and no project is specified, this function will be |
54704 | 111 called to determine what is the current project to be worked on. |
30781 | 112 If this variable is nil, no questions will be asked." |
113 :type 'function | |
114 :group 'timeclock) | |
115 | |
116 (defcustom timeclock-get-reason-function 'timeclock-ask-for-reason | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
117 "A function used to determine the reason for clocking out. |
30781 | 118 When clocking out, and no reason is specified, this function will be |
54704 | 119 called to determine what is the reason. |
30781 | 120 If this variable is nil, no questions will be asked." |
121 :type 'function | |
122 :group 'timeclock) | |
123 | |
124 (defcustom timeclock-get-workday-function nil | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
125 "A function used to determine the length of today's workday. |
30781 | 126 The first time that a user clocks in each day, this function will be |
54704 | 127 called to determine what is the length of the current workday. If |
46341
ff3a56c0df0f
(timeclock-get-workday-function): `timeclock-workday' is not a valid
Glenn Morris <rgm@gnu.org>
parents:
46160
diff
changeset
|
128 the return value is nil, or equal to `timeclock-workday', nothing special |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48224
diff
changeset
|
129 will be done. If it is a quantity different from `timeclock-workday', |
46341
ff3a56c0df0f
(timeclock-get-workday-function): `timeclock-workday' is not a valid
Glenn Morris <rgm@gnu.org>
parents:
46160
diff
changeset
|
130 however, a record will be output to the timelog file to note the fact that |
54704 | 131 that day has a length that is different from the norm." |
46341
ff3a56c0df0f
(timeclock-get-workday-function): `timeclock-workday' is not a valid
Glenn Morris <rgm@gnu.org>
parents:
46160
diff
changeset
|
132 :type '(choice (const nil) function) |
30781 | 133 :group 'timeclock) |
134 | |
135 (defcustom timeclock-ask-before-exiting t | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
136 "If non-nil, ask if the user wants to clock out before exiting Emacs. |
54704 | 137 This variable only has effect if set with \\[customize]." |
30781 | 138 :set (lambda (symbol value) |
139 (if value | |
51263 | 140 (add-hook 'kill-emacs-query-functions 'timeclock-query-out) |
141 (remove-hook 'kill-emacs-query-functions 'timeclock-query-out)) | |
30781 | 142 (setq timeclock-ask-before-exiting value)) |
143 :type 'boolean | |
144 :group 'timeclock) | |
145 | |
146 (defvar timeclock-update-timer nil | |
147 "The timer used to update `timeclock-mode-string'.") | |
148 | |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
149 ;; For byte-compiler. |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
150 (defvar display-time-hook) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
151 (defvar timeclock-modeline-display) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
152 |
30781 | 153 (defcustom timeclock-use-display-time t |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
154 "If non-nil, use `display-time-hook' for doing modeline updates. |
54704 | 155 The advantage of this is that one less timer has to be set running |
156 amok in Emacs' process space. The disadvantage is that it requires | |
157 you to have `display-time' running. If you don't want to use | |
30781 | 158 `display-time', but still want the modeline to show how much time is |
51871 | 159 left, set this variable to nil. Changing the value of this variable |
160 while timeclock information is being displayed in the modeline has no | |
161 effect. You should call the function `timeclock-modeline-display' with | |
162 a positive argument to force an update." | |
30781 | 163 :set (lambda (symbol value) |
164 (let ((currently-displaying | |
165 (and (boundp 'timeclock-modeline-display) | |
166 timeclock-modeline-display))) | |
167 ;; if we're changing to the state that | |
168 ;; `timeclock-modeline-display' is already using, don't | |
169 ;; bother toggling it. This happens on the initial loading | |
170 ;; of timeclock.el. | |
171 (if (and currently-displaying | |
172 (or (and value | |
173 (boundp 'display-time-hook) | |
174 (memq 'timeclock-update-modeline | |
175 display-time-hook)) | |
176 (and (not value) | |
177 timeclock-update-timer))) | |
178 (setq currently-displaying nil)) | |
179 (and currently-displaying | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
180 (set-variable 'timeclock-modeline-display nil)) |
30781 | 181 (setq timeclock-use-display-time value) |
182 (and currently-displaying | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
183 (set-variable 'timeclock-modeline-display t)) |
30781 | 184 timeclock-use-display-time)) |
185 :type 'boolean | |
186 :group 'timeclock | |
187 :require 'time) | |
188 | |
189 (defcustom timeclock-first-in-hook nil | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
190 "A hook run for the first \"in\" event each day. |
30781 | 191 Note that this hook is run before recording any events. Thus the |
192 value of `timeclock-hours-today', `timeclock-last-event' and the | |
193 return value of function `timeclock-last-period' are relative previous | |
194 to today." | |
195 :type 'hook | |
196 :group 'timeclock) | |
197 | |
198 (defcustom timeclock-load-hook nil | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
199 "Hook that gets run after timeclock has been loaded." |
30781 | 200 :type 'hook |
201 :group 'timeclock) | |
202 | |
203 (defcustom timeclock-in-hook nil | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
204 "A hook run every time an \"in\" event is recorded." |
30781 | 205 :type 'hook |
206 :group 'timeclock) | |
207 | |
208 (defcustom timeclock-day-over-hook nil | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
209 "A hook that is run when the workday has been completed. |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
210 This hook is only run if the current time remaining is being displayed |
30781 | 211 in the modeline. See the variable `timeclock-modeline-display'." |
212 :type 'hook | |
213 :group 'timeclock) | |
214 | |
215 (defcustom timeclock-out-hook nil | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
216 "A hook run every time an \"out\" event is recorded." |
30781 | 217 :type 'hook |
218 :group 'timeclock) | |
219 | |
220 (defcustom timeclock-done-hook nil | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
221 "A hook run every time a project is marked as completed." |
30781 | 222 :type 'hook |
223 :group 'timeclock) | |
224 | |
225 (defcustom timeclock-event-hook nil | |
92548
979f17a77d87
Remove leading `*' from defcustom doc-strings.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
226 "A hook run every time any event is recorded." |
30781 | 227 :type 'hook |
228 :group 'timeclock) | |
229 | |
230 (defvar timeclock-last-event nil | |
231 "A list containing the last event that was recorded. | |
33020 | 232 The format of this list is (CODE TIME PROJECT).") |
30781 | 233 |
234 (defvar timeclock-last-event-workday nil | |
235 "The number of seconds in the workday of `timeclock-last-event'.") | |
236 | |
237 ;;; Internal Variables: | |
238 | |
239 (defvar timeclock-discrepancy nil | |
240 "A variable containing the time discrepancy before the last event. | |
241 Normally, timeclock assumes that you intend to work for | |
242 `timeclock-workday' seconds every day. Any days in which you work | |
243 more or less than this amount is considered either a positive or | |
54704 | 244 a negative discrepancy. If you work in such a manner that the |
30781 | 245 discrepancy is always brought back to zero, then you will by |
246 definition have worked an average amount equal to `timeclock-workday' | |
247 each day.") | |
248 | |
249 (defvar timeclock-elapsed nil | |
250 "A variable containing the time elapsed for complete periods today. | |
251 This value is not accurate enough to be useful by itself. Rather, | |
252 call `timeclock-workday-elapsed', to determine how much time has been | |
253 worked so far today. Also, if `timeclock-relative' is nil, this value | |
72331
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
254 will be the same as `timeclock-discrepancy'.") |
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
255 |
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
256 (defvar timeclock-use-elapsed nil |
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
257 "Non-nil if the modeline should display time elapsed, not remaining.") |
30781 | 258 |
259 (defvar timeclock-last-period nil | |
260 "Integer representing the number of seconds in the last period. | |
54704 | 261 Note that you shouldn't access this value, but instead should use the |
262 function `timeclock-last-period'.") | |
30781 | 263 |
264 (defvar timeclock-mode-string nil | |
51263 | 265 "The timeclock string (optionally) displayed in the modeline. |
266 The time is bracketed by <> if you are clocked in, otherwise by [].") | |
30781 | 267 |
268 (defvar timeclock-day-over nil | |
269 "The date of the last day when notified \"day over\" for.") | |
270 | |
271 ;;; User Functions: | |
272 | |
273 ;;;###autoload | |
274 (defun timeclock-modeline-display (&optional arg) | |
275 "Toggle display of the amount of time left today in the modeline. | |
51263 | 276 If `timeclock-use-display-time' is non-nil (the default), then |
277 the function `display-time-mode' must be active, and the modeline | |
278 will be updated whenever the time display is updated. Otherwise, | |
279 the timeclock will use its own sixty second timer to do its | |
280 updating. With prefix ARG, turn modeline display on if and only | |
281 if ARG is positive. Returns the new status of timeclock modeline | |
282 display (non-nil means on)." | |
30781 | 283 (interactive "P") |
51263 | 284 ;; cf display-time-mode. |
285 (setq timeclock-mode-string "") | |
286 (or global-mode-string (setq global-mode-string '(""))) | |
30781 | 287 (let ((on-p (if arg |
288 (> (prefix-numeric-value arg) 0) | |
289 (not timeclock-modeline-display)))) | |
290 (if on-p | |
51263 | 291 (progn |
292 (or (memq 'timeclock-mode-string global-mode-string) | |
293 (setq global-mode-string | |
294 (append global-mode-string '(timeclock-mode-string)))) | |
30781 | 295 (unless (memq 'timeclock-update-modeline timeclock-event-hook) |
296 (add-hook 'timeclock-event-hook 'timeclock-update-modeline)) | |
297 (when timeclock-update-timer | |
298 (cancel-timer timeclock-update-timer) | |
299 (setq timeclock-update-timer nil)) | |
300 (if (boundp 'display-time-hook) | |
301 (remove-hook 'display-time-hook 'timeclock-update-modeline)) | |
302 (if timeclock-use-display-time | |
51263 | 303 (progn |
304 ;; Update immediately so there is a visible change | |
305 ;; on calling this function. | |
51871 | 306 (if display-time-mode (timeclock-update-modeline) |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
307 (message "Activate `display-time-mode' or turn off \ |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
308 `timeclock-use-display-time' to see timeclock information")) |
51263 | 309 (add-hook 'display-time-hook 'timeclock-update-modeline)) |
30781 | 310 (setq timeclock-update-timer |
311 (run-at-time nil 60 'timeclock-update-modeline)))) | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
312 (setq global-mode-string |
51263 | 313 (delq 'timeclock-mode-string global-mode-string)) |
30781 | 314 (remove-hook 'timeclock-event-hook 'timeclock-update-modeline) |
315 (if (boundp 'display-time-hook) | |
316 (remove-hook 'display-time-hook | |
317 'timeclock-update-modeline)) | |
318 (when timeclock-update-timer | |
319 (cancel-timer timeclock-update-timer) | |
320 (setq timeclock-update-timer nil))) | |
321 (force-mode-line-update) | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
322 (setq timeclock-modeline-display on-p))) |
30781 | 323 |
324 ;; This has to be here so that the function definition of | |
325 ;; `timeclock-modeline-display' is known to the "set" function. | |
326 (defcustom timeclock-modeline-display nil | |
327 "Toggle modeline display of time remaining. | |
328 You must modify via \\[customize] for this variable to have an effect." | |
329 :set (lambda (symbol value) | |
330 (setq timeclock-modeline-display | |
331 (timeclock-modeline-display (or value 0)))) | |
332 :type 'boolean | |
333 :group 'timeclock | |
334 :require 'timeclock) | |
335 | |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
336 (defsubst timeclock-time-to-date (time) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
337 "Convert the TIME value to a textual date string." |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
338 (format-time-string "%Y/%m/%d" time)) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
339 |
30781 | 340 ;;;###autoload |
341 (defun timeclock-in (&optional arg project find-project) | |
342 "Clock in, recording the current time moment in the timelog. | |
343 With a numeric prefix ARG, record the fact that today has only that | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
344 many hours in it to be worked. If ARG is a non-numeric prefix argument |
30781 | 345 \(non-nil, but not a number), 0 is assumed (working on a holiday or |
346 weekend). *If not called interactively, ARG should be the number of | |
347 _seconds_ worked today*. This feature only has effect the first time | |
348 this function is called within a day. | |
349 | |
54704 | 350 PROJECT is the project being clocked into. If PROJECT is nil, and |
30781 | 351 FIND-PROJECT is non-nil -- or the user calls `timeclock-in' |
352 interactively -- call the function `timeclock-get-project-function' to | |
353 discover the name of the project." | |
354 (interactive | |
355 (list (and current-prefix-arg | |
356 (if (numberp current-prefix-arg) | |
357 (* current-prefix-arg 60 60) | |
358 0)))) | |
359 (if (equal (car timeclock-last-event) "i") | |
360 (error "You've already clocked in!") | |
361 (unless timeclock-last-event | |
362 (timeclock-reread-log)) | |
46350
9cead6e97a53
(timeclock-in): Run the new day section if, after rereading the log file,
Glenn Morris <rgm@gnu.org>
parents:
46341
diff
changeset
|
363 ;; Either no log file, or day has rolled over. |
9cead6e97a53
(timeclock-in): Run the new day section if, after rereading the log file,
Glenn Morris <rgm@gnu.org>
parents:
46341
diff
changeset
|
364 (unless (and timeclock-last-event |
9cead6e97a53
(timeclock-in): Run the new day section if, after rereading the log file,
Glenn Morris <rgm@gnu.org>
parents:
46341
diff
changeset
|
365 (equal (timeclock-time-to-date |
9cead6e97a53
(timeclock-in): Run the new day section if, after rereading the log file,
Glenn Morris <rgm@gnu.org>
parents:
46341
diff
changeset
|
366 (cadr timeclock-last-event)) |
9cead6e97a53
(timeclock-in): Run the new day section if, after rereading the log file,
Glenn Morris <rgm@gnu.org>
parents:
46341
diff
changeset
|
367 (timeclock-time-to-date (current-time)))) |
30781 | 368 (let ((workday (or (and (numberp arg) arg) |
369 (and arg 0) | |
370 (and timeclock-get-workday-function | |
371 (funcall timeclock-get-workday-function)) | |
372 timeclock-workday))) | |
373 (run-hooks 'timeclock-first-in-hook) | |
374 ;; settle the discrepancy for the new day | |
375 (setq timeclock-discrepancy | |
46350
9cead6e97a53
(timeclock-in): Run the new day section if, after rereading the log file,
Glenn Morris <rgm@gnu.org>
parents:
46341
diff
changeset
|
376 (- (or timeclock-discrepancy 0) workday)) |
30781 | 377 (if (not (= workday timeclock-workday)) |
77671
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
378 (timeclock-log "h" (number-to-string |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
379 (/ workday (if (zerop (% workday (* 60 60))) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
380 60 60.0) 60)))))) |
30781 | 381 (timeclock-log "i" (or project |
382 (and timeclock-get-project-function | |
383 (or find-project (interactive-p)) | |
384 (funcall timeclock-get-project-function)))) | |
385 (run-hooks 'timeclock-in-hook))) | |
386 | |
387 ;;;###autoload | |
388 (defun timeclock-out (&optional arg reason find-reason) | |
389 "Clock out, recording the current time moment in the timelog. | |
390 If a prefix ARG is given, the user has completed the project that was | |
391 begun during the last time segment. | |
392 | |
393 REASON is the user's reason for clocking out. If REASON is nil, and | |
394 FIND-REASON is non-nil -- or the user calls `timeclock-out' | |
395 interactively -- call the function `timeclock-get-reason-function' to | |
396 discover the reason." | |
397 (interactive "P") | |
40671
526c9b7941f5
(timeclock-out): Signal an error if timeclock-last-event is nil.
Eli Zaretskii <eliz@gnu.org>
parents:
37652
diff
changeset
|
398 (or timeclock-last-event |
526c9b7941f5
(timeclock-out): Signal an error if timeclock-last-event is nil.
Eli Zaretskii <eliz@gnu.org>
parents:
37652
diff
changeset
|
399 (error "You haven't clocked in!")) |
30781 | 400 (if (equal (downcase (car timeclock-last-event)) "o") |
401 (error "You've already clocked out!") | |
402 (timeclock-log | |
403 (if arg "O" "o") | |
404 (or reason | |
405 (and timeclock-get-reason-function | |
406 (or find-reason (interactive-p)) | |
407 (funcall timeclock-get-reason-function)))) | |
408 (run-hooks 'timeclock-out-hook) | |
409 (if arg | |
410 (run-hooks 'timeclock-done-hook)))) | |
411 | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
412 ;; Should today-only be removed in favour of timeclock-relative? - gm |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
413 (defsubst timeclock-workday-remaining (&optional today-only) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
414 "Return the number of seconds until the workday is complete. |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
415 The amount returned is relative to the value of `timeclock-workday'. |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
416 If TODAY-ONLY is non-nil, the value returned will be relative only to |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
417 the time worked today, and not to past time." |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
418 (let ((discrep (timeclock-find-discrep))) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
419 (if discrep |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
420 (- (if today-only (cadr discrep) |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
421 (car discrep))) |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
422 0.0))) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
423 |
30781 | 424 ;;;###autoload |
425 (defun timeclock-status-string (&optional show-seconds today-only) | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
426 "Report the overall timeclock status at the present moment. |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
427 If SHOW-SECONDS is non-nil, display second resolution. |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
428 If TODAY-ONLY is non-nil, the display will be relative only to time |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
429 worked today, ignoring the time worked on previous days." |
30781 | 430 (interactive "P") |
72331
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
431 (let ((remainder (timeclock-workday-remaining |
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
432 (or today-only |
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
433 (not timeclock-relative)))) |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
434 (last-in (equal (car timeclock-last-event) "i")) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
435 status) |
30781 | 436 (setq status |
437 (format "Currently %s since %s (%s), %s %s, leave at %s" | |
438 (if last-in "IN" "OUT") | |
439 (if show-seconds | |
440 (format-time-string "%-I:%M:%S %p" | |
441 (nth 1 timeclock-last-event)) | |
442 (format-time-string "%-I:%M %p" | |
443 (nth 1 timeclock-last-event))) | |
444 (or (nth 2 timeclock-last-event) | |
445 (if last-in "**UNKNOWN**" "workday over")) | |
446 (timeclock-seconds-to-string remainder show-seconds t) | |
447 (if (> remainder 0) | |
448 "remaining" "over") | |
449 (timeclock-when-to-leave-string show-seconds today-only))) | |
450 (if (interactive-p) | |
65591
a65f8ec418fc
message format spec fixes, commit # 10
Deepak Goel <deego@gnufans.org>
parents:
64085
diff
changeset
|
451 (message "%s" status) |
30781 | 452 status))) |
453 | |
454 ;;;###autoload | |
455 (defun timeclock-change (&optional arg project) | |
54704 | 456 "Change to working on a different project. |
457 This clocks out of the current project, then clocks in on a new one. | |
458 With a prefix ARG, consider the previous project as finished at the | |
459 time of changeover. PROJECT is the name of the last project you were | |
460 working on." | |
30781 | 461 (interactive "P") |
462 (timeclock-out arg) | |
463 (timeclock-in nil project (interactive-p))) | |
464 | |
465 ;;;###autoload | |
466 (defun timeclock-query-out () | |
54704 | 467 "Ask the user whether to clock out. |
51263 | 468 This is a useful function for adding to `kill-emacs-query-functions'." |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
469 (and (equal (car timeclock-last-event) "i") |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
470 (y-or-n-p "You're currently clocking time, clock out? ") |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
471 (timeclock-out)) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
472 ;; Unconditionally return t for `kill-emacs-query-functions'. |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
473 t) |
30781 | 474 |
475 ;;;###autoload | |
476 (defun timeclock-reread-log () | |
477 "Re-read the timeclock, to account for external changes. | |
478 Returns the new value of `timeclock-discrepancy'." | |
479 (interactive) | |
480 (setq timeclock-discrepancy nil) | |
481 (timeclock-find-discrep) | |
36851 | 482 (if (and timeclock-discrepancy timeclock-modeline-display) |
30781 | 483 (timeclock-update-modeline)) |
484 timeclock-discrepancy) | |
485 | |
486 (defun timeclock-seconds-to-string (seconds &optional show-seconds | |
487 reverse-leader) | |
488 "Convert SECONDS into a compact time string. | |
489 If SHOW-SECONDS is non-nil, make the resolution of the return string | |
490 include the second count. If REVERSE-LEADER is non-nil, it means to | |
491 output a \"+\" if the time value is negative, rather than a \"-\". | |
492 This is used when negative time values have an inverted meaning (such | |
493 as with time remaining, where negative time really means overtime)." | |
494 (if show-seconds | |
495 (format "%s%d:%02d:%02d" | |
496 (if (< seconds 0) (if reverse-leader "+" "-") "") | |
497 (truncate (/ (abs seconds) 60 60)) | |
498 (% (truncate (/ (abs seconds) 60)) 60) | |
499 (% (truncate (abs seconds)) 60)) | |
500 (format "%s%d:%02d" | |
501 (if (< seconds 0) (if reverse-leader "+" "-") "") | |
502 (truncate (/ (abs seconds) 60 60)) | |
503 (% (truncate (/ (abs seconds) 60)) 60)))) | |
504 | |
33020 | 505 (defsubst timeclock-currently-in-p () |
30781 | 506 "Return non-nil if the user is currently clocked in." |
507 (equal (car timeclock-last-event) "i")) | |
508 | |
509 ;;;###autoload | |
510 (defun timeclock-workday-remaining-string (&optional show-seconds | |
511 today-only) | |
512 "Return a string representing the amount of time left today. | |
513 Display second resolution if SHOW-SECONDS is non-nil. If TODAY-ONLY | |
514 is non-nil, the display will be relative only to time worked today. | |
515 See `timeclock-relative' for more information about the meaning of | |
516 \"relative to today\"." | |
517 (interactive) | |
518 (let ((string (timeclock-seconds-to-string | |
519 (timeclock-workday-remaining today-only) | |
520 show-seconds t))) | |
521 (if (interactive-p) | |
65591
a65f8ec418fc
message format spec fixes, commit # 10
Deepak Goel <deego@gnufans.org>
parents:
64085
diff
changeset
|
522 (message "%s" string) |
30781 | 523 string))) |
524 | |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
525 (defsubst timeclock-workday-elapsed () |
46160
b88409633904
(timeclock-workday-remaining): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
40671
diff
changeset
|
526 "Return the number of seconds worked so far today. |
30781 | 527 If RELATIVE is non-nil, the amount returned will be relative to past |
528 time worked. The default is to return only the time that has elapsed | |
529 so far today." | |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
530 (let ((discrep (timeclock-find-discrep))) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
531 (if discrep |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
532 (nth 2 discrep) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
533 0.0))) |
30781 | 534 |
535 ;;;###autoload | |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
536 (defun timeclock-workday-elapsed-string (&optional show-seconds) |
30781 | 537 "Return a string representing the amount of time worked today. |
538 Display seconds resolution if SHOW-SECONDS is non-nil. If RELATIVE is | |
539 non-nil, the amount returned will be relative to past time worked." | |
540 (interactive) | |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
541 (let ((string (timeclock-seconds-to-string (timeclock-workday-elapsed) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
542 show-seconds))) |
30781 | 543 (if (interactive-p) |
65591
a65f8ec418fc
message format spec fixes, commit # 10
Deepak Goel <deego@gnufans.org>
parents:
64085
diff
changeset
|
544 (message "%s" string) |
30781 | 545 string))) |
546 | |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
547 (defsubst timeclock-time-to-seconds (time) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
548 "Convert TIME to a floating point number." |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
549 (+ (* (car time) 65536.0) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
550 (cadr time) |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
551 (/ (or (nth 2 time) 0) 1000000.0))) |
51549
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
552 |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
553 (defsubst timeclock-seconds-to-time (seconds) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
554 "Convert SECONDS (a floating point number) to an Emacs time structure." |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
555 (list (floor seconds 65536) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
556 (floor (mod seconds 65536)) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
557 (floor (* (- seconds (ffloor seconds)) 1000000)))) |
48facdb1558e
(display-time-hook, timeclock-modeline-display): Define for byte-compiler.
Glenn Morris <rgm@gnu.org>
parents:
51263
diff
changeset
|
558 |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
559 ;; Should today-only be removed in favour of timeclock-relative? - gm |
33020 | 560 (defsubst timeclock-when-to-leave (&optional today-only) |
54704 | 561 "Return a time value representing the end of today's workday. |
30781 | 562 If TODAY-ONLY is non-nil, the value returned will be relative only to |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
563 the time worked today, and not to past time." |
30781 | 564 (timeclock-seconds-to-time |
565 (- (timeclock-time-to-seconds (current-time)) | |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
566 (let ((discrep (timeclock-find-discrep))) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
567 (if discrep |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
568 (if today-only |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
569 (cadr discrep) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
570 (car discrep)) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
571 0.0))))) |
30781 | 572 |
573 ;;;###autoload | |
574 (defun timeclock-when-to-leave-string (&optional show-seconds | |
575 today-only) | |
54704 | 576 "Return a string representing the end of today's workday. |
30781 | 577 This string is relative to the value of `timeclock-workday'. If |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
578 SHOW-SECONDS is non-nil, the value printed/returned will include |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
579 seconds. If TODAY-ONLY is non-nil, the value returned will be |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
580 relative only to the time worked today, and not to past time." |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
581 ;; Should today-only be removed in favour of timeclock-relative? - gm |
30781 | 582 (interactive) |
583 (let* ((then (timeclock-when-to-leave today-only)) | |
584 (string | |
585 (if show-seconds | |
586 (format-time-string "%-I:%M:%S %p" then) | |
587 (format-time-string "%-I:%M %p" then)))) | |
588 (if (interactive-p) | |
65591
a65f8ec418fc
message format spec fixes, commit # 10
Deepak Goel <deego@gnufans.org>
parents:
64085
diff
changeset
|
589 (message "%s" string) |
30781 | 590 string))) |
591 | |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
592 (defun timeclock-make-hours-explicit (old-default) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
593 "Specify all workday lengths in `timeclock-file'. |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
594 OLD-DEFAULT hours are set for every day that has no number indicated." |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
595 (interactive "P") |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
596 (if old-default (setq old-default (prefix-numeric-value old-default)) |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
597 (error "`timelog-make-hours-explicit' requires an explicit argument")) |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
598 (let ((extant-timelog (find-buffer-visiting timeclock-file)) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
599 current-date) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
600 (with-current-buffer (find-file-noselect timeclock-file t) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
601 (unwind-protect |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
602 (save-excursion |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
603 (save-restriction |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
604 (widen) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
605 (goto-char (point-min)) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
606 (while (progn (skip-chars-forward "\n") (not (eobp))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
607 ;; This is just a variant of `timeclock-moment-regexp'. |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
608 (unless (looking-at |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
609 (concat "^\\([bhioO]\\) \\([0-9]+/[0-9]+/[0-9]+\\) " |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
610 "\\([0-9]+:[0-9]+:[0-9]+\\)")) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
611 (error "Can't parse `%s'" timeclock-file)) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
612 (let ((this-date (match-string 2))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
613 (unless (or (and current-date |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
614 (string= this-date current-date)) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
615 (string= (match-string 1) "h")) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
616 (insert (format "h %s %s %s\n" (match-string 2) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
617 (match-string 3) old-default))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
618 (if (string-match "^[ih]" (match-string 1)) ; ignore logouts |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
619 (setq current-date this-date))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
620 (forward-line)) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
621 (save-buffer))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
622 (unless extant-timelog (kill-buffer (current-buffer))))))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
623 |
30781 | 624 ;;; Internal Functions: |
625 | |
626 (defvar timeclock-project-list nil) | |
627 (defvar timeclock-last-project nil) | |
628 | |
37324
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
629 (defun timeclock-completing-read (prompt alist &optional default) |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
630 "A version of `completing-read' that works on both Emacs and XEmacs. |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
631 PROMPT, ALIST and DEFAULT are used for the PROMPT, COLLECTION and DEF |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
632 arguments of `completing-read'." |
37324
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
633 (if (featurep 'xemacs) |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
634 (let ((str (completing-read prompt alist))) |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
635 (if (or (null str) (zerop (length str))) |
37324
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
636 default |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
637 str)) |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
638 (completing-read prompt alist nil nil nil nil default))) |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
639 |
30781 | 640 (defun timeclock-ask-for-project () |
641 "Ask the user for the project they are clocking into." | |
37324
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
642 (timeclock-completing-read |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65591
diff
changeset
|
643 (format "Clock into which project (default %s): " |
37324
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
644 (or timeclock-last-project |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
645 (car timeclock-project-list))) |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
646 (mapcar 'list timeclock-project-list) |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
647 (or timeclock-last-project |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
648 (car timeclock-project-list)))) |
30781 | 649 |
650 (defvar timeclock-reason-list nil) | |
651 | |
652 (defun timeclock-ask-for-reason () | |
653 "Ask the user for the reason they are clocking out." | |
37324
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
654 (timeclock-completing-read "Reason for clocking out: " |
570c667b4d1c
(timeclock-completing-read): new function.
John Wiegley <johnw@newartisans.com>
parents:
37282
diff
changeset
|
655 (mapcar 'list timeclock-reason-list))) |
30781 | 656 |
657 (defun timeclock-update-modeline () | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
658 "Update the `timeclock-mode-string' displayed in the modeline. |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
659 The value of `timeclock-relative' affects the display as described in |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
660 that variable's documentation." |
30781 | 661 (interactive) |
72331
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
662 (let ((remainder |
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
663 (if timeclock-use-elapsed |
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
664 (timeclock-workday-elapsed) |
4e0c58818901
(timeclock-use-elapsed): Added a new variable, which causes timeclock
John Wiegley <johnw@newartisans.com>
parents:
68721
diff
changeset
|
665 (timeclock-workday-remaining (not timeclock-relative)))) |
51263 | 666 (last-in (equal (car timeclock-last-event) "i"))) |
30781 | 667 (when (and (< remainder 0) |
668 (not (and timeclock-day-over | |
669 (equal timeclock-day-over | |
670 (timeclock-time-to-date | |
671 (current-time)))))) | |
672 (setq timeclock-day-over | |
673 (timeclock-time-to-date (current-time))) | |
674 (run-hooks 'timeclock-day-over-hook)) | |
675 (setq timeclock-mode-string | |
51263 | 676 (propertize |
677 (format " %c%s%c " | |
678 (if last-in ?< ?[) | |
679 (timeclock-seconds-to-string remainder nil t) | |
680 (if last-in ?> ?])) | |
681 'help-echo "timeclock: time remaining")))) | |
682 | |
683 (put 'timeclock-mode-string 'risky-local-variable t) | |
30781 | 684 |
685 (defun timeclock-log (code &optional project) | |
686 "Log the event CODE to the timeclock log, at the time of call. | |
687 If PROJECT is a string, it represents the project which the event is | |
33020 | 688 being logged for. Normally only \"in\" events specify a project." |
77671
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
689 (let ((extant-timelog (find-buffer-visiting timeclock-file))) |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
690 (with-current-buffer (find-file-noselect timeclock-file t) |
77671
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
691 (save-excursion |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
692 (save-restriction |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
693 (widen) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
694 (goto-char (point-max)) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
695 (if (not (bolp)) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
696 (insert "\n")) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
697 (let ((now (current-time))) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
698 (insert code " " |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
699 (format-time-string "%Y/%m/%d %H:%M:%S" now) |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
700 (or (and (stringp project) |
77671
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
701 (> (length project) 0) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
702 (concat " " project)) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
703 "") |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
704 "\n") |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
705 (if (equal (downcase code) "o") |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
706 (setq timeclock-last-period |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
707 (- (timeclock-time-to-seconds now) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
708 (timeclock-time-to-seconds |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
709 (cadr timeclock-last-event))) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
710 timeclock-discrepancy |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
711 (+ timeclock-discrepancy |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
712 timeclock-last-period))) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
713 (setq timeclock-last-event (list code now project))))) |
693e049fff70
(timeclock-in): Fix non-interactive workday specifications.
Richard M. Stallman <rms@gnu.org>
parents:
75346
diff
changeset
|
714 (save-buffer) |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
715 (unless extant-timelog (kill-buffer (current-buffer))))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
716 (run-hooks 'timeclock-event-hook)) |
30781 | 717 |
33020 | 718 (defvar timeclock-moment-regexp |
719 (concat "\\([bhioO]\\)\\s-+" | |
720 "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)\\s-+" | |
721 "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)[ \t]*" "\\([^\n]*\\)")) | |
722 | |
723 (defsubst timeclock-read-moment () | |
30781 | 724 "Read the moment under point from the timelog." |
33020 | 725 (if (looking-at timeclock-moment-regexp) |
726 (let ((code (match-string 1)) | |
727 (year (string-to-number (match-string 2))) | |
728 (mon (string-to-number (match-string 3))) | |
729 (mday (string-to-number (match-string 4))) | |
730 (hour (string-to-number (match-string 5))) | |
731 (min (string-to-number (match-string 6))) | |
732 (sec (string-to-number (match-string 7))) | |
733 (project (match-string 8))) | |
734 (list code (encode-time sec min hour mday mon year) project)))) | |
30781 | 735 |
736 (defun timeclock-last-period (&optional moment) | |
737 "Return the value of the last event period. | |
738 If the last event was a clock-in, the period will be open ended, and | |
739 growing every second. Otherwise, it is a fixed amount which has been | |
740 recorded to disk. If MOMENT is non-nil, use that as the current time. | |
741 This is only provided for coherency when used by | |
742 `timeclock-discrepancy'." | |
743 (if (equal (car timeclock-last-event) "i") | |
744 (- (timeclock-time-to-seconds (or moment (current-time))) | |
745 (timeclock-time-to-seconds | |
746 (cadr timeclock-last-event))) | |
747 timeclock-last-period)) | |
748 | |
33020 | 749 (defsubst timeclock-entry-length (entry) |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
750 "Return the length of ENTRY in seconds." |
33020 | 751 (- (timeclock-time-to-seconds (cadr entry)) |
752 (timeclock-time-to-seconds (car entry)))) | |
753 | |
754 (defsubst timeclock-entry-begin (entry) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
755 "Return the start time of ENTRY." |
33020 | 756 (car entry)) |
757 | |
758 (defsubst timeclock-entry-end (entry) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
759 "Return the end time of ENTRY." |
33020 | 760 (cadr entry)) |
761 | |
762 (defsubst timeclock-entry-project (entry) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
763 "Return the project of ENTRY." |
33020 | 764 (nth 2 entry)) |
765 | |
766 (defsubst timeclock-entry-comment (entry) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
767 "Return the comment of ENTRY." |
33020 | 768 (nth 3 entry)) |
769 | |
770 (defsubst timeclock-entry-list-length (entry-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
771 "Return the total length of ENTRY-LIST in seconds." |
33020 | 772 (let ((length 0)) |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
773 (dolist (entry entry-list) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
774 (setq length (+ length (timeclock-entry-length entry)))) |
33020 | 775 length)) |
776 | |
777 (defsubst timeclock-entry-list-begin (entry-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
778 "Return the start time of the first element of ENTRY-LIST." |
33020 | 779 (timeclock-entry-begin (car entry-list))) |
780 | |
781 (defsubst timeclock-entry-list-end (entry-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
782 "Return the end time of the last element of ENTRY-LIST." |
33020 | 783 (timeclock-entry-end (car (last entry-list)))) |
784 | |
785 (defsubst timeclock-entry-list-span (entry-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
786 "Return the total time in seconds spanned by ENTRY-LIST." |
33020 | 787 (- (timeclock-time-to-seconds (timeclock-entry-list-end entry-list)) |
788 (timeclock-time-to-seconds (timeclock-entry-list-begin entry-list)))) | |
789 | |
790 (defsubst timeclock-entry-list-break (entry-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
791 "Return the total break time (span - length) in ENTRY-LIST." |
33020 | 792 (- (timeclock-entry-list-span entry-list) |
793 (timeclock-entry-list-length entry-list))) | |
794 | |
795 (defsubst timeclock-entry-list-projects (entry-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
796 "Return a list of all the projects in ENTRY-LIST." |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
797 (let (projects proj) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
798 (dolist (entry entry-list) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
799 (setq proj (timeclock-entry-project entry)) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
800 (if projects |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
801 (add-to-list 'projects proj) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
802 (setq projects (list proj)))) |
33020 | 803 projects)) |
804 | |
805 (defsubst timeclock-day-required (day) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
806 "Return the required length of DAY in seconds, default `timeclock-workday'." |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
807 (or (car day) timeclock-workday)) |
33020 | 808 |
809 (defsubst timeclock-day-length (day) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
810 "Return the actual length of DAY in seconds." |
33020 | 811 (timeclock-entry-list-length (cdr day))) |
812 | |
813 (defsubst timeclock-day-debt (day) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
814 "Return the debt (required - actual) associated with DAY, in seconds." |
33020 | 815 (- (timeclock-day-required day) |
816 (timeclock-day-length day))) | |
817 | |
818 (defsubst timeclock-day-begin (day) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
819 "Return the start time of DAY." |
33020 | 820 (timeclock-entry-list-begin (cdr day))) |
821 | |
822 (defsubst timeclock-day-end (day) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
823 "Return the end time of DAY." |
33020 | 824 (timeclock-entry-list-end (cdr day))) |
825 | |
826 (defsubst timeclock-day-span (day) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
827 "Return the span of DAY." |
33020 | 828 (timeclock-entry-list-span (cdr day))) |
829 | |
830 (defsubst timeclock-day-break (day) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
831 "Return the total break time of DAY." |
33020 | 832 (timeclock-entry-list-break (cdr day))) |
833 | |
834 (defsubst timeclock-day-projects (day) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
835 "Return a list of all the projects in DAY." |
33020 | 836 (timeclock-entry-list-projects (cdr day))) |
837 | |
838 (defmacro timeclock-day-list-template (func) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
839 "Template for summing the result of FUNC on each element of DAY-LIST." |
33020 | 840 `(let ((length 0)) |
841 (while day-list | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
842 (setq length (+ length (,(eval func) (car day-list))) |
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
843 day-list (cdr day-list))) |
33020 | 844 length)) |
845 | |
846 (defun timeclock-day-list-required (day-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
847 "Return total required length of DAY-LIST, in seconds." |
33020 | 848 (timeclock-day-list-template 'timeclock-day-required)) |
849 | |
850 (defun timeclock-day-list-length (day-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
851 "Return actual length of DAY-LIST, in seconds." |
33020 | 852 (timeclock-day-list-template 'timeclock-day-length)) |
853 | |
854 (defun timeclock-day-list-debt (day-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
855 "Return total debt (required - actual) of DAY-LIST." |
33020 | 856 (timeclock-day-list-template 'timeclock-day-debt)) |
857 | |
858 (defsubst timeclock-day-list-begin (day-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
859 "Return the start time of DAY-LIST." |
33020 | 860 (timeclock-day-begin (car day-list))) |
861 | |
862 (defsubst timeclock-day-list-end (day-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
863 "Return the end time of DAY-LIST." |
33020 | 864 (timeclock-day-end (car (last day-list)))) |
865 | |
866 (defun timeclock-day-list-span (day-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
867 "Return the span of DAY-LIST." |
33020 | 868 (timeclock-day-list-template 'timeclock-day-span)) |
869 | |
870 (defun timeclock-day-list-break (day-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
871 "Return the total break of DAY-LIST." |
33020 | 872 (timeclock-day-list-template 'timeclock-day-break)) |
873 | |
874 (defun timeclock-day-list-projects (day-list) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
875 "Return a list of all the projects in DAY-LIST." |
33020 | 876 (let (projects) |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
877 (dolist (day day-list) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
878 (dolist (proj (timeclock-day-projects day)) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
879 (if projects |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
880 (add-to-list 'projects proj) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
881 (setq projects (list proj))))) |
33020 | 882 projects)) |
883 | |
884 (defsubst timeclock-current-debt (&optional log-data) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
885 "Return the seconds debt from LOG-DATA, default `timeclock-log-data'." |
33020 | 886 (nth 0 (or log-data (timeclock-log-data)))) |
887 | |
888 (defsubst timeclock-day-alist (&optional log-data) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
889 "Return the date alist from LOG-DATA, default `timeclock-log-data'." |
33020 | 890 (nth 1 (or log-data (timeclock-log-data)))) |
891 | |
892 (defun timeclock-day-list (&optional log-data) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
893 "Return a list of the cdrs of the date alist from LOG-DATA." |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
894 (let (day-list) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
895 (dolist (date-list (timeclock-day-alist log-data)) |
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
896 (setq day-list (cons (cdr date-list) day-list))) |
33020 | 897 day-list)) |
898 | |
899 (defsubst timeclock-project-alist (&optional log-data) | |
92669
c0e9d49498b9
Add doc-strings to all functions.
Glenn Morris <rgm@gnu.org>
parents:
92600
diff
changeset
|
900 "Return the project alist from LOG-DATA, default `timeclock-log-data'." |
33020 | 901 (nth 2 (or log-data (timeclock-log-data)))) |
902 | |
903 (defun timeclock-log-data (&optional recent-only filename) | |
904 "Return the contents of the timelog file, in a useful format. | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
905 If the optional argument RECENT-ONLY is non-nil, only show the contents |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
906 from the last point where the time debt (see below) was set. |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
907 If the optional argument FILENAME is non-nil, it is used instead of |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
908 the file specified by `timeclock-file.' |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
909 |
33020 | 910 A timelog contains data in the form of a single entry per line. |
911 Each entry has the form: | |
912 | |
913 CODE YYYY/MM/DD HH:MM:SS [COMMENT] | |
914 | |
915 CODE is one of: b, h, i, o or O. COMMENT is optional when the code is | |
916 i, o or O. The meanings of the codes are: | |
917 | |
918 b Set the current time balance, or \"time debt\". Useful when | |
919 archiving old log data, when a debt must be carried forward. | |
920 The COMMENT here is the number of seconds of debt. | |
921 | |
922 h Set the required working time for the given day. This must | |
923 be the first entry for that day. The COMMENT in this case is | |
54704 | 924 the number of hours in this workday. Floating point amounts |
925 are allowed. | |
33020 | 926 |
927 i Clock in. The COMMENT in this case should be the name of the | |
928 project worked on. | |
929 | |
930 o Clock out. COMMENT is unnecessary, but can be used to provide | |
931 a description of how the period went, for example. | |
932 | |
933 O Final clock out. Whatever project was being worked on, it is | |
934 now finished. Useful for creating summary reports. | |
935 | |
936 When this function is called, it will return a data structure with the | |
937 following format: | |
938 | |
939 (DEBT ENTRIES-BY-DAY ENTRIES-BY-PROJECT) | |
940 | |
941 DEBT is a floating point number representing the number of seconds | |
942 \"owed\" before any work was done. For a new file (one without a 'b' | |
943 entry), this is always zero. | |
944 | |
945 The two entries lists have similar formats. They are both alists, | |
946 where the CAR is the index, and the CDR is a list of time entries. | |
947 For ENTRIES-BY-DAY, the CAR is a textual date string, of the form | |
948 YYYY/MM/DD. For ENTRIES-BY-PROJECT, it is the name of the project | |
949 worked on, or t for the default project. | |
950 | |
951 The CDR for ENTRIES-BY-DAY is slightly different than for | |
952 ENTRIES-BY-PROJECT. It has the following form: | |
953 | |
954 (DAY-LENGTH TIME-ENTRIES...) | |
955 | |
956 For ENTRIES-BY-PROJECT, there is no DAY-LENGTH member. It is simply a | |
957 list of TIME-ENTRIES. Note that if DAY-LENGTH is nil, it means | |
958 whatever is the default should be used. | |
959 | |
960 A TIME-ENTRY is a recorded time interval. It has the following format | |
961 \(although generally one does not have to manipulate these entries | |
962 directly; see below): | |
963 | |
964 (BEGIN-TIME END-TIME PROJECT [COMMENT] [FINAL-P]) | |
965 | |
966 Anyway, suffice it to say there are a lot of structures. Typically | |
967 the user is expected to manipulate to the day(s) or project(s) that he | |
968 or she wants, at which point the following helper functions may be | |
969 used: | |
970 | |
971 timeclock-day-required | |
972 timeclock-day-length | |
973 timeclock-day-debt | |
974 timeclock-day-begin | |
975 timeclock-day-end | |
976 timeclock-day-span | |
977 timeclock-day-break | |
978 timeclock-day-projects | |
979 | |
980 timeclock-day-list-required | |
981 timeclock-day-list-length | |
982 timeclock-day-list-debt | |
983 timeclock-day-list-begin | |
984 timeclock-day-list-end | |
985 timeclock-day-list-span | |
986 timeclock-day-list-break | |
987 timeclock-day-list-projects | |
988 | |
989 timeclock-entry-length | |
990 timeclock-entry-begin | |
991 timeclock-entry-end | |
992 timeclock-entry-project | |
993 timeclock-entry-comment | |
994 | |
995 timeclock-entry-list-length | |
996 timeclock-entry-list-begin | |
997 timeclock-entry-list-end | |
998 timeclock-entry-list-span | |
999 timeclock-entry-list-break | |
1000 timeclock-entry-list-projects | |
1001 | |
1002 A few comments should make the use of the above functions obvious: | |
1003 | |
1004 `required' is the amount of time that must be spent during a day, or | |
1005 sequence of days, in order to have no debt. | |
1006 | |
1007 `length' is the actual amount of time that was spent. | |
1008 | |
1009 `debt' is the difference between required time and length. A | |
1010 negative debt signifies overtime. | |
1011 | |
1012 `begin' is the earliest moment at which work began. | |
1013 | |
1014 `end' is the final moment work was done. | |
1015 | |
1016 `span' is the difference between begin and end. | |
1017 | |
1018 `break' is the difference between span and length. | |
1019 | |
1020 `project' is the project that was worked on, and `projects' is a | |
1021 list of all the projects that were worked on during a given period. | |
1022 | |
1023 `comment', where it applies, could mean anything. | |
1024 | |
1025 There are a few more functions available, for locating day and entry | |
1026 lists: | |
1027 | |
1028 timeclock-day-alist LOG-DATA | |
1029 timeclock-project-alist LOG-DATA | |
1030 timeclock-current-debt LOG-DATA | |
1031 | |
1032 See the documentation for the given function if more info is needed." | |
1033 (let* ((log-data (list 0.0 nil nil)) | |
1034 (now (current-time)) | |
1035 (todays-date (timeclock-time-to-date now)) | |
1036 last-date-limited last-date-seconds last-date | |
36851 | 1037 (line 0) last beg day entry event) |
33020 | 1038 (with-temp-buffer |
1039 (insert-file-contents (or filename timeclock-file)) | |
1040 (when recent-only | |
1041 (goto-char (point-max)) | |
1042 (unless (re-search-backward "^b\\s-+" nil t) | |
1043 (goto-char (point-min)))) | |
1044 (while (or (setq event (timeclock-read-moment)) | |
1045 (and beg (not last) | |
1046 (setq last t event (list "o" now)))) | |
1047 (setq line (1+ line)) | |
1048 (cond ((equal (car event) "b") | |
1049 (setcar log-data (string-to-number (nth 2 event)))) | |
1050 ((equal (car event) "h") | |
1051 (setq last-date-limited (timeclock-time-to-date (cadr event)) | |
1052 last-date-seconds (* (string-to-number (nth 2 event)) | |
1053 3600.0))) | |
1054 ((equal (car event) "i") | |
1055 (if beg | |
1056 (error "Error in format of timelog file, line %d" line) | |
1057 (setq beg t)) | |
1058 (setq entry (list (cadr event) nil | |
1059 (and (> (length (nth 2 event)) 0) | |
1060 (nth 2 event)))) | |
1061 (let ((date (timeclock-time-to-date (cadr event)))) | |
1062 (if (and last-date | |
1063 (not (equal date last-date))) | |
36851 | 1064 (progn |
1065 (setcar (cdr log-data) | |
1066 (cons (cons last-date day) | |
1067 (cadr log-data))) | |
1068 (setq day (list (and last-date-limited | |
1069 last-date-seconds)))) | |
1070 (unless day | |
1071 (setq day (list (and last-date-limited | |
1072 last-date-seconds))))) | |
33020 | 1073 (setq last-date date |
1074 last-date-limited nil))) | |
1075 ((equal (downcase (car event)) "o") | |
1076 (if (not beg) | |
1077 (error "Error in format of timelog file, line %d" line) | |
1078 (setq beg nil)) | |
1079 (setcar (cdr entry) (cadr event)) | |
1080 (let ((desc (and (> (length (nth 2 event)) 0) | |
1081 (nth 2 event)))) | |
1082 (if desc | |
1083 (nconc entry (list (nth 2 event)))) | |
1084 (if (equal (car event) "O") | |
1085 (nconc entry (if desc | |
1086 (list t) | |
1087 (list nil t)))) | |
1088 (nconc day (list entry)) | |
1089 (setq desc (nth 2 entry)) | |
1090 (let ((proj (assoc desc (nth 2 log-data)))) | |
36851 | 1091 (if (null proj) |
33020 | 1092 (setcar (cddr log-data) |
1093 (cons (cons desc (list entry)) | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1094 (nth 2 log-data))) |
33020 | 1095 (nconc (cdr proj) (list entry))))))) |
1096 (forward-line)) | |
1097 (if day | |
1098 (setcar (cdr log-data) | |
1099 (cons (cons last-date day) | |
1100 (cadr log-data)))) | |
1101 log-data))) | |
1102 | |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1103 (defun timeclock-find-discrep () |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
1104 "Calculate time discrepancies, in seconds. |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
1105 The result is a three element list, containing the total time |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
1106 discrepancy, today's discrepancy, and the time worked today." |
33020 | 1107 ;; This is not implemented in terms of the functions above, because |
1108 ;; it's a bit wasteful to read all of that data in, just to throw | |
1109 ;; away more than 90% of the information afterwards. | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1110 ;; |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1111 ;; If it were implemented using those functions, it would look |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1112 ;; something like this: |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1113 ;; (let ((days (timeclock-day-alist (timeclock-log-data))) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1114 ;; (total 0.0)) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1115 ;; (while days |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1116 ;; (setq total (+ total (- (timeclock-day-length (cdar days)) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1117 ;; (timeclock-day-required (cdar days)))) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1118 ;; days (cdr days))) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1119 ;; total) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1120 (let* ((now (current-time)) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1121 (todays-date (timeclock-time-to-date now)) |
37648
9baaf32f355a
(timeclock-find-discrep): Initialize `elapsed' to 0.
John Wiegley <johnw@newartisans.com>
parents:
37625
diff
changeset
|
1122 (first t) (accum 0) (elapsed 0) |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1123 event beg last-date avg |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1124 last-date-limited last-date-seconds) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1125 (unless timeclock-discrepancy |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1126 (when (file-readable-p timeclock-file) |
36851 | 1127 (setq timeclock-project-list nil |
1128 timeclock-last-project nil | |
1129 timeclock-reason-list nil | |
1130 timeclock-elapsed 0) | |
1131 (with-temp-buffer | |
1132 (insert-file-contents timeclock-file) | |
1133 (goto-char (point-max)) | |
1134 (unless (re-search-backward "^b\\s-+" nil t) | |
1135 (goto-char (point-min))) | |
1136 (while (setq event (timeclock-read-moment)) | |
1137 (cond ((equal (car event) "b") | |
1138 (setq accum (string-to-number (nth 2 event)))) | |
1139 ((equal (car event) "h") | |
1140 (setq last-date-limited | |
1141 (timeclock-time-to-date (cadr event)) | |
1142 last-date-seconds | |
1143 (* (string-to-number (nth 2 event)) 3600.0))) | |
1144 ((equal (car event) "i") | |
1145 (when (and (nth 2 event) | |
1146 (> (length (nth 2 event)) 0)) | |
1147 (add-to-list 'timeclock-project-list (nth 2 event)) | |
1148 (setq timeclock-last-project (nth 2 event))) | |
1149 (let ((date (timeclock-time-to-date (cadr event)))) | |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1150 (if (if last-date |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1151 (not (equal date last-date)) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1152 first) |
36851 | 1153 (setq first nil |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1154 accum (- accum (if last-date-limited |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1155 last-date-seconds |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1156 timeclock-workday)))) |
36851 | 1157 (setq last-date date |
1158 last-date-limited nil) | |
1159 (if beg | |
1160 (error "Error in format of timelog file!") | |
1161 (setq beg (timeclock-time-to-seconds (cadr event)))))) | |
1162 ((equal (downcase (car event)) "o") | |
1163 (if (and (nth 2 event) | |
30781 | 1164 (> (length (nth 2 event)) 0)) |
36851 | 1165 (add-to-list 'timeclock-reason-list (nth 2 event))) |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1166 (if (not beg) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1167 (error "Error in format of timelog file!") |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1168 (setq timeclock-last-period |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1169 (- (timeclock-time-to-seconds (cadr event)) beg) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1170 accum (+ timeclock-last-period accum) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1171 beg nil)) |
36851 | 1172 (if (equal last-date todays-date) |
1173 (setq timeclock-elapsed | |
1174 (+ timeclock-last-period timeclock-elapsed))))) | |
1175 (setq timeclock-last-event event | |
1176 timeclock-last-event-workday | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1177 (if (equal (timeclock-time-to-date now) last-date-limited) |
36851 | 1178 last-date-seconds |
1179 timeclock-workday)) | |
1180 (forward-line)) | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1181 (setq timeclock-discrepancy accum)))) |
37650
061ef023b0af
(timeclock-find-discrep): Set `timeclock-last-event-workday' if it's
John Wiegley <johnw@newartisans.com>
parents:
37648
diff
changeset
|
1182 (unless timeclock-last-event-workday |
061ef023b0af
(timeclock-find-discrep): Set `timeclock-last-event-workday' if it's
John Wiegley <johnw@newartisans.com>
parents:
37648
diff
changeset
|
1183 (setq timeclock-last-event-workday timeclock-workday)) |
51263 | 1184 (setq accum (or timeclock-discrepancy 0) |
37652
7fb1a7ce4a40
One more variable coming up nil on the first time around, needing
John Wiegley <johnw@newartisans.com>
parents:
37651
diff
changeset
|
1185 elapsed (or timeclock-elapsed elapsed)) |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1186 (if timeclock-last-event |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1187 (if (equal (car timeclock-last-event) "i") |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1188 (let ((last-period (timeclock-last-period now))) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1189 (setq accum (+ accum last-period) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1190 elapsed (+ elapsed last-period))) |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1191 (if (not (equal (timeclock-time-to-date |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1192 (cadr timeclock-last-event)) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1193 (timeclock-time-to-date now))) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1194 (setq accum (- accum timeclock-last-event-workday))))) |
37625
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1195 (list accum (- elapsed timeclock-last-event-workday) |
53351976477e
(timeclock-workday-remaining): Changed logic for determining how much
John Wiegley <johnw@newartisans.com>
parents:
37437
diff
changeset
|
1196 elapsed))) |
36851 | 1197 |
1198 ;;; A reporting function that uses timeclock-log-data | |
1199 | |
1200 (defun timeclock-day-base (&optional time) | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
1201 "Given a time within a day, return 0:0:0 within that day. |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
1202 If optional argument TIME is non-nil, use that instead of the current time." |
36851 | 1203 (let ((decoded (decode-time (or time (current-time))))) |
1204 (setcar (nthcdr 0 decoded) 0) | |
1205 (setcar (nthcdr 1 decoded) 0) | |
1206 (setcar (nthcdr 2 decoded) 0) | |
1207 (apply 'encode-time decoded))) | |
1208 | |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
1209 (defun timeclock-mean (l) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
1210 "Compute the arithmetic mean of the values in the list L." |
36851 | 1211 (let ((total 0) |
1212 (count 0)) | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1213 (dolist (thisl l) |
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1214 (setq total (+ total thisl) |
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1215 count (1+ count))) |
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1216 (if (zerop count) |
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1217 0 |
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1218 (/ total count)))) |
36851 | 1219 |
1220 (defun timeclock-generate-report (&optional html-p) | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
1221 "Generate a summary report based on the current timelog file. |
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
1222 By default, the report is in plain text, but if the optional argument |
54704 | 1223 HTML-P is non-nil, HTML markup is added." |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
1224 (interactive "P") |
36851 | 1225 (let ((log (timeclock-log-data)) |
1226 (today (timeclock-day-base))) | |
1227 (if html-p (insert "<p>")) | |
1228 (insert "Currently ") | |
1229 (let ((project (nth 2 timeclock-last-event)) | |
1230 (begin (nth 1 timeclock-last-event)) | |
1231 done) | |
1232 (if (timeclock-currently-in-p) | |
1233 (insert "IN") | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1234 (if (zerop (length project)) |
36851 | 1235 (progn (insert "Done Working Today") |
1236 (setq done t)) | |
1237 (insert "OUT"))) | |
1238 (unless done | |
1239 (insert " since " (format-time-string "%Y/%m/%d %-I:%M %p" begin)) | |
1240 (if html-p | |
1241 (insert "<br>\n<b>") | |
1242 (insert "\n*")) | |
1243 (if (timeclock-currently-in-p) | |
1244 (insert "Working on ")) | |
1245 (if html-p | |
37282
d30baa39a3b4
(timeclock-generate-report): Added a missing insert of the project
John Wiegley <johnw@newartisans.com>
parents:
36854
diff
changeset
|
1246 (insert project "</b><br>\n") |
36851 | 1247 (insert project "*\n")) |
1248 (let ((proj-data (cdr (assoc project (timeclock-project-alist log)))) | |
1249 (two-weeks-ago (timeclock-seconds-to-time | |
1250 (- (timeclock-time-to-seconds today) | |
1251 (* 2 7 24 60 60)))) | |
1252 two-week-len today-len) | |
1253 (while proj-data | |
55207
a3244da8e396
(timeclock-time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54704
diff
changeset
|
1254 (if (not (time-less-p |
36851 | 1255 (timeclock-entry-begin (car proj-data)) today)) |
1256 (setq today-len (timeclock-entry-list-length proj-data) | |
1257 proj-data nil) | |
1258 (if (and (null two-week-len) | |
55207
a3244da8e396
(timeclock-time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54704
diff
changeset
|
1259 (not (time-less-p |
36851 | 1260 (timeclock-entry-begin (car proj-data)) |
1261 two-weeks-ago))) | |
1262 (setq two-week-len (timeclock-entry-list-length proj-data))) | |
1263 (setq proj-data (cdr proj-data)))) | |
1264 (if (null two-week-len) | |
1265 (setq two-week-len today-len)) | |
1266 (if html-p (insert "<p>")) | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1267 (if today-len |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1268 (insert "\nTime spent on this task today: " |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1269 (timeclock-seconds-to-string today-len) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1270 ". In the last two weeks: " |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1271 (timeclock-seconds-to-string two-week-len)) |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1272 (if two-week-len |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1273 (insert "\nTime spent on this task in the last two weeks: " |
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1274 (timeclock-seconds-to-string two-week-len)))) |
36851 | 1275 (if html-p (insert "<br>")) |
1276 (insert "\n" | |
1277 (timeclock-seconds-to-string (timeclock-workday-elapsed)) | |
1278 " worked today, " | |
1279 (timeclock-seconds-to-string (timeclock-workday-remaining)) | |
1280 " remaining, done at " | |
1281 (timeclock-when-to-leave-string) "\n"))) | |
1282 (if html-p (insert "<p>")) | |
1283 (insert "\nThere have been " | |
1284 (number-to-string | |
1285 (length (timeclock-day-alist log))) | |
1286 " days of activity, starting " | |
1287 (caar (last (timeclock-day-alist log)))) | |
1288 (if html-p (insert "</p>")) | |
1289 (when html-p | |
1290 (insert "<p> | |
1291 <table> | |
1292 <td width=\"25\"><br></td><td> | |
1293 <table border=1 cellpadding=3> | |
1294 <tr><th><i>Statistics</i></th> | |
1295 <th>Entire</th> | |
1296 <th>-30 days</th> | |
1297 <th>-3 mons</th> | |
1298 <th>-6 mons</th> | |
1299 <th>-1 year</th> | |
1300 </tr>") | |
1301 (let* ((day-list (timeclock-day-list)) | |
1302 (thirty-days-ago (timeclock-seconds-to-time | |
1303 (- (timeclock-time-to-seconds today) | |
1304 (* 30 24 60 60)))) | |
1305 (three-months-ago (timeclock-seconds-to-time | |
1306 (- (timeclock-time-to-seconds today) | |
1307 (* 90 24 60 60)))) | |
1308 (six-months-ago (timeclock-seconds-to-time | |
1309 (- (timeclock-time-to-seconds today) | |
1310 (* 180 24 60 60)))) | |
1311 (one-year-ago (timeclock-seconds-to-time | |
1312 (- (timeclock-time-to-seconds today) | |
1313 (* 365 24 60 60)))) | |
1314 (time-in (vector (list t) (list t) (list t) (list t) (list t))) | |
1315 (time-out (vector (list t) (list t) (list t) (list t) (list t))) | |
1316 (breaks (vector (list t) (list t) (list t) (list t) (list t))) | |
1317 (workday (vector (list t) (list t) (list t) (list t) (list t))) | |
1318 (lengths (vector '(0 0) thirty-days-ago three-months-ago | |
1319 six-months-ago one-year-ago))) | |
1320 ;; collect statistics from complete timelog | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1321 (dolist (day day-list) |
36851 | 1322 (let ((i 0) (l 5)) |
1323 (while (< i l) | |
55207
a3244da8e396
(timeclock-time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents:
54704
diff
changeset
|
1324 (unless (time-less-p |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1325 (timeclock-day-begin day) |
36851 | 1326 (aref lengths i)) |
1327 (let ((base (timeclock-time-to-seconds | |
1328 (timeclock-day-base | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1329 (timeclock-day-begin day))))) |
36851 | 1330 (nconc (aref time-in i) |
1331 (list (- (timeclock-time-to-seconds | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1332 (timeclock-day-begin day)) |
36851 | 1333 base))) |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1334 (let ((span (timeclock-day-span day)) |
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1335 (len (timeclock-day-length day)) |
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1336 (req (timeclock-day-required day))) |
36851 | 1337 ;; If the day's actual work length is less than |
1338 ;; 70% of its span, then likely the exit time | |
1339 ;; and break amount are not worthwhile adding to | |
1340 ;; the statistic | |
1341 (when (and (> span 0) | |
1342 (> (/ (float len) (float span)) 0.70)) | |
1343 (nconc (aref time-out i) | |
1344 (list (- (timeclock-time-to-seconds | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1345 (timeclock-day-end day)) |
36851 | 1346 base))) |
1347 (nconc (aref breaks i) (list (- span len)))) | |
1348 (if req | |
1349 (setq len (+ len (- timeclock-workday req)))) | |
1350 (nconc (aref workday i) (list len))))) | |
92957
c3b09ba22de9
(timeclock-time-to-seconds, timeclock-log-data): Use nth.
Glenn Morris <rgm@gnu.org>
parents:
92669
diff
changeset
|
1351 (setq i (1+ i))))) |
36851 | 1352 ;; average statistics |
1353 (let ((i 0) (l 5)) | |
1354 (while (< i l) | |
77900
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
1355 (aset time-in i (timeclock-mean (cdr (aref time-in i)))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
1356 (aset time-out i (timeclock-mean (cdr (aref time-out i)))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
1357 (aset breaks i (timeclock-mean (cdr (aref breaks i)))) |
2e526dc9c6b6
Update version number.
Chong Yidong <cyd@stupidchicken.com>
parents:
77671
diff
changeset
|
1358 (aset workday i (timeclock-mean (cdr (aref workday i)))) |
36851 | 1359 (setq i (1+ i)))) |
1360 ;; Output the HTML table | |
1361 (insert "<tr>\n") | |
1362 (insert "<td align=\"center\">Time in</td>\n") | |
1363 (let ((i 0) (l 5)) | |
1364 (while (< i l) | |
1365 (insert "<td align=\"right\">" | |
1366 (timeclock-seconds-to-string (aref time-in i)) | |
1367 "</td>\n") | |
1368 (setq i (1+ i)))) | |
1369 (insert "</tr>\n") | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1370 |
36851 | 1371 (insert "<tr>\n") |
1372 (insert "<td align=\"center\">Time out</td>\n") | |
1373 (let ((i 0) (l 5)) | |
1374 (while (< i l) | |
1375 (insert "<td align=\"right\">" | |
1376 (timeclock-seconds-to-string (aref time-out i)) | |
1377 "</td>\n") | |
1378 (setq i (1+ i)))) | |
1379 (insert "</tr>\n") | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1380 |
36851 | 1381 (insert "<tr>\n") |
1382 (insert "<td align=\"center\">Break</td>\n") | |
1383 (let ((i 0) (l 5)) | |
1384 (while (< i l) | |
1385 (insert "<td align=\"right\">" | |
1386 (timeclock-seconds-to-string (aref breaks i)) | |
1387 "</td>\n") | |
1388 (setq i (1+ i)))) | |
1389 (insert "</tr>\n") | |
37437
ed485de91fcf
(timeclock-day-required): If the time required for a particular day is
John Wiegley <johnw@newartisans.com>
parents:
37324
diff
changeset
|
1390 |
36851 | 1391 (insert "<tr>\n") |
1392 (insert "<td align=\"center\">Workday</td>\n") | |
1393 (let ((i 0) (l 5)) | |
1394 (while (< i l) | |
1395 (insert "<td align=\"right\">" | |
1396 (timeclock-seconds-to-string (aref workday i)) | |
1397 "</td>\n") | |
1398 (setq i (1+ i)))) | |
1399 (insert "</tr>\n")) | |
1400 (insert "<tfoot> | |
1401 <td colspan=\"6\" align=\"center\"> | |
1402 <i>These are approximate figures</i></td> | |
1403 </tfoot> | |
1404 </table> | |
1405 </td></table>"))))) | |
1406 | |
1407 ;;; A helpful little function | |
1408 | |
1409 (defun timeclock-visit-timelog () | |
51861
91e4e5fd11de
(timeclock-use-display-time, timeclock-day-over-hook)
Glenn Morris <rgm@gnu.org>
parents:
51549
diff
changeset
|
1410 "Open the file named by `timeclock-file' in another window." |
36851 | 1411 (interactive) |
1412 (find-file-other-window timeclock-file)) | |
30781 | 1413 |
1414 (provide 'timeclock) | |
1415 | |
1416 (run-hooks 'timeclock-load-hook) | |
1417 | |
1418 ;; make sure we know the list of reasons, projects, and have computed | |
1419 ;; the last event and current discrepancy. | |
1420 (if (file-readable-p timeclock-file) | |
1421 (timeclock-reread-log)) | |
1422 | |
92600 | 1423 ;; arch-tag: a0be3377-deb6-44ec-b9a2-a7be28436a40 |
30781 | 1424 ;;; timeclock.el ends here |