1 ;;; timeclock.el --- mode for keeping track of how much you work
3 ;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
5 ;; Author: John Wiegley <johnw@gnu.org>
6 ;; Created: 25 Mar 1999
8 ;; Keywords: calendar data
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This mode is for keeping track of time intervals. You can use it
28 ;; for whatever purpose you like, but the typical scenario is to keep
29 ;; track of how much time you spend working on certain projects.
31 ;; Use `timeclock-in' when you start on a project, and `timeclock-out'
32 ;; when you're done. Once you've collected some data, you can use
33 ;; `timeclock-workday-remaining' to see how much time is left to be
34 ;; worked today (where `timeclock-workday' specifies the length of the
35 ;; working day), and `timeclock-when-to-leave' to calculate when you're free.
37 ;; You'll probably want to bind the timeclock commands to some handy
38 ;; keystrokes. At the moment, C-x t is unused:
40 ;; (require 'timeclock)
42 ;; (define-key ctl-x-map "ti" 'timeclock-in)
43 ;; (define-key ctl-x-map "to" 'timeclock-out)
44 ;; (define-key ctl-x-map "tc" 'timeclock-change)
45 ;; (define-key ctl-x-map "tr" 'timeclock-reread-log)
46 ;; (define-key ctl-x-map "tu" 'timeclock-update-mode-line)
47 ;; (define-key ctl-x-map "tw" 'timeclock-when-to-leave-string)
49 ;; If you want Emacs to display the amount of time "left" to your
50 ;; workday in the mode-line, you can either set the value of
51 ;; `timeclock-mode-line-display' to t using M-x customize, or you can
52 ;; add this code to your init file:
54 ;; (require 'timeclock)
55 ;; (timeclock-mode-line-display)
57 ;; To cancel this mode line display at any time, just call
58 ;; `timeclock-mode-line-display' again.
60 ;; You may also want Emacs to ask you before exiting, if you are
61 ;; currently working on a project. This can be done either by setting
62 ;; `timeclock-ask-before-exiting' to t using M-x customize (this is
63 ;; the default), or by adding the following to your init file:
65 ;; (add-hook 'kill-emacs-query-functions 'timeclock-query-out)
67 ;; NOTE: If you change your .timelog file without using timeclock's
68 ;; functions, or if you change the value of any of timeclock's
69 ;; customizable variables, you should run the command
70 ;; `timeclock-reread-log'. This will recompute any discrepancies in
71 ;; your average working time, and will make sure that the various
72 ;; display functions return the correct value.
78 (defgroup timeclock nil
79 "Keeping track of the time that gets spent."
84 (defcustom timeclock-file
(locate-user-emacs-file "timelog" ".timelog")
85 "The file used to store timeclock data in."
89 (defcustom timeclock-workday
(* 8 60 60)
90 "The length of a work period in seconds."
94 (defcustom timeclock-relative t
95 "Whether to make reported time relative to `timeclock-workday'.
96 For example, if the length of a normal workday is eight hours, and you
97 work four hours on Monday, then the amount of time \"remaining\" on
98 Tuesday is twelve hours -- relative to an averaged work period of
99 eight hours -- or eight hours, non-relative. So relative time takes
100 into account any discrepancy of time under-worked or over-worked on
101 previous days. This only affects the timeclock mode line display."
105 (defcustom timeclock-get-project-function
'timeclock-ask-for-project
106 "The function used to determine the name of the current project.
107 When clocking in, and no project is specified, this function will be
108 called to determine what is the current project to be worked on.
109 If this variable is nil, no questions will be asked."
113 (defcustom timeclock-get-reason-function
'timeclock-ask-for-reason
114 "A function used to determine the reason for clocking out.
115 When clocking out, and no reason is specified, this function will be
116 called to determine what is the reason.
117 If this variable is nil, no questions will be asked."
121 (defcustom timeclock-get-workday-function nil
122 "A function used to determine the length of today's workday.
123 The first time that a user clocks in each day, this function will be
124 called to determine what is the length of the current workday. If
125 the return value is nil, or equal to `timeclock-workday', nothing special
126 will be done. If it is a quantity different from `timeclock-workday',
127 however, a record will be output to the timelog file to note the fact that
128 that day has a length that is different from the norm."
129 :type
'(choice (const nil
) function
)
132 (defcustom timeclock-ask-before-exiting t
133 "If non-nil, ask if the user wants to clock out before exiting Emacs.
134 This variable only has effect if set with \\[customize]."
135 :set
(lambda (symbol value
)
137 (add-hook 'kill-emacs-query-functions
'timeclock-query-out
)
138 (remove-hook 'kill-emacs-query-functions
'timeclock-query-out
))
139 (setq timeclock-ask-before-exiting value
))
143 (defvar timeclock-update-timer nil
144 "The timer used to update `timeclock-mode-string'.")
146 ;; For byte-compiler.
147 (defvar display-time-hook
)
148 (defvar timeclock-mode-line-display
)
150 (defcustom timeclock-use-display-time t
151 "If non-nil, use `display-time-hook' for doing mode line updates.
152 The advantage of this is that one less timer has to be set running
153 amok in Emacs's process space. The disadvantage is that it requires
154 you to have `display-time' running. If you don't want to use
155 `display-time', but still want the mode line to show how much time is
156 left, set this variable to nil. Changing the value of this variable
157 while timeclock information is being displayed in the mode line has no
158 effect. You should call the function `timeclock-mode-line-display' with
159 a positive argument to force an update."
160 :set
(lambda (symbol value
)
161 (let ((currently-displaying
162 (and (boundp 'timeclock-mode-line-display
)
163 timeclock-mode-line-display
)))
164 ;; if we're changing to the state that
165 ;; `timeclock-mode-line-display' is already using, don't
166 ;; bother toggling it. This happens on the initial loading
168 (if (and currently-displaying
170 (boundp 'display-time-hook
)
171 (memq 'timeclock-update-mode-line
174 timeclock-update-timer
)))
175 (setq currently-displaying nil
))
176 (and currently-displaying
177 (set-variable 'timeclock-mode-line-display nil
))
178 (setq timeclock-use-display-time value
)
179 (and currently-displaying
180 (set-variable 'timeclock-mode-line-display t
))
181 timeclock-use-display-time
))
186 (defcustom timeclock-first-in-hook nil
187 "A hook run for the first \"in\" event each day.
188 Note that this hook is run before recording any events. Thus the
189 value of `timeclock-hours-today', `timeclock-last-event' and the
190 return value of function `timeclock-last-period' are relative previous
195 (defcustom timeclock-load-hook nil
196 "Hook that gets run after timeclock has been loaded."
200 (defcustom timeclock-in-hook nil
201 "A hook run every time an \"in\" event is recorded."
205 (defcustom timeclock-day-over-hook nil
206 "A hook that is run when the workday has been completed.
207 This hook is only run if the current time remaining is being displayed
208 in the mode line. See the variable `timeclock-mode-line-display'."
212 (defcustom timeclock-out-hook nil
213 "A hook run every time an \"out\" event is recorded."
217 (defcustom timeclock-done-hook nil
218 "A hook run every time a project is marked as completed."
222 (defcustom timeclock-event-hook nil
223 "A hook run every time any event is recorded."
227 (defvar timeclock-last-event nil
228 "A list containing the last event that was recorded.
229 The format of this list is (CODE TIME PROJECT).")
231 (defvar timeclock-last-event-workday nil
232 "The number of seconds in the workday of `timeclock-last-event'.")
234 ;;; Internal Variables:
236 (defvar timeclock-discrepancy nil
237 "A variable containing the time discrepancy before the last event.
238 Normally, timeclock assumes that you intend to work for
239 `timeclock-workday' seconds every day. Any days in which you work
240 more or less than this amount is considered either a positive or
241 a negative discrepancy. If you work in such a manner that the
242 discrepancy is always brought back to zero, then you will by
243 definition have worked an average amount equal to `timeclock-workday'
246 (defvar timeclock-elapsed nil
247 "A variable containing the time elapsed for complete periods today.
248 This value is not accurate enough to be useful by itself. Rather,
249 call `timeclock-workday-elapsed', to determine how much time has been
250 worked so far today. Also, if `timeclock-relative' is nil, this value
251 will be the same as `timeclock-discrepancy'.")
253 (defvar timeclock-use-elapsed nil
254 "Non-nil if the mode line should display time elapsed, not remaining.")
256 (defvar timeclock-last-period nil
257 "Integer representing the number of seconds in the last period.
258 Note that you shouldn't access this value, but instead should use the
259 function `timeclock-last-period'.")
261 (defvar timeclock-mode-string nil
262 "The timeclock string (optionally) displayed in the mode line.
263 The time is bracketed by <> if you are clocked in, otherwise by [].")
265 (defvar timeclock-day-over nil
266 "The date of the last day when notified \"day over\" for.")
270 (define-obsolete-function-alias 'timeclock-modeline-display
271 'timeclock-mode-line-display
"24.3")
274 (defun timeclock-mode-line-display (&optional arg
)
275 "Toggle display of the amount of time left today in the mode line.
276 If `timeclock-use-display-time' is non-nil (the default), then
277 the function `display-time-mode' must be active, and the mode line
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 mode line display on if and only
281 if ARG is positive. Returns the new status of timeclock mode line
282 display (non-nil means on)."
284 ;; cf display-time-mode.
285 (setq timeclock-mode-string
"")
286 (or global-mode-string
(setq global-mode-string
'("")))
288 (> (prefix-numeric-value arg
) 0)
289 (not timeclock-mode-line-display
))))
292 (or (memq 'timeclock-mode-string global-mode-string
)
293 (setq global-mode-string
294 (append global-mode-string
'(timeclock-mode-string))))
295 (add-hook 'timeclock-event-hook
'timeclock-update-mode-line
)
296 (when timeclock-update-timer
297 (cancel-timer timeclock-update-timer
)
298 (setq timeclock-update-timer nil
))
299 (if (boundp 'display-time-hook
)
300 (remove-hook 'display-time-hook
'timeclock-update-mode-line
))
301 (if timeclock-use-display-time
303 ;; Update immediately so there is a visible change
304 ;; on calling this function.
305 (if display-time-mode
306 (timeclock-update-mode-line)
307 (message "Activate `display-time-mode' or turn off \
308 `timeclock-use-display-time' to see timeclock information"))
309 (add-hook 'display-time-hook
'timeclock-update-mode-line
))
310 (setq timeclock-update-timer
311 (run-at-time nil
60 'timeclock-update-mode-line
))))
312 (setq global-mode-string
313 (delq 'timeclock-mode-string global-mode-string
))
314 (remove-hook 'timeclock-event-hook
'timeclock-update-mode-line
)
315 (if (boundp 'display-time-hook
)
316 (remove-hook 'display-time-hook
317 'timeclock-update-mode-line
))
318 (when timeclock-update-timer
319 (cancel-timer timeclock-update-timer
)
320 (setq timeclock-update-timer nil
)))
321 (force-mode-line-update)
322 (setq timeclock-mode-line-display on-p
)))
324 (define-obsolete-variable-alias 'timeclock-modeline-display
325 'timeclock-mode-line-display
"24.3")
327 ;; This has to be here so that the function definition of
328 ;; `timeclock-mode-line-display' is known to the "set" function.
329 (defcustom timeclock-mode-line-display nil
330 "Toggle mode line display of time remaining.
331 You must modify via \\[customize] for this variable to have an effect."
332 :set
(lambda (symbol value
)
333 (setq timeclock-mode-line-display
334 (timeclock-mode-line-display (or value
0))))
339 (defsubst timeclock-time-to-date
(time)
340 "Convert the TIME value to a textual date string."
341 (format-time-string "%Y/%m/%d" time
))
344 (defun timeclock-in (&optional arg project find-project
)
345 "Clock in, recording the current time moment in the timelog.
346 With a numeric prefix ARG, record the fact that today has only that
347 many hours in it to be worked. If ARG is a non-numeric prefix argument
348 \(non-nil, but not a number), 0 is assumed (working on a holiday or
349 weekend). *If not called interactively, ARG should be the number of
350 _seconds_ worked today*. This feature only has effect the first time
351 this function is called within a day.
353 PROJECT is the project being clocked into. If PROJECT is nil, and
354 FIND-PROJECT is non-nil -- or the user calls `timeclock-in'
355 interactively -- call the function `timeclock-get-project-function' to
356 discover the name of the project."
358 (list (and current-prefix-arg
359 (if (numberp current-prefix-arg
)
360 (* current-prefix-arg
60 60)
362 (if (equal (car timeclock-last-event
) "i")
363 (error "You've already clocked in!")
364 (unless timeclock-last-event
365 (timeclock-reread-log))
366 ;; Either no log file, or day has rolled over.
367 (unless (and timeclock-last-event
368 (equal (timeclock-time-to-date
369 (cadr timeclock-last-event
))
370 (timeclock-time-to-date (current-time))))
371 (let ((workday (or (and (numberp arg
) arg
)
373 (and timeclock-get-workday-function
374 (funcall timeclock-get-workday-function
))
376 (run-hooks 'timeclock-first-in-hook
)
377 ;; settle the discrepancy for the new day
378 (setq timeclock-discrepancy
379 (- (or timeclock-discrepancy
0) workday
))
380 (if (not (= workday timeclock-workday
))
381 (timeclock-log "h" (number-to-string
382 (/ workday
(if (zerop (% workday
(* 60 60)))
384 (timeclock-log "i" (or project
385 (and timeclock-get-project-function
387 (called-interactively-p 'interactive
))
388 (funcall timeclock-get-project-function
))))
389 (run-hooks 'timeclock-in-hook
)))
392 (defun timeclock-out (&optional arg reason find-reason
)
393 "Clock out, recording the current time moment in the timelog.
394 If a prefix ARG is given, the user has completed the project that was
395 begun during the last time segment.
397 REASON is the user's reason for clocking out. If REASON is nil, and
398 FIND-REASON is non-nil -- or the user calls `timeclock-out'
399 interactively -- call the function `timeclock-get-reason-function' to
400 discover the reason."
402 (or timeclock-last-event
403 (error "You haven't clocked in!"))
404 (if (equal (downcase (car timeclock-last-event
)) "o")
405 (error "You've already clocked out!")
409 (and timeclock-get-reason-function
410 (or find-reason
(called-interactively-p 'interactive
))
411 (funcall timeclock-get-reason-function
))))
412 (run-hooks 'timeclock-out-hook
)
414 (run-hooks 'timeclock-done-hook
))))
416 ;; Should today-only be removed in favor of timeclock-relative? - gm
417 (defsubst timeclock-workday-remaining
(&optional today-only
)
418 "Return the number of seconds until the workday is complete.
419 The amount returned is relative to the value of `timeclock-workday'.
420 If TODAY-ONLY is non-nil, the value returned will be relative only to
421 the time worked today, and not to past time."
422 (let ((discrep (timeclock-find-discrep)))
424 (- (if today-only
(cadr discrep
)
429 (defun timeclock-status-string (&optional show-seconds today-only
)
430 "Report the overall timeclock status at the present moment.
431 If SHOW-SECONDS is non-nil, display second resolution.
432 If TODAY-ONLY is non-nil, the display will be relative only to time
433 worked today, ignoring the time worked on previous days."
435 (let ((remainder (timeclock-workday-remaining
437 (not timeclock-relative
))))
438 (last-in (equal (car timeclock-last-event
) "i"))
441 (format "Currently %s since %s (%s), %s %s, leave at %s"
442 (if last-in
"IN" "OUT")
444 (format-time-string "%-I:%M:%S %p"
445 (nth 1 timeclock-last-event
))
446 (format-time-string "%-I:%M %p"
447 (nth 1 timeclock-last-event
)))
448 (or (nth 2 timeclock-last-event
)
449 (if last-in
"**UNKNOWN**" "workday over"))
450 (timeclock-seconds-to-string remainder show-seconds t
)
453 (timeclock-when-to-leave-string show-seconds today-only
)))
454 (if (called-interactively-p 'interactive
)
455 (message "%s" status
)
459 (defun timeclock-change (&optional arg project
)
460 "Change to working on a different project.
461 This clocks out of the current project, then clocks in on a new one.
462 With a prefix ARG, consider the previous project as finished at the
463 time of changeover. PROJECT is the name of the last project you were
467 (timeclock-in nil project
(called-interactively-p 'interactive
)))
470 (defun timeclock-query-out ()
471 "Ask the user whether to clock out.
472 This is a useful function for adding to `kill-emacs-query-functions'."
473 (and (equal (car timeclock-last-event
) "i")
474 (y-or-n-p "You're currently clocking time, clock out? ")
476 ;; Unconditionally return t for `kill-emacs-query-functions'.
480 (defun timeclock-reread-log ()
481 "Re-read the timeclock, to account for external changes.
482 Returns the new value of `timeclock-discrepancy'."
484 (setq timeclock-discrepancy nil
)
485 (timeclock-find-discrep)
486 (if (and timeclock-discrepancy timeclock-mode-line-display
)
487 (timeclock-update-mode-line))
488 timeclock-discrepancy
)
490 (defun timeclock-seconds-to-string (seconds &optional show-seconds
492 "Convert SECONDS into a compact time string.
493 If SHOW-SECONDS is non-nil, make the resolution of the return string
494 include the second count. If REVERSE-LEADER is non-nil, it means to
495 output a \"+\" if the time value is negative, rather than a \"-\".
496 This is used when negative time values have an inverted meaning (such
497 as with time remaining, where negative time really means overtime)."
499 (format "%s%d:%02d:%02d"
500 (if (< seconds
0) (if reverse-leader
"+" "-") "")
501 (truncate (/ (abs seconds
) 60 60))
502 (%
(truncate (/ (abs seconds
) 60)) 60)
503 (%
(truncate (abs seconds
)) 60))
505 (if (< seconds
0) (if reverse-leader
"+" "-") "")
506 (truncate (/ (abs seconds
) 60 60))
507 (%
(truncate (/ (abs seconds
) 60)) 60))))
509 (defsubst timeclock-currently-in-p
()
510 "Return non-nil if the user is currently clocked in."
511 (equal (car timeclock-last-event
) "i"))
514 (defun timeclock-workday-remaining-string (&optional show-seconds
516 "Return a string representing the amount of time left today.
517 Display second resolution if SHOW-SECONDS is non-nil. If TODAY-ONLY
518 is non-nil, the display will be relative only to time worked today.
519 See `timeclock-relative' for more information about the meaning of
520 \"relative to today\"."
522 (let ((string (timeclock-seconds-to-string
523 (timeclock-workday-remaining today-only
)
525 (if (called-interactively-p 'interactive
)
526 (message "%s" string
)
529 (defsubst timeclock-workday-elapsed
()
530 "Return the number of seconds worked so far today.
531 If RELATIVE is non-nil, the amount returned will be relative to past
532 time worked. The default is to return only the time that has elapsed
534 (let ((discrep (timeclock-find-discrep)))
540 (defun timeclock-workday-elapsed-string (&optional show-seconds
)
541 "Return a string representing the amount of time worked today.
542 Display seconds resolution if SHOW-SECONDS is non-nil. If RELATIVE is
543 non-nil, the amount returned will be relative to past time worked."
545 (let ((string (timeclock-seconds-to-string (timeclock-workday-elapsed)
547 (if (called-interactively-p 'interactive
)
548 (message "%s" string
)
551 (defalias 'timeclock-time-to-seconds
(if (fboundp 'float-time
) 'float-time
554 (defalias 'timeclock-seconds-to-time
'seconds-to-time
)
556 ;; Should today-only be removed in favor of timeclock-relative? - gm
557 (defsubst timeclock-when-to-leave
(&optional today-only
)
558 "Return a time value representing the end of today's workday.
559 If TODAY-ONLY is non-nil, the value returned will be relative only to
560 the time worked today, and not to past time."
561 (timeclock-seconds-to-time
562 (- (timeclock-time-to-seconds (current-time))
563 (let ((discrep (timeclock-find-discrep)))
571 (defun timeclock-when-to-leave-string (&optional show-seconds
573 "Return a string representing the end of today's workday.
574 This string is relative to the value of `timeclock-workday'. If
575 SHOW-SECONDS is non-nil, the value printed/returned will include
576 seconds. If TODAY-ONLY is non-nil, the value returned will be
577 relative only to the time worked today, and not to past time."
578 ;; Should today-only be removed in favor of timeclock-relative? - gm
580 (let* ((then (timeclock-when-to-leave today-only
))
583 (format-time-string "%-I:%M:%S %p" then
)
584 (format-time-string "%-I:%M %p" then
))))
585 (if (called-interactively-p 'interactive
)
586 (message "%s" string
)
589 (defun timeclock-make-hours-explicit (old-default)
590 "Specify all workday lengths in `timeclock-file'.
591 OLD-DEFAULT hours are set for every day that has no number indicated."
593 (if old-default
(setq old-default
(prefix-numeric-value old-default
))
594 (error "`timelog-make-hours-explicit' requires an explicit argument"))
595 (let ((extant-timelog (find-buffer-visiting timeclock-file
))
597 (with-current-buffer (find-file-noselect timeclock-file t
)
602 (goto-char (point-min))
603 (while (progn (skip-chars-forward "\n") (not (eobp)))
604 ;; This is just a variant of `timeclock-moment-regexp'.
606 (concat "^\\([bhioO]\\) \\([0-9]+/[0-9]+/[0-9]+\\) "
607 "\\([0-9]+:[0-9]+:[0-9]+\\)"))
608 (error "Can't parse `%s'" timeclock-file
))
609 (let ((this-date (match-string 2)))
610 (unless (or (and current-date
611 (string= this-date current-date
))
612 (string= (match-string 1) "h"))
613 (insert (format "h %s %s %s\n" (match-string 2)
614 (match-string 3) old-default
)))
615 (if (string-match "^[ih]" (match-string 1)) ; ignore logouts
616 (setq current-date this-date
)))
619 (unless extant-timelog
(kill-buffer (current-buffer)))))))
621 ;;; Internal Functions:
623 (defvar timeclock-project-list nil
)
624 (defvar timeclock-last-project nil
)
626 (defun timeclock-completing-read (prompt alist
&optional default
)
627 "A version of `completing-read' that works on both Emacs and XEmacs.
628 PROMPT, ALIST and DEFAULT are used for the PROMPT, COLLECTION and DEF
629 arguments of `completing-read'."
630 (if (featurep 'xemacs
)
631 (let ((str (completing-read prompt alist
)))
632 (if (or (null str
) (zerop (length str
)))
635 (completing-read prompt alist nil nil nil nil default
)))
637 (defun timeclock-ask-for-project ()
638 "Ask the user for the project they are clocking into."
639 (timeclock-completing-read
640 (format "Clock into which project (default %s): "
641 (or timeclock-last-project
642 (car timeclock-project-list
)))
643 (mapcar 'list timeclock-project-list
)
644 (or timeclock-last-project
645 (car timeclock-project-list
))))
647 (defvar timeclock-reason-list nil
)
649 (defun timeclock-ask-for-reason ()
650 "Ask the user for the reason they are clocking out."
651 (timeclock-completing-read "Reason for clocking out: "
652 (mapcar 'list timeclock-reason-list
)))
654 (define-obsolete-function-alias 'timeclock-update-modeline
655 'timeclock-update-mode-line
"24.3")
657 (defun timeclock-update-mode-line ()
658 "Update the `timeclock-mode-string' displayed in the mode line.
659 The value of `timeclock-relative' affects the display as described in
660 that variable's documentation."
663 (if timeclock-use-elapsed
664 (timeclock-workday-elapsed)
665 (timeclock-workday-remaining (not timeclock-relative
))))
666 (last-in (equal (car timeclock-last-event
) "i")))
667 (when (and (< remainder
0)
668 (not (and timeclock-day-over
669 (equal timeclock-day-over
670 (timeclock-time-to-date
672 (setq timeclock-day-over
673 (timeclock-time-to-date (current-time)))
674 (run-hooks 'timeclock-day-over-hook
))
675 (setq timeclock-mode-string
679 (timeclock-seconds-to-string remainder nil t
)
681 'help-echo
"timeclock: time remaining"))))
683 (put 'timeclock-mode-string
'risky-local-variable t
)
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
688 being logged for. Normally only \"in\" events specify a project."
689 (let ((extant-timelog (find-buffer-visiting timeclock-file
)))
690 (with-current-buffer (find-file-noselect timeclock-file t
)
694 (goto-char (point-max))
697 (let ((now (current-time)))
699 (format-time-string "%Y/%m/%d %H:%M:%S" now
)
700 (or (and (stringp project
)
701 (> (length project
) 0)
702 (concat " " project
))
705 (if (equal (downcase code
) "o")
706 (setq timeclock-last-period
707 (- (timeclock-time-to-seconds now
)
708 (timeclock-time-to-seconds
709 (cadr timeclock-last-event
)))
710 timeclock-discrepancy
711 (+ timeclock-discrepancy
712 timeclock-last-period
)))
713 (setq timeclock-last-event
(list code now project
)))))
715 (unless extant-timelog
(kill-buffer (current-buffer)))))
716 (run-hooks 'timeclock-event-hook
))
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]*\\)"))
723 (defsubst timeclock-read-moment
()
724 "Read the moment under point from the timelog."
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
))))
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
))
749 (defsubst timeclock-entry-length
(entry)
750 "Return the length of ENTRY in seconds."
751 (- (timeclock-time-to-seconds (cadr entry
))
752 (timeclock-time-to-seconds (car entry
))))
754 (defsubst timeclock-entry-begin
(entry)
755 "Return the start time of ENTRY."
758 (defsubst timeclock-entry-end
(entry)
759 "Return the end time of ENTRY."
762 (defsubst timeclock-entry-project
(entry)
763 "Return the project of ENTRY."
766 (defsubst timeclock-entry-comment
(entry)
767 "Return the comment of ENTRY."
770 (defsubst timeclock-entry-list-length
(entry-list)
771 "Return the total length of ENTRY-LIST in seconds."
773 (dolist (entry entry-list
)
774 (setq length
(+ length
(timeclock-entry-length entry
))))
777 (defsubst timeclock-entry-list-begin
(entry-list)
778 "Return the start time of the first element of ENTRY-LIST."
779 (timeclock-entry-begin (car entry-list
)))
781 (defsubst timeclock-entry-list-end
(entry-list)
782 "Return the end time of the last element of ENTRY-LIST."
783 (timeclock-entry-end (car (last entry-list
))))
785 (defsubst timeclock-entry-list-span
(entry-list)
786 "Return the total time in seconds spanned by ENTRY-LIST."
787 (- (timeclock-time-to-seconds (timeclock-entry-list-end entry-list
))
788 (timeclock-time-to-seconds (timeclock-entry-list-begin entry-list
))))
790 (defsubst timeclock-entry-list-break
(entry-list)
791 "Return the total break time (span - length) in ENTRY-LIST."
792 (- (timeclock-entry-list-span entry-list
)
793 (timeclock-entry-list-length entry-list
)))
795 (defsubst timeclock-entry-list-projects
(entry-list)
796 "Return a list of all the projects in ENTRY-LIST."
798 (dolist (entry entry-list
)
799 (setq proj
(timeclock-entry-project entry
))
801 (add-to-list 'projects proj
)
802 (setq projects
(list proj
))))
805 (defsubst timeclock-day-required
(day)
806 "Return the required length of DAY in seconds, default `timeclock-workday'."
807 (or (car day
) timeclock-workday
))
809 (defsubst timeclock-day-length
(day)
810 "Return the actual length of DAY in seconds."
811 (timeclock-entry-list-length (cdr day
)))
813 (defsubst timeclock-day-debt
(day)
814 "Return the debt (required - actual) associated with DAY, in seconds."
815 (- (timeclock-day-required day
)
816 (timeclock-day-length day
)))
818 (defsubst timeclock-day-begin
(day)
819 "Return the start time of DAY."
820 (timeclock-entry-list-begin (cdr day
)))
822 (defsubst timeclock-day-end
(day)
823 "Return the end time of DAY."
824 (timeclock-entry-list-end (cdr day
)))
826 (defsubst timeclock-day-span
(day)
827 "Return the span of DAY."
828 (timeclock-entry-list-span (cdr day
)))
830 (defsubst timeclock-day-break
(day)
831 "Return the total break time of DAY."
832 (timeclock-entry-list-break (cdr day
)))
834 (defsubst timeclock-day-projects
(day)
835 "Return a list of all the projects in DAY."
836 (timeclock-entry-list-projects (cddr day
)))
838 (defmacro timeclock-day-list-template
(func)
839 "Template for summing the result of FUNC on each element of DAY-LIST."
842 (setq length
(+ length
(,(eval func
) (car day-list
)))
843 day-list
(cdr day-list
)))
846 (defun timeclock-day-list-required (day-list)
847 "Return total required length of DAY-LIST, in seconds."
848 (timeclock-day-list-template 'timeclock-day-required
))
850 (defun timeclock-day-list-length (day-list)
851 "Return actual length of DAY-LIST, in seconds."
852 (timeclock-day-list-template 'timeclock-day-length
))
854 (defun timeclock-day-list-debt (day-list)
855 "Return total debt (required - actual) of DAY-LIST."
856 (timeclock-day-list-template 'timeclock-day-debt
))
858 (defsubst timeclock-day-list-begin
(day-list)
859 "Return the start time of DAY-LIST."
860 (timeclock-day-begin (car day-list
)))
862 (defsubst timeclock-day-list-end
(day-list)
863 "Return the end time of DAY-LIST."
864 (timeclock-day-end (car (last day-list
))))
866 (defun timeclock-day-list-span (day-list)
867 "Return the span of DAY-LIST."
868 (timeclock-day-list-template 'timeclock-day-span
))
870 (defun timeclock-day-list-break (day-list)
871 "Return the total break of DAY-LIST."
872 (timeclock-day-list-template 'timeclock-day-break
))
874 (defun timeclock-day-list-projects (day-list)
875 "Return a list of all the projects in DAY-LIST."
877 (dolist (day day-list
)
878 (dolist (proj (timeclock-day-projects day
))
880 (add-to-list 'projects proj
)
881 (setq projects
(list proj
)))))
884 (defsubst timeclock-current-debt
(&optional log-data
)
885 "Return the seconds debt from LOG-DATA, default `timeclock-log-data'."
886 (nth 0 (or log-data
(timeclock-log-data))))
888 (defsubst timeclock-day-alist
(&optional log-data
)
889 "Return the date alist from LOG-DATA, default `timeclock-log-data'."
890 (nth 1 (or log-data
(timeclock-log-data))))
892 (defun timeclock-day-list (&optional log-data
)
893 "Return a list of the cdrs of the date alist from LOG-DATA."
895 (dolist (date-list (timeclock-day-alist log-data
))
896 (setq day-list
(cons (cdr date-list
) day-list
)))
899 (defsubst timeclock-project-alist
(&optional log-data
)
900 "Return the project alist from LOG-DATA, default `timeclock-log-data'."
901 (nth 2 (or log-data
(timeclock-log-data))))
903 (defun timeclock-log-data (&optional recent-only filename
)
904 "Return the contents of the timelog file, in a useful format.
905 If the optional argument RECENT-ONLY is non-nil, only show the contents
906 from the last point where the time debt (see below) was set.
907 If the optional argument FILENAME is non-nil, it is used instead of
908 the file specified by `timeclock-file.'
910 A timelog contains data in the form of a single entry per line.
911 Each entry has the form:
913 CODE YYYY/MM/DD HH:MM:SS [COMMENT]
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:
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.
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
924 the number of hours in this workday. Floating point amounts
927 i Clock in. The COMMENT in this case should be the name of the
930 o Clock out. COMMENT is unnecessary, but can be used to provide
931 a description of how the period went, for example.
933 O Final clock out. Whatever project was being worked on, it is
934 now finished. Useful for creating summary reports.
936 When this function is called, it will return a data structure with the
939 (DEBT ENTRIES-BY-DAY ENTRIES-BY-PROJECT)
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.
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.
951 The CDR for ENTRIES-BY-DAY is slightly different than for
952 ENTRIES-BY-PROJECT. It has the following form:
954 (DAY-LENGTH TIME-ENTRIES...)
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.
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):
964 (BEGIN-TIME END-TIME PROJECT [COMMENT] [FINAL-P])
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
971 timeclock-day-required
978 timeclock-day-projects
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
989 timeclock-entry-length
990 timeclock-entry-begin
992 timeclock-entry-project
993 timeclock-entry-comment
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
1002 A few comments should make the use of the above functions obvious:
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.
1007 `length' is the actual amount of time that was spent.
1009 `debt' is the difference between required time and length. A
1010 negative debt signifies overtime.
1012 `begin' is the earliest moment at which work began.
1014 `end' is the final moment work was done.
1016 `span' is the difference between begin and end.
1018 `break' is the difference between span and length.
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.
1023 `comment', where it applies, could mean anything.
1025 There are a few more functions available, for locating day and entry
1028 timeclock-day-alist LOG-DATA
1029 timeclock-project-alist LOG-DATA
1030 timeclock-current-debt LOG-DATA
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 last-date-limited last-date-seconds last-date
1036 (line 0) last beg day entry event
)
1038 (insert-file-contents (or filename timeclock-file
))
1040 (goto-char (point-max))
1041 (unless (re-search-backward "^b\\s-+" nil t
)
1042 (goto-char (point-min))))
1043 (while (or (setq event
(timeclock-read-moment))
1045 (setq last t event
(list "o" now
))))
1046 (setq line
(1+ line
))
1047 (cond ((equal (car event
) "b")
1048 (setcar log-data
(string-to-number (nth 2 event
))))
1049 ((equal (car event
) "h")
1050 (setq last-date-limited
(timeclock-time-to-date (cadr event
))
1051 last-date-seconds
(* (string-to-number (nth 2 event
))
1053 ((equal (car event
) "i")
1055 (error "Error in format of timelog file, line %d" line
)
1057 (setq entry
(list (cadr event
) nil
1058 (and (> (length (nth 2 event
)) 0)
1060 (let ((date (timeclock-time-to-date (cadr event
))))
1062 (not (equal date last-date
)))
1064 (setcar (cdr log-data
)
1065 (cons (cons last-date day
)
1067 (setq day
(list (and last-date-limited
1068 last-date-seconds
))))
1070 (setq day
(list (and last-date-limited
1071 last-date-seconds
)))))
1072 (setq last-date date
1073 last-date-limited nil
)))
1074 ((equal (downcase (car event
)) "o")
1076 (error "Error in format of timelog file, line %d" line
)
1078 (setcar (cdr entry
) (cadr event
))
1079 (let ((desc (and (> (length (nth 2 event
)) 0)
1082 (nconc entry
(list (nth 2 event
))))
1083 (if (equal (car event
) "O")
1084 (nconc entry
(if desc
1087 (nconc day
(list entry
))
1088 (setq desc
(nth 2 entry
))
1089 (let ((proj (assoc desc
(nth 2 log-data
))))
1091 (setcar (cddr log-data
)
1092 (cons (cons desc
(list entry
))
1094 (nconc (cdr proj
) (list entry
)))))))
1097 (setcar (cdr log-data
)
1098 (cons (cons last-date day
)
1102 (defun timeclock-find-discrep ()
1103 "Calculate time discrepancies, in seconds.
1104 The result is a three element list, containing the total time
1105 discrepancy, today's discrepancy, and the time worked today."
1106 ;; This is not implemented in terms of the functions above, because
1107 ;; it's a bit wasteful to read all of that data in, just to throw
1108 ;; away more than 90% of the information afterwards.
1110 ;; If it were implemented using those functions, it would look
1111 ;; something like this:
1112 ;; (let ((days (timeclock-day-alist (timeclock-log-data)))
1115 ;; (setq total (+ total (- (timeclock-day-length (cdar days))
1116 ;; (timeclock-day-required (cdar days))))
1117 ;; days (cdr days)))
1119 (let* ((now (current-time))
1120 (todays-date (timeclock-time-to-date now
))
1121 (first t
) (accum 0) (elapsed 0)
1123 last-date-limited last-date-seconds
)
1124 (unless timeclock-discrepancy
1125 (when (file-readable-p timeclock-file
)
1126 (setq timeclock-project-list nil
1127 timeclock-last-project nil
1128 timeclock-reason-list nil
1129 timeclock-elapsed
0)
1131 (insert-file-contents timeclock-file
)
1132 (goto-char (point-max))
1133 (unless (re-search-backward "^b\\s-+" nil t
)
1134 (goto-char (point-min)))
1135 (while (setq event
(timeclock-read-moment))
1136 (cond ((equal (car event
) "b")
1137 (setq accum
(string-to-number (nth 2 event
))))
1138 ((equal (car event
) "h")
1139 (setq last-date-limited
1140 (timeclock-time-to-date (cadr event
))
1142 (* (string-to-number (nth 2 event
)) 3600.0)))
1143 ((equal (car event
) "i")
1144 (when (and (nth 2 event
)
1145 (> (length (nth 2 event
)) 0))
1146 (add-to-list 'timeclock-project-list
(nth 2 event
))
1147 (setq timeclock-last-project
(nth 2 event
)))
1148 (let ((date (timeclock-time-to-date (cadr event
))))
1150 (not (equal date last-date
))
1153 accum
(- accum
(if last-date-limited
1155 timeclock-workday
))))
1156 (setq last-date date
1157 last-date-limited nil
)
1159 (error "Error in format of timelog file!")
1160 (setq beg
(timeclock-time-to-seconds (cadr event
))))))
1161 ((equal (downcase (car event
)) "o")
1162 (if (and (nth 2 event
)
1163 (> (length (nth 2 event
)) 0))
1164 (add-to-list 'timeclock-reason-list
(nth 2 event
)))
1166 (error "Error in format of timelog file!")
1167 (setq timeclock-last-period
1168 (- (timeclock-time-to-seconds (cadr event
)) beg
)
1169 accum
(+ timeclock-last-period accum
)
1171 (if (equal last-date todays-date
)
1172 (setq timeclock-elapsed
1173 (+ timeclock-last-period timeclock-elapsed
)))))
1174 (setq timeclock-last-event event
1175 timeclock-last-event-workday
1176 (if (equal (timeclock-time-to-date now
) last-date-limited
)
1180 (setq timeclock-discrepancy accum
))))
1181 (unless timeclock-last-event-workday
1182 (setq timeclock-last-event-workday timeclock-workday
))
1183 (setq accum
(or timeclock-discrepancy
0)
1184 elapsed
(or timeclock-elapsed elapsed
))
1185 (if timeclock-last-event
1186 (if (equal (car timeclock-last-event
) "i")
1187 (let ((last-period (timeclock-last-period now
)))
1188 (setq accum
(+ accum last-period
)
1189 elapsed
(+ elapsed last-period
)))
1190 (if (not (equal (timeclock-time-to-date
1191 (cadr timeclock-last-event
))
1192 (timeclock-time-to-date now
)))
1193 (setq accum
(- accum timeclock-last-event-workday
)))))
1194 (list accum
(- elapsed timeclock-last-event-workday
)
1197 ;;; A reporting function that uses timeclock-log-data
1199 (defun timeclock-day-base (&optional time
)
1200 "Given a time within a day, return 0:0:0 within that day.
1201 If optional argument TIME is non-nil, use that instead of the current time."
1202 (let ((decoded (decode-time (or time
(current-time)))))
1203 (setcar (nthcdr 0 decoded
) 0)
1204 (setcar (nthcdr 1 decoded
) 0)
1205 (setcar (nthcdr 2 decoded
) 0)
1206 (apply 'encode-time decoded
)))
1208 (defun timeclock-mean (l)
1209 "Compute the arithmetic mean of the values in the list L."
1213 (setq total
(+ total thisl
)
1219 (defun timeclock-generate-report (&optional html-p
)
1220 "Generate a summary report based on the current timelog file.
1221 By default, the report is in plain text, but if the optional argument
1222 HTML-P is non-nil, HTML markup is added."
1224 (let ((log (timeclock-log-data))
1225 (today (timeclock-day-base)))
1226 (if html-p
(insert "<p>"))
1227 (insert "Currently ")
1228 (let ((project (nth 2 timeclock-last-event
))
1229 (begin (nth 1 timeclock-last-event
))
1231 (if (timeclock-currently-in-p)
1233 (if (zerop (length project
))
1234 (progn (insert "Done Working Today")
1238 (insert " since " (format-time-string "%Y/%m/%d %-I:%M %p" begin
))
1240 (insert "<br>\n<b>")
1242 (if (timeclock-currently-in-p)
1243 (insert "Working on "))
1245 (insert project
"</b><br>\n")
1246 (insert project
"*\n"))
1247 (let ((proj-data (cdr (assoc project
(timeclock-project-alist log
))))
1248 (two-weeks-ago (timeclock-seconds-to-time
1249 (- (timeclock-time-to-seconds today
)
1251 two-week-len today-len
)
1253 (if (not (time-less-p
1254 (timeclock-entry-begin (car proj-data
)) today
))
1255 (setq today-len
(timeclock-entry-list-length proj-data
)
1257 (if (and (null two-week-len
)
1259 (timeclock-entry-begin (car proj-data
))
1261 (setq two-week-len
(timeclock-entry-list-length proj-data
)))
1262 (setq proj-data
(cdr proj-data
))))
1263 (if (null two-week-len
)
1264 (setq two-week-len today-len
))
1265 (if html-p
(insert "<p>"))
1267 (insert "\nTime spent on this task today: "
1268 (timeclock-seconds-to-string today-len
)
1269 ". In the last two weeks: "
1270 (timeclock-seconds-to-string two-week-len
))
1272 (insert "\nTime spent on this task in the last two weeks: "
1273 (timeclock-seconds-to-string two-week-len
))))
1274 (if html-p
(insert "<br>"))
1276 (timeclock-seconds-to-string (timeclock-workday-elapsed))
1278 (timeclock-seconds-to-string (timeclock-workday-remaining))
1279 " remaining, done at "
1280 (timeclock-when-to-leave-string) "\n")))
1281 (if html-p
(insert "<p>"))
1282 (insert "\nThere have been "
1284 (length (timeclock-day-alist log
)))
1285 " days of activity, starting "
1286 (caar (last (timeclock-day-alist log
))))
1287 (if html-p
(insert "</p>"))
1291 <td width=\"25\"><br></td><td>
1292 <table border=1 cellpadding=3>
1293 <tr><th><i>Statistics</i></th>
1300 (let* ((day-list (timeclock-day-list))
1301 (thirty-days-ago (timeclock-seconds-to-time
1302 (- (timeclock-time-to-seconds today
)
1304 (three-months-ago (timeclock-seconds-to-time
1305 (- (timeclock-time-to-seconds today
)
1307 (six-months-ago (timeclock-seconds-to-time
1308 (- (timeclock-time-to-seconds today
)
1310 (one-year-ago (timeclock-seconds-to-time
1311 (- (timeclock-time-to-seconds today
)
1313 (time-in (vector (list t
) (list t
) (list t
) (list t
) (list t
)))
1314 (time-out (vector (list t
) (list t
) (list t
) (list t
) (list t
)))
1315 (breaks (vector (list t
) (list t
) (list t
) (list t
) (list t
)))
1316 (workday (vector (list t
) (list t
) (list t
) (list t
) (list t
)))
1317 (lengths (vector '(0 0) thirty-days-ago three-months-ago
1318 six-months-ago one-year-ago
)))
1319 ;; collect statistics from complete timelog
1320 (dolist (day day-list
)
1323 (unless (time-less-p
1324 (timeclock-day-begin day
)
1326 (let ((base (timeclock-time-to-seconds
1328 (timeclock-day-begin day
)))))
1329 (nconc (aref time-in i
)
1330 (list (- (timeclock-time-to-seconds
1331 (timeclock-day-begin day
))
1333 (let ((span (timeclock-day-span day
))
1334 (len (timeclock-day-length day
))
1335 (req (timeclock-day-required day
)))
1336 ;; If the day's actual work length is less than
1337 ;; 70% of its span, then likely the exit time
1338 ;; and break amount are not worthwhile adding to
1340 (when (and (> span
0)
1341 (> (/ (float len
) (float span
)) 0.70))
1342 (nconc (aref time-out i
)
1343 (list (- (timeclock-time-to-seconds
1344 (timeclock-day-end day
))
1346 (nconc (aref breaks i
) (list (- span len
))))
1348 (setq len
(+ len
(- timeclock-workday req
))))
1349 (nconc (aref workday i
) (list len
)))))
1351 ;; average statistics
1354 (aset time-in i
(timeclock-mean (cdr (aref time-in i
))))
1355 (aset time-out i
(timeclock-mean (cdr (aref time-out i
))))
1356 (aset breaks i
(timeclock-mean (cdr (aref breaks i
))))
1357 (aset workday i
(timeclock-mean (cdr (aref workday i
))))
1359 ;; Output the HTML table
1361 (insert "<td align=\"center\">Time in</td>\n")
1364 (insert "<td align=\"right\">"
1365 (timeclock-seconds-to-string (aref time-in i
))
1371 (insert "<td align=\"center\">Time out</td>\n")
1374 (insert "<td align=\"right\">"
1375 (timeclock-seconds-to-string (aref time-out i
))
1381 (insert "<td align=\"center\">Break</td>\n")
1384 (insert "<td align=\"right\">"
1385 (timeclock-seconds-to-string (aref breaks i
))
1391 (insert "<td align=\"center\">Workday</td>\n")
1394 (insert "<td align=\"right\">"
1395 (timeclock-seconds-to-string (aref workday i
))
1400 <td colspan=\"6\" align=\"center\">
1401 <i>These are approximate figures</i></td>
1406 ;;; A helpful little function
1408 (defun timeclock-visit-timelog ()
1409 "Open the file named by `timeclock-file' in another window."
1411 (find-file-other-window timeclock-file
))
1413 (provide 'timeclock
)
1415 (run-hooks 'timeclock-load-hook
)
1417 ;; make sure we know the list of reasons, projects, and have computed
1418 ;; the last event and current discrepancy.
1419 (if (file-readable-p timeclock-file
)
1420 (timeclock-reread-log))
1422 ;;; timeclock.el ends here