annotate lisp/calendar/timeclock.el @ 110263:280c5216180d

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