-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtotaltime.xml
218 lines (194 loc) · 6.76 KB
/
totaltime.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Weekly Time Totals">
<Optional feature="google.calendar-0.5"/>
<Optional feature="google.calendar-0.5.read"/>
</ModulePrefs>
<Content type="html"><![CDATA[
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<body style="font-size:10pt; font-face: Verdana;">
<script>
function eventInArray(a, eventTitle)
{
for(title in a) {
if (title == eventTitle) {
return true;
}
}
return false;
}
// {year: 2010, month: 1, date: 3, hour: 0, minute: 0, second: 0}
function getTimeDiffInHours(start, end)
{
// only count events that occur within this week...
var length = 0;
// TODO: for now just assume events go on in <= 1 day
if(end.hour == 0)
end.hour = 24;
length += end.hour - start.hour;
if(length > 0)
{
// check for 1 less than hour
if(end.minute < start.minute)
{
length -= 1;
length += (60 + (end.minute - start.minute)) / 60;
} else {
length += (end.minute - start.minute) / 60;
}
} else {
length = (end.minute - start.minute) / 60;
}
return length;
}
function eventCallback(response) {
var my_events = new Array();
var my_event_days = new Array();
//var out1 = '';
//for(prop in response)
//{
// out1 += prop + " value: " + response[prop] + '\n';
//}
//alert(out1);
var events = response[0]['events'];
var out = '';
for(var i = 0; i < events.length; ++i) {
var e = events[i];
if ('title' in e) {
var time_length = getTimeDiffInHours(e.startTime, e.endTime);
//(e.endTime['hour'] - e.startTime['hour'])
if(eventInArray(my_events, e.title)) {
my_events[e.title] += time_length;
} else {
my_events[e.title] = time_length;
my_event_days[e.title] = e.startTime.date;
}
}
}
var c = document.getElementById("myCustomContainer");
var x = document.createElement("TABLE");
x.setAttribute("id", "weeklyTotalTable");
x.setAttribute("style", "table-layout: fixed; border-collapse: collapse; width: 100%; max-width: 140px; border: 0px");
c.appendChild(x);
var i = 0;
var currentDayOfMonth = 0;
var totalHoursForDay = 0;
var grandTotal = 0;
for(title in my_events) {
if (currentDayOfMonth == 0)
currentDayOfMonth = my_event_days[title];
if (currentDayOfMonth != my_event_days[title])
{
var y = document.createElement("TR");
y.setAttribute("id", "weekly_row_" + i);
y.setAttribute("style", "background-color: #444; color: white;");
document.getElementById("weeklyTotalTable").appendChild(y);
var z = document.createElement("TD");
z.setAttribute("style", "width: 78px; overflow: hidden; white-space: nowrap;");
var t = document.createTextNode("Total for " + currentDayOfMonth);
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
z = document.createElement("TD");
z.setAttribute("style", "width: 29px; overflow: hidden; white-space: nowrap;");
t = document.createTextNode(" ");
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
z = document.createElement("TD");
z.setAttribute("style", "width: 29px; overflow: hidden; white-space: nowrap;");
t = document.createTextNode(totalHoursForDay.toFixed(2));
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
i++;
currentDayOfMonth = my_event_days[title];
totalHoursForDay = 0;
}
var num = my_events[title];
totalHoursForDay += num;
grandTotal += num;
var y = document.createElement("TR");
y.setAttribute("id", "weekly_row_" + i);
document.getElementById("weeklyTotalTable").appendChild(y);
var z = document.createElement("TD");
z.setAttribute("style", "width: 78px; overflow: hidden; white-space: nowrap;");
var t = document.createTextNode(title);
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
z = document.createElement("TD");
z.setAttribute("style", "width: 29px; overflow: hidden; white-space: nowrap;");
t = document.createTextNode(num.toFixed(2));
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
z = document.createElement("TD");
z.setAttribute("style", "width: 29px; overflow: hidden; white-space: nowrap;");
t = document.createTextNode(" ");
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
i++;
}
var y = document.createElement("TR");
y.setAttribute("id", "weekly_row_" + i);
y.setAttribute("style", "background-color: #444; color: white;");
document.getElementById("weeklyTotalTable").appendChild(y);
var z = document.createElement("TD");
z.setAttribute("style", "width: 78px; overflow: hidden; white-space: nowrap;");
var t = document.createTextNode("Weekly Total");
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
z = document.createElement("TD");
z.setAttribute("style", "width: 29px; overflow: hidden; white-space: nowrap;");
t = document.createTextNode(" ");
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
z = document.createElement("TD");
z.setAttribute("style", "width: 29px; overflow: hidden; white-space: nowrap;");
t = document.createTextNode(grandTotal.toFixed(2));
z.appendChild(t);
document.getElementById("weekly_row_" + i).appendChild(z);
}
function getWeekStart()
{
var now = google.calendar.utils.getNow();
var mtime = now.getTime();
mtime -= now.getDay() * 24 * 60 * 60 * 1000; // get beginning of week
var start = new Date();
start.setTime(mtime);
start.setHours(0);
start.setMinutes(0);
start.setSeconds(0);
start.setMilliseconds(0);
return google.calendar.utils.fromDate(start);
}
function getWeekEnd()
{
var now = google.calendar.utils.getNow();
var mtime = now.getTime();
mtime += (7 - now.getDay()) * 24 * 60 * 60 * 1000; // get beginning of week
var end = new Date();
end.setTime(mtime);
end.setHours(0);
end.setMinutes(0);
end.setSeconds(0);
end.setMilliseconds(0);
return google.calendar.utils.fromDate(end);
}
//var startDate = {year: 2010, month: 1, date: 3, hour: 0, minute: 0, second: 0};
//var endDate = {year: 2010, month: 1, date:10, hour: 0, minute: 0, second: 0};
function readEvents()
{
var calendar_id = document.getElementById("eventid").value;
google.calendar.read.getEvents(eventCallback, [calendar_id], getWeekStart(), getWeekEnd());
}
</script>
Calendar ID:
<input type="text" id="eventid" size="6"/><br/>
<input type="button" onclick="readEvents()" value="Refresh"/><br/>
<a href="http://bit.ly/OsO3ka" target="_blank">
How to use</a><br/>
<div id="myCustomContainer" style="overflow-y:scroll; height:144px">
</div>
</body>
</html>
]]></Content>
</Module>