annotate lisp/calendar/timeclock.el @ 88306:7b65aade5e20

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