annotate lisp/calendar/timeclock.el @ 36085:0b84ec0dc628

Fix problems confusing authors.el.
author Dave Love <fx@gnu.org>
date Wed, 14 Feb 2001 20:23:45 +0000
parents e21feeab77fb
children 9dc1ae87ded3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; timeclock.el --- mode for keeping track of how much you work
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: John Wiegley <johnw@gnu.org>
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Created: 25 Mar 1999
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
7 ;; Version: 2.3
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; Keywords: calendar data
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; any later version.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; This mode is for keeping track of time intervals. You can use it
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; for whatever purpose you like, but the typical scenario is to keep
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; track of how much time you spend working on certain projects.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; Use `timeclock-in' when you start on a project, and `timeclock-out'
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;; when you're done. Once you've collected some data, you can use
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; `timeclock-workday-remaining' to see how much time is left to be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; worked today (assuming a typical average of 8 hours a day), and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; `timeclock-when-to-leave' which will calculate when you're free.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; You'll probably want to bind the timeclock commands to some handy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; keystrokes. At the moment, C-x t is unused in Emacs 20:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; (require 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; (define-key ctl-x-map "ti" 'timeclock-in)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; (define-key ctl-x-map "to" 'timeclock-out)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; (define-key ctl-x-map "tc" 'timeclock-change)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; (define-key ctl-x-map "tr" 'timeclock-reread-log)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; (define-key ctl-x-map "tu" 'timeclock-update-modeline)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; (define-key ctl-x-map "tw" 'timeclock-when-to-leave-string)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; If you want Emacs to display the amount of time "left" to your
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; workday in the modeline, you can either set the value of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; `timeclock-modeline-display' to t using M-x customize, or you
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; can add this code to your .emacs file:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;; (require 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; (timeclock-modeline-display)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; To cancel this modeline display at any time, just call
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; `timeclock-modeline-display' again.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; You may also want Emacs to ask you before exiting, if you are
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; current working on a project. This can be done either by setting
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; `timeclock-ask-before-exiting' to t using M-x customize (this is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; the default), or by adding the following to your .emacs file:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; (add-hook 'kill-emacs-hook 'timeclock-query-out)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; NOTE: If you change your .timelog file without using timeclock's
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; functions, or if you change the value of any of timeclock's
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;; customizable variables, you should run the command
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;; `timeclock-reread-log'. This will recompute any discrepancies in
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; your average working time, and will make sure that the various
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; display functions return the correct value.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;;; History:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;;; Code:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 (defgroup timeclock nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 "Keeping track time of the time that gets spent."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 :group 'data)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;;; User Variables:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85
30795
5b4027fef808 (timeclock-file): Run .timelog through convert-standard-filename.
Eli Zaretskii <eliz@gnu.org>
parents: 30781
diff changeset
86 (defcustom timeclock-file (convert-standard-filename "~/.timelog")
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 "*The file used to store timeclock data in."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 :type 'file
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 (defcustom timeclock-workday (* 8 60 60)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 "*The length of a work period."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 :type 'integer
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 (defcustom timeclock-relative t
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 "*When reporting time, make it relative to `timeclock-workday'?
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 For example, if the length of a normal workday is eight hours, and you
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 work four hours on Monday, then the amount of time \"remaining\" on
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 Tuesday is twelve hours -- relative to an averaged work period of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 eight hours -- or eight hours, non-relative. So relative time takes
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 into account any discrepancy of time under-worked or overworked on
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 previous days."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 :type 'boolean
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (defcustom timeclock-get-project-function 'timeclock-ask-for-project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 "*The function used to determine the name of the current project.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 When clocking in, and no project is specified, this function will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 called to determine what the current project to be worked on is.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 If this variable is nil, no questions will be asked."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 :type 'function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (defcustom timeclock-get-reason-function 'timeclock-ask-for-reason
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 "*A function used to determine the reason for clocking out.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 When clocking out, and no reason is specified, this function will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 called to determine what the reason is.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 If this variable is nil, no questions will be asked."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 :type 'function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 (defcustom timeclock-get-workday-function nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 "*A function used to determine the length of today's workday.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 The first time that a user clocks in each day, this function will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 called to determine what the length of the current workday is. If
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 nil, or equal to `timeclock-workday', nothing special will be done.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 If it is a quantity different from `timeclock-workday', however, a
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 record will be output to the timelog file to note the fact that that
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 day has a different length from the norm."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 :type 'function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (defcustom timeclock-ask-before-exiting t
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 "*If non-nil, ask if the user wants to clock out before exiting Emacs."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 :set (lambda (symbol value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (if value
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (add-hook 'kill-emacs-hook 'timeclock-query-out)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (remove-hook 'kill-emacs-hook 'timeclock-query-out))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (setq timeclock-ask-before-exiting value))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 :type 'boolean
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (defvar timeclock-update-timer nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 "The timer used to update `timeclock-mode-string'.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (defcustom timeclock-use-display-time t
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 "*If non-nil, use `display-time-hook' for doing modeline updates.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 The advantage to this is that it means one less timer has to be set
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 running amok in Emacs' process space. The disadvantage is that it
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 requires you to have `display-time' running. If you don't want to use
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 `display-time', but still want the modeline to show how much time is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 left, set this variable to nil. You will need to restart Emacs (or
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 toggle the value of `timeclock-modeline-display') for the change to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 take effect."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 :set (lambda (symbol value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (let ((currently-displaying
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (and (boundp 'timeclock-modeline-display)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 timeclock-modeline-display)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 ;; if we're changing to the state that
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 ;; `timeclock-modeline-display' is already using, don't
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 ;; bother toggling it. This happens on the initial loading
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 ;; of timeclock.el.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (if (and currently-displaying
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (or (and value
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (boundp 'display-time-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (memq 'timeclock-update-modeline
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 display-time-hook))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (and (not value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 timeclock-update-timer)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (setq currently-displaying nil))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (and currently-displaying
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (set-variable timeclock-modeline-display nil))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (setq timeclock-use-display-time value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (and currently-displaying
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (set-variable timeclock-modeline-display t))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 timeclock-use-display-time))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 :type 'boolean
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 :group 'timeclock
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 :require 'time)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (defcustom timeclock-first-in-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 "*A hook run for the first \"in\" event each day.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 Note that this hook is run before recording any events. Thus the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 value of `timeclock-hours-today', `timeclock-last-event' and the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 return value of function `timeclock-last-period' are relative previous
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 to today."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (defcustom timeclock-load-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 "*Hook that gets run after timeclock has been loaded."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (defcustom timeclock-in-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 "*A hook run every time an \"in\" event is recorded."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (defcustom timeclock-day-over-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 "*A hook that is run when the workday has been completed.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 This hook is only run if the current time remaining is being display
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 in the modeline. See the variable `timeclock-modeline-display'."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (defcustom timeclock-out-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 "*A hook run every time an \"out\" event is recorded."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (defcustom timeclock-done-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 "*A hook run every time a project is marked as completed."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (defcustom timeclock-event-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 "*A hook run every time any event is recorded."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (defvar timeclock-last-event nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 "A list containing the last event that was recorded.
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
225 The format of this list is (CODE TIME PROJECT).")
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (defvar timeclock-last-event-workday nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 "The number of seconds in the workday of `timeclock-last-event'.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 ;;; Internal Variables:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (defvar timeclock-discrepancy nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 "A variable containing the time discrepancy before the last event.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 Normally, timeclock assumes that you intend to work for
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 `timeclock-workday' seconds every day. Any days in which you work
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 more or less than this amount is considered either a positive or
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 negative discrepancy. If you work in such a manner that the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 discrepancy is always brought back to zero, then you will by
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 definition have worked an average amount equal to `timeclock-workday'
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 each day.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 (defvar timeclock-elapsed nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 "A variable containing the time elapsed for complete periods today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 This value is not accurate enough to be useful by itself. Rather,
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 call `timeclock-workday-elapsed', to determine how much time has been
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 worked so far today. Also, if `timeclock-relative' is nil, this value
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 will be the same as `timeclock-discrepancy'.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (defvar timeclock-last-period nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 "Integer representing the number of seconds in the last period.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 Note that you shouldn't access this value, but should use the function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 `timeclock-last-period' instead.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 (defvar timeclock-mode-string nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 "The timeclock string (optionally) displayed in the modeline.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (defvar timeclock-day-over nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 "The date of the last day when notified \"day over\" for.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 ;;; User Functions:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (defun timeclock-modeline-display (&optional arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 "Toggle display of the amount of time left today in the modeline.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 If `timeclock-use-display-time' is non-nil, the modeline will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 updated whenever the time display is updated. Otherwise, the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 timeclock will use its own sixty second timer to do its updating.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 With prefix ARG, turn modeline display on if and only if ARG is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 positive. Returns the new status of timeclock modeline display
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 \(non-nil means on)."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (interactive "P")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (let ((on-p (if arg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (> (prefix-numeric-value arg) 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (not timeclock-modeline-display))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (if on-p
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (let ((list-entry (memq 'global-mode-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 mode-line-format)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (unless (memq 'timeclock-mode-string mode-line-format)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 (setcdr list-entry
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (cons 'timeclock-mode-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (cdr list-entry))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (unless (memq 'timeclock-update-modeline timeclock-event-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (add-hook 'timeclock-event-hook 'timeclock-update-modeline))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (when timeclock-update-timer
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (cancel-timer timeclock-update-timer)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (setq timeclock-update-timer nil))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 (if (boundp 'display-time-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (remove-hook 'display-time-hook 'timeclock-update-modeline))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (if timeclock-use-display-time
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (add-hook 'display-time-hook 'timeclock-update-modeline)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (setq timeclock-update-timer
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (run-at-time nil 60 'timeclock-update-modeline))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (setq mode-line-format
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (delq 'timeclock-mode-string mode-line-format))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (remove-hook 'timeclock-event-hook 'timeclock-update-modeline)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 (if (boundp 'display-time-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (remove-hook 'display-time-hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 'timeclock-update-modeline))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (when timeclock-update-timer
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (cancel-timer timeclock-update-timer)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 (setq timeclock-update-timer nil)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (force-mode-line-update)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 on-p))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 ;; This has to be here so that the function definition of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 ;; `timeclock-modeline-display' is known to the "set" function.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 (defcustom timeclock-modeline-display nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 "Toggle modeline display of time remaining.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 You must modify via \\[customize] for this variable to have an effect."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 :set (lambda (symbol value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 (setq timeclock-modeline-display
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 (timeclock-modeline-display (or value 0))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 :type 'boolean
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 :group 'timeclock
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 :require 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (defun timeclock-in (&optional arg project find-project)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 "Clock in, recording the current time moment in the timelog.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 With a numeric prefix ARG, record the fact that today has only that
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 many hours in it to be worked. If arg is a non-numeric prefix arg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 \(non-nil, but not a number), 0 is assumed (working on a holiday or
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 weekend). *If not called interactively, ARG should be the number of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 _seconds_ worked today*. This feature only has effect the first time
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 this function is called within a day.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 PROJECT as the project being clocked into. If PROJECT is nil, and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 FIND-PROJECT is non-nil -- or the user calls `timeclock-in'
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 interactively -- call the function `timeclock-get-project-function' to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 discover the name of the project."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (interactive
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 (list (and current-prefix-arg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (if (numberp current-prefix-arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (* current-prefix-arg 60 60)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 0))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (if (equal (car timeclock-last-event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (error "You've already clocked in!")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (unless timeclock-last-event
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (timeclock-reread-log))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (unless (equal (timeclock-time-to-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 (cadr timeclock-last-event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (timeclock-time-to-date (current-time)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (let ((workday (or (and (numberp arg) arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 (and arg 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (and timeclock-get-workday-function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (funcall timeclock-get-workday-function))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 timeclock-workday)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (run-hooks 'timeclock-first-in-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 ;; settle the discrepancy for the new day
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (setq timeclock-discrepancy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (- timeclock-discrepancy workday))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 (if (not (= workday timeclock-workday))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (timeclock-log "h" (and (numberp arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (number-to-string arg))))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (timeclock-log "i" (or project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (and timeclock-get-project-function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 (or find-project (interactive-p))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 (funcall timeclock-get-project-function))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (run-hooks 'timeclock-in-hook)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 (defun timeclock-out (&optional arg reason find-reason)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 "Clock out, recording the current time moment in the timelog.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 If a prefix ARG is given, the user has completed the project that was
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 begun during the last time segment.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 REASON is the user's reason for clocking out. If REASON is nil, and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 FIND-REASON is non-nil -- or the user calls `timeclock-out'
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 interactively -- call the function `timeclock-get-reason-function' to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 discover the reason."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 (interactive "P")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (if (equal (downcase (car timeclock-last-event)) "o")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (error "You've already clocked out!")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 (timeclock-log
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 (if arg "O" "o")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 (or reason
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (and timeclock-get-reason-function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 (or find-reason (interactive-p))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (funcall timeclock-get-reason-function))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 (run-hooks 'timeclock-out-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (if arg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (run-hooks 'timeclock-done-hook))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (defun timeclock-status-string (&optional show-seconds today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 "Report the overall timeclock status at the present moment."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (interactive "P")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (let* ((remainder (timeclock-workday-remaining))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (last-in (equal (car timeclock-last-event) "i"))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 status)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (setq status
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (format "Currently %s since %s (%s), %s %s, leave at %s"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 (if last-in "IN" "OUT")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (if show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (format-time-string "%-I:%M:%S %p"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (nth 1 timeclock-last-event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (format-time-string "%-I:%M %p"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (nth 1 timeclock-last-event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 (or (nth 2 timeclock-last-event)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (if last-in "**UNKNOWN**" "workday over"))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (timeclock-seconds-to-string remainder show-seconds t)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (if (> remainder 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 "remaining" "over")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (timeclock-when-to-leave-string show-seconds today-only)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (if (interactive-p)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (message status)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 status)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (defun timeclock-change (&optional arg project)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 "Change to working on a different project, by clocking in then out.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 With a prefix ARG, consider the previous project as having been
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 finished at the time of changeover. PROJECT is the name of the last
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 project you were working on."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (interactive "P")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (timeclock-out arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (timeclock-in nil project (interactive-p)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 (defun timeclock-query-out ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 "Ask the user before clocking out.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 This is a useful function for adding to `kill-emacs-hook'."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 (if (and (equal (car timeclock-last-event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 (y-or-n-p "You're currently clocking time, clock out? "))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 (timeclock-out)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (defun timeclock-reread-log ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 "Re-read the timeclock, to account for external changes.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 Returns the new value of `timeclock-discrepancy'."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (setq timeclock-discrepancy nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (timeclock-find-discrep)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (if timeclock-modeline-display
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (timeclock-update-modeline))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 timeclock-discrepancy)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (defun timeclock-seconds-to-string (seconds &optional show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 reverse-leader)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 "Convert SECONDS into a compact time string.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 If SHOW-SECONDS is non-nil, make the resolution of the return string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 include the second count. If REVERSE-LEADER is non-nil, it means to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 output a \"+\" if the time value is negative, rather than a \"-\".
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 This is used when negative time values have an inverted meaning (such
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 as with time remaining, where negative time really means overtime)."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (if show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 (format "%s%d:%02d:%02d"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (if (< seconds 0) (if reverse-leader "+" "-") "")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (truncate (/ (abs seconds) 60 60))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (% (truncate (/ (abs seconds) 60)) 60)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 (% (truncate (abs seconds)) 60))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (format "%s%d:%02d"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 (if (< seconds 0) (if reverse-leader "+" "-") "")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (truncate (/ (abs seconds) 60 60))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (% (truncate (/ (abs seconds) 60)) 60))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
457 (defsubst timeclock-workday-remaining (&optional today-only)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 "Return a the number of seconds until the workday is complete.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 The amount returned is relative to the value of `timeclock-workday'.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 If TODAY-ONLY is non-nil, the value returned will be relative only to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 the time worked today, and not to past time. This argument only makes
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 a difference if `timeclock-relative' is non-nil."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 (- (timeclock-find-discrep today-only)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
465 (defsubst timeclock-currently-in-p ()
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 "Return non-nil if the user is currently clocked in."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 (equal (car timeclock-last-event) "i"))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 (defun timeclock-workday-remaining-string (&optional show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 "Return a string representing the amount of time left today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 Display second resolution if SHOW-SECONDS is non-nil. If TODAY-ONLY
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 is non-nil, the display will be relative only to time worked today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 See `timeclock-relative' for more information about the meaning of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 \"relative to today\"."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (let ((string (timeclock-seconds-to-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (timeclock-workday-remaining today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 show-seconds t)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (if (interactive-p)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (message string)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 string)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
485 (defsubst timeclock-workday-elapsed (&optional relative)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 "Return a the number of seconds worked so far today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 If RELATIVE is non-nil, the amount returned will be relative to past
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 time worked. The default is to return only the time that has elapsed
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 so far today."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 (+ timeclock-workday
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (timeclock-find-discrep (not relative))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 (defun timeclock-workday-elapsed-string (&optional show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 relative)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 "Return a string representing the amount of time worked today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 Display seconds resolution if SHOW-SECONDS is non-nil. If RELATIVE is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 non-nil, the amount returned will be relative to past time worked."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (let ((string (timeclock-seconds-to-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (timeclock-workday-elapsed relative)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 show-seconds)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 (if (interactive-p)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 (message string)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 string)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
507 (defsubst timeclock-when-to-leave (&optional today-only)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 "Return a time value representing at when the workday ends today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 If TODAY-ONLY is non-nil, the value returned will be relative only to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 the time worked today, and not to past time. This argument only makes
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 a difference if `timeclock-relative' is non-nil."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 (timeclock-seconds-to-time
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (- (timeclock-time-to-seconds (current-time))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 (timeclock-find-discrep today-only))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 (defun timeclock-when-to-leave-string (&optional show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 "Return a string representing at what time the workday ends today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 This string is relative to the value of `timeclock-workday'. If
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521 NO-MESSAGE is non-nil, no messages will be displayed in the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 minibuffer. If SHOW-SECONDS is non-nil, the value printed/returned
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 will include seconds. If TODAY-ONLY is non-nil, the value returned
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 will be relative only to the time worked today, and not to past time.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 This argument only makes a difference if `timeclock-relative' is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 non-nil."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (let* ((then (timeclock-when-to-leave today-only))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 (string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 (if show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 (format-time-string "%-I:%M:%S %p" then)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 (format-time-string "%-I:%M %p" then))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 (if (interactive-p)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (message string)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 string)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 ;;; Internal Functions:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539 (defvar timeclock-project-list nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (defvar timeclock-last-project nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
542 (defun timeclock-ask-for-project ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543 "Ask the user for the project they are clocking into."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 (completing-read (format "Clock into which project (default \"%s\"): "
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 (or timeclock-last-project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 (car timeclock-project-list)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (mapcar 'list timeclock-project-list)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 nil nil nil nil (or timeclock-last-project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 (car timeclock-project-list))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 (defvar timeclock-reason-list nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (defun timeclock-ask-for-reason ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 "Ask the user for the reason they are clocking out."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (completing-read "Reason for clocking out: "
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 (mapcar 'list timeclock-reason-list)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558 (defun timeclock-update-modeline ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559 "Update the `timeclock-mode-string' displayed in the modeline."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 (let* ((remainder (timeclock-workday-remaining))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 (last-in (equal (car timeclock-last-event) "i")))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 (when (and (< remainder 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564 (not (and timeclock-day-over
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 (equal timeclock-day-over
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 (timeclock-time-to-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 (current-time))))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 (setq timeclock-day-over
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 (timeclock-time-to-date (current-time)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570 (run-hooks 'timeclock-day-over-hook))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571 (setq timeclock-mode-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 (format " %c%s%c"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 (if last-in ?< ?[)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 (timeclock-seconds-to-string remainder nil t)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 (if last-in ?> ?])))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (defun timeclock-log (code &optional project)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 "Log the event CODE to the timeclock log, at the time of call.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 If PROJECT is a string, it represents the project which the event is
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
580 being logged for. Normally only \"in\" events specify a project."
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
581 (with-current-buffer (find-file-noselect timeclock-file)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 (goto-char (point-max))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 (if (not (bolp))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 (insert "\n"))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (let ((now (current-time)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 (insert code " "
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (format-time-string "%Y/%m/%d %H:%M:%S" now)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 (or (and project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 (stringp project)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 (> (length project) 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 (concat " " project))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 "")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 "\n")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (if (equal (downcase code) "o")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 (setq timeclock-last-period
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (- (timeclock-time-to-seconds now)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (timeclock-time-to-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (cadr timeclock-last-event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 timeclock-discrepancy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (+ timeclock-discrepancy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 timeclock-last-period)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (setq timeclock-last-event (list code now project)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603 (save-buffer)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
604 (run-hooks 'timeclock-event-hook)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
605 (kill-buffer (current-buffer))))
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
607 (defvar timeclock-moment-regexp
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
608 (concat "\\([bhioO]\\)\\s-+"
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
609 "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)\\s-+"
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
610 "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)[ \t]*" "\\([^\n]*\\)"))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
611
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
612 (defsubst timeclock-read-moment ()
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 "Read the moment under point from the timelog."
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
614 (if (looking-at timeclock-moment-regexp)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
615 (let ((code (match-string 1))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
616 (year (string-to-number (match-string 2)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
617 (mon (string-to-number (match-string 3)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
618 (mday (string-to-number (match-string 4)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
619 (hour (string-to-number (match-string 5)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
620 (min (string-to-number (match-string 6)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
621 (sec (string-to-number (match-string 7)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
622 (project (match-string 8)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
623 (list code (encode-time sec min hour mday mon year) project))))
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
625 (defsubst timeclock-time-to-seconds (time)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 "Convert TIME to a floating point number."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627 (+ (* (car time) 65536.0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 (cadr time)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629 (/ (or (car (cdr (cdr time))) 0) 1000000.0)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
631 (defsubst timeclock-seconds-to-time (seconds)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632 "Convert SECONDS (a floating point number) to an Emacs time structure."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 (list (floor seconds 65536)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 (floor (mod seconds 65536))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 (floor (* (- seconds (ffloor seconds)) 1000000))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
637 (defsubst timeclock-time-to-date (time)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 "Convert the TIME value to a textual date string."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639 (format-time-string "%Y/%m/%d" time))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641 (defun timeclock-last-period (&optional moment)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 "Return the value of the last event period.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 If the last event was a clock-in, the period will be open ended, and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644 growing every second. Otherwise, it is a fixed amount which has been
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 recorded to disk. If MOMENT is non-nil, use that as the current time.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 This is only provided for coherency when used by
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 `timeclock-discrepancy'."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 (if (equal (car timeclock-last-event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649 (- (timeclock-time-to-seconds (or moment (current-time)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 (timeclock-time-to-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 (cadr timeclock-last-event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652 timeclock-last-period))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
654 (defsubst timeclock-entry-length (entry)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
655 (- (timeclock-time-to-seconds (cadr entry))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
656 (timeclock-time-to-seconds (car entry))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
657
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
658 (defsubst timeclock-entry-begin (entry)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
659 (car entry))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
660
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
661 (defsubst timeclock-entry-end (entry)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
662 (cadr entry))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
663
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
664 (defsubst timeclock-entry-project (entry)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
665 (nth 2 entry))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
666
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
667 (defsubst timeclock-entry-comment (entry)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
668 (nth 3 entry))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
669
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
670
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
671 (defsubst timeclock-entry-list-length (entry-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
672 (let ((length 0))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
673 (while entry-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
674 (setq length (+ length (timeclock-entry-length (car entry-list))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
675 (setq entry-list (cdr entry-list)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
676 length))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
677
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
678 (defsubst timeclock-entry-list-begin (entry-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
679 (timeclock-entry-begin (car entry-list)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
680
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
681 (defsubst timeclock-entry-list-end (entry-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
682 (timeclock-entry-end (car (last entry-list))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
683
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
684 (defsubst timeclock-entry-list-span (entry-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
685 (- (timeclock-time-to-seconds (timeclock-entry-list-end entry-list))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
686 (timeclock-time-to-seconds (timeclock-entry-list-begin entry-list))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
687
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
688 (defsubst timeclock-entry-list-break (entry-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
689 (- (timeclock-entry-list-span entry-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
690 (timeclock-entry-list-length entry-list)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
691
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
692 (defsubst timeclock-entry-list-projects (entry-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
693 (let (projects)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
694 (while entry-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
695 (let ((project (timeclock-entry-project (car entry-list))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
696 (if projects
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
697 (add-to-list 'projects project)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
698 (setq projects (list project))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
699 (setq entry-list (cdr entry-list)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
700 projects))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
701
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
702
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
703 (defsubst timeclock-day-required (day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
704 (car day))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
705
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
706 (defsubst timeclock-day-length (day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
707 (timeclock-entry-list-length (cdr day)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
708
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
709 (defsubst timeclock-day-debt (day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
710 (- (timeclock-day-required day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
711 (timeclock-day-length day)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
712
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
713 (defsubst timeclock-day-begin (day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
714 (timeclock-entry-list-begin (cdr day)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
715
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
716 (defsubst timeclock-day-end (day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
717 (timeclock-entry-list-end (cdr day)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
718
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
719 (defsubst timeclock-day-span (day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
720 (timeclock-entry-list-span (cdr day)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
721
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
722 (defsubst timeclock-day-break (day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
723 (timeclock-entry-list-break (cdr day)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
724
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
725 (defsubst timeclock-day-projects (day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
726 (timeclock-entry-list-projects (cdr day)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
727
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
728 (defmacro timeclock-day-list-template (func)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
729 `(let ((length 0))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
730 (while day-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
731 (setq length (+ length (,(eval func) (car day-list))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
732 (setq day-list (cdr day-list)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
733 length))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
734
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
735 (defun timeclock-day-list-required (day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
736 (timeclock-day-list-template 'timeclock-day-required))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
737
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
738 (defun timeclock-day-list-length (day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
739 (timeclock-day-list-template 'timeclock-day-length))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
740
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
741 (defun timeclock-day-list-debt (day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
742 (timeclock-day-list-template 'timeclock-day-debt))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
743
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
744 (defsubst timeclock-day-list-begin (day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
745 (timeclock-day-begin (car day-list)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
746
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
747 (defsubst timeclock-day-list-end (day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
748 (timeclock-day-end (car (last day-list))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
749
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
750 (defun timeclock-day-list-span (day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
751 (timeclock-day-list-template 'timeclock-day-span))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
752
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
753 (defun timeclock-day-list-break (day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
754 (timeclock-day-list-template 'timeclock-day-break))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
755
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
756 (defun timeclock-day-list-projects (day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
757 (let (projects)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
758 (while day-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
759 (let ((projs (timeclock-day-projects (car day-list))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
760 (while projs
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
761 (if projects
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
762 (add-to-list 'projects (car projs))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
763 (setq projects (list (car projs))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
764 (setq projs (cdr projs))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
765 (setq day-list (cdr day-list)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
766 projects))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
767
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
768
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
769 (defsubst timeclock-current-debt (&optional log-data)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
770 (nth 0 (or log-data (timeclock-log-data))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
771
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
772 (defsubst timeclock-day-alist (&optional log-data)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
773 (nth 1 (or log-data (timeclock-log-data))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
774
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
775 (defun timeclock-day-list (&optional log-data)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
776 (let ((alist (timeclock-day-alist log-data))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
777 day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
778 (while alist
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
779 (setq day-list (cons (cdar alist) day-list)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
780 alist (cdr alist)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
781 day-list))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
782
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
783 (defsubst timeclock-project-alist (&optional log-data)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
784 (nth 2 (or log-data (timeclock-log-data))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
785
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
786
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
787 (defun timeclock-log-data (&optional recent-only filename)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
788 "Return the contents of the timelog file, in a useful format.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
789 A timelog contains data in the form of a single entry per line.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
790 Each entry has the form:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
791
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
792 CODE YYYY/MM/DD HH:MM:SS [COMMENT]
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
793
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
794 CODE is one of: b, h, i, o or O. COMMENT is optional when the code is
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
795 i, o or O. The meanings of the codes are:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
796
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
797 b Set the current time balance, or \"time debt\". Useful when
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
798 archiving old log data, when a debt must be carried forward.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
799 The COMMENT here is the number of seconds of debt.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
800
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
801 h Set the required working time for the given day. This must
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
802 be the first entry for that day. The COMMENT in this case is
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
803 the number of hours that must be worked. Floating point
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
804 amounts are allowed.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
805
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
806 i Clock in. The COMMENT in this case should be the name of the
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
807 project worked on.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
808
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
809 o Clock out. COMMENT is unnecessary, but can be used to provide
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
810 a description of how the period went, for example.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
811
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
812 O Final clock out. Whatever project was being worked on, it is
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
813 now finished. Useful for creating summary reports.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
814
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
815 When this function is called, it will return a data structure with the
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
816 following format:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
817
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
818 (DEBT ENTRIES-BY-DAY ENTRIES-BY-PROJECT)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
819
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
820 DEBT is a floating point number representing the number of seconds
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
821 \"owed\" before any work was done. For a new file (one without a 'b'
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
822 entry), this is always zero.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
823
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
824 The two entries lists have similar formats. They are both alists,
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
825 where the CAR is the index, and the CDR is a list of time entries.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
826 For ENTRIES-BY-DAY, the CAR is a textual date string, of the form
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
827 YYYY/MM/DD. For ENTRIES-BY-PROJECT, it is the name of the project
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
828 worked on, or t for the default project.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
829
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
830 The CDR for ENTRIES-BY-DAY is slightly different than for
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
831 ENTRIES-BY-PROJECT. It has the following form:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
832
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
833 (DAY-LENGTH TIME-ENTRIES...)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
834
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
835 For ENTRIES-BY-PROJECT, there is no DAY-LENGTH member. It is simply a
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
836 list of TIME-ENTRIES. Note that if DAY-LENGTH is nil, it means
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
837 whatever is the default should be used.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
838
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
839 A TIME-ENTRY is a recorded time interval. It has the following format
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
840 \(although generally one does not have to manipulate these entries
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
841 directly; see below):
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
842
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
843 (BEGIN-TIME END-TIME PROJECT [COMMENT] [FINAL-P])
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
844
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
845 Anyway, suffice it to say there are a lot of structures. Typically
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
846 the user is expected to manipulate to the day(s) or project(s) that he
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
847 or she wants, at which point the following helper functions may be
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
848 used:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
849
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
850 timeclock-day-required
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
851 timeclock-day-length
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
852 timeclock-day-debt
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
853 timeclock-day-begin
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
854 timeclock-day-end
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
855 timeclock-day-span
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
856 timeclock-day-break
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
857 timeclock-day-projects
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
858
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
859 timeclock-day-list-required
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
860 timeclock-day-list-length
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
861 timeclock-day-list-debt
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
862 timeclock-day-list-begin
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
863 timeclock-day-list-end
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
864 timeclock-day-list-span
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
865 timeclock-day-list-break
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
866 timeclock-day-list-projects
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
867
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
868 timeclock-entry-length
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
869 timeclock-entry-begin
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
870 timeclock-entry-end
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
871 timeclock-entry-project
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
872 timeclock-entry-comment
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
873
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
874 timeclock-entry-list-length
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
875 timeclock-entry-list-begin
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
876 timeclock-entry-list-end
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
877 timeclock-entry-list-span
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
878 timeclock-entry-list-break
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
879 timeclock-entry-list-projects
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
880
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
881 A few comments should make the use of the above functions obvious:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
882
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
883 `required' is the amount of time that must be spent during a day, or
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
884 sequence of days, in order to have no debt.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
885
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
886 `length' is the actual amount of time that was spent.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
887
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
888 `debt' is the difference between required time and length. A
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
889 negative debt signifies overtime.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
890
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
891 `begin' is the earliest moment at which work began.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
892
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
893 `end' is the final moment work was done.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
894
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
895 `span' is the difference between begin and end.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
896
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
897 `break' is the difference between span and length.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
898
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
899 `project' is the project that was worked on, and `projects' is a
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
900 list of all the projects that were worked on during a given period.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
901
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
902 `comment', where it applies, could mean anything.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
903
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
904 There are a few more functions available, for locating day and entry
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
905 lists:
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
906
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
907 timeclock-day-alist LOG-DATA
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
908 timeclock-project-alist LOG-DATA
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
909 timeclock-current-debt LOG-DATA
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
910
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
911 See the documentation for the given function if more info is needed."
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
912 (let* ((log-data (list 0.0 nil nil))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
913 (now (current-time))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
914 (todays-date (timeclock-time-to-date now))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
915 last-date-limited last-date-seconds last-date
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
916 (line 0) last beg day entry)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
917 (with-temp-buffer
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
918 (insert-file-contents (or filename timeclock-file))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
919 (when recent-only
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
920 (goto-char (point-max))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
921 (unless (re-search-backward "^b\\s-+" nil t)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
922 (goto-char (point-min))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
923 (while (or (setq event (timeclock-read-moment))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
924 (and beg (not last)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
925 (setq last t event (list "o" now))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
926 (setq line (1+ line))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
927 (cond ((equal (car event) "b")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
928 (setcar log-data (string-to-number (nth 2 event))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
929 ((equal (car event) "h")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
930 (setq last-date-limited (timeclock-time-to-date (cadr event))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
931 last-date-seconds (* (string-to-number (nth 2 event))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
932 3600.0)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
933 ((equal (car event) "i")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
934 (if beg
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
935 (error "Error in format of timelog file, line %d" line)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
936 (setq beg t))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
937 (setq entry (list (cadr event) nil
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
938 (and (> (length (nth 2 event)) 0)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
939 (nth 2 event))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
940 (let ((date (timeclock-time-to-date (cadr event))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
941 (if (and last-date
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
942 (not (equal date last-date)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
943 (setcar (cdr log-data)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
944 (cons (cons last-date day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
945 (cadr log-data)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
946 (setq day (list (and last-date-limited
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
947 last-date-seconds))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
948 (setq last-date date
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
949 last-date-limited nil)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
950 ((equal (downcase (car event)) "o")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
951 (if (not beg)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
952 (error "Error in format of timelog file, line %d" line)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
953 (setq beg nil))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
954 (setcar (cdr entry) (cadr event))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
955 (let ((desc (and (> (length (nth 2 event)) 0)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
956 (nth 2 event))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
957 (if desc
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
958 (nconc entry (list (nth 2 event))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
959 (if (equal (car event) "O")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
960 (nconc entry (if desc
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
961 (list t)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
962 (list nil t))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
963 (nconc day (list entry))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
964 (setq desc (nth 2 entry))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
965 (let ((proj (assoc desc (nth 2 log-data))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
966 (if (not proj)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
967 (setcar (cddr log-data)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
968 (cons (cons desc (list entry))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
969 (car (cddr log-data))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
970 (nconc (cdr proj) (list entry)))))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
971 (forward-line))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
972 (if day
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
973 (setcar (cdr log-data)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
974 (cons (cons last-date day)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
975 (cadr log-data))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
976 log-data)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
977
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
978 (defun timeclock-find-discrep (&optional today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
979 "Find overall discrepancy from `timeclock-workday' (in seconds).
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
980 If TODAY-ONLY is non-nil, the discrepancy will be not be relative, and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
981 will correspond only to the amount of time elapsed today. This is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
982 identical to what would be return if `timeclock-relative' were nil."
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
983 ;; This is not implemented in terms of the functions above, because
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
984 ;; it's a bit wasteful to read all of that data in, just to throw
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
985 ;; away more than 90% of the information afterwards.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
986 (let* ((now (current-time))
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
987 (todays-date (timeclock-time-to-date now))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
988 (first t) (accum 0)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
989 event beg last-date avg
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
990 last-date-limited last-date-seconds)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
991 (unless timeclock-discrepancy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
992 (setq timeclock-project-list nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
993 timeclock-last-project nil
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
994 timeclock-reason-list nil
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
995 timeclock-elapsed 0)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
996 (with-temp-buffer
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
997 (insert-file-contents timeclock-file)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
998 (goto-char (point-max))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
999 (unless (re-search-backward "^b\\s-+" nil t)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1000 (goto-char (point-min)))
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1001 (while (setq event (timeclock-read-moment))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1002 (cond ((equal (car event) "b")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1003 (setq accum (string-to-number (nth 2 event))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1004 ((equal (car event) "h")
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1005 (setq last-date-limited
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1006 (timeclock-time-to-date (cadr event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1007 last-date-seconds
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1008 (* (string-to-number (nth 2 event)) 3600.0)))
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1009 ((equal (car event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1010 (when (and (nth 2 event)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1011 (> (length (nth 2 event)) 0))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1012 (add-to-list 'timeclock-project-list (nth 2 event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1013 (setq timeclock-last-project (nth 2 event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1014 (let ((date (timeclock-time-to-date (cadr event))))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1015 (if (and timeclock-relative
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1016 (if last-date
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1017 (not (equal date last-date))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1018 first))
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1019 (setq first nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1020 accum (- accum
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1021 (if last-date-limited
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1022 last-date-seconds
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1023 timeclock-workday))))
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1024 (setq last-date date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1025 last-date-limited nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1026 (if beg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1027 (error "Error in format of timelog file!")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1028 (setq beg (timeclock-time-to-seconds (cadr event))))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1029 ((equal (downcase (car event)) "o")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1030 (if (and (nth 2 event)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1031 (> (length (nth 2 event)) 0))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1032 (add-to-list 'timeclock-reason-list (nth 2 event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1033 (if (or timeclock-relative
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1034 (equal last-date todays-date))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1035 (if (not beg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1036 (error "Error in format of timelog file!")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1037 (setq timeclock-last-period
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32451
diff changeset
1038 (- (timeclock-time-to-seconds (cadr event)) beg)
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1039 accum (+ timeclock-last-period accum)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1040 beg nil)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1041 (if (equal last-date todays-date)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1042 (setq timeclock-elapsed
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1043 (+ timeclock-last-period timeclock-elapsed)))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1044 (setq timeclock-last-event event
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1045 timeclock-last-event-workday
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1046 (if (equal (timeclock-time-to-date now)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1047 last-date-limited)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1048 last-date-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1049 timeclock-workday))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1050 (forward-line))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1051 (setq timeclock-discrepancy accum)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1052 (setq accum (if today-only
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1053 timeclock-elapsed
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1054 timeclock-discrepancy))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1055 (if timeclock-last-event
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1056 (if (equal (car timeclock-last-event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1057 (setq accum (+ accum (timeclock-last-period now)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1058 (if (not (equal (timeclock-time-to-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1059 (cadr timeclock-last-event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1060 (timeclock-time-to-date now)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1061 (setq accum (- accum timeclock-last-event-workday)))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1062 (setq accum
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1063 (- accum
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1064 (if (and timeclock-last-event
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1065 (equal (timeclock-time-to-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1066 (cadr timeclock-last-event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1067 (timeclock-time-to-date now)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1068 timeclock-last-event-workday
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1069 timeclock-workday)))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1070
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1071 (provide 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1072
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1073 (run-hooks 'timeclock-load-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1074
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1075 ;; make sure we know the list of reasons, projects, and have computed
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1076 ;; the last event and current discrepancy.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1077 (if (file-readable-p timeclock-file)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1078 (timeclock-reread-log))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1079
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1080 ;;; timeclock.el ends here