-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.js
More file actions
52 lines (42 loc) · 1.61 KB
/
Code.js
File metadata and controls
52 lines (42 loc) · 1.61 KB
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
/**
* Finance Secretary v1:
* should fetch calendar title which starts with a $ string in the last 7 days
* add the numbers that come after the $ sign
*/
function myFunction() {
var today = new Date(); //creates a var named today and stores today's date into it. Blank gives today's date by default
var firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
console.log("first day of this month: ", firstDayOfMonth);
var dateSevenDaysAgo = new Date(today.getTime() - 24 * 60 * 60 * 1000 * 7);
console.log(dateSevenDaysAgo);
var eventsToday = CalendarApp.getOwnedCalendarById(
"lzh.carey@gmail.com"
).getEventsForDay(today);
var firstEventOfToday = eventsToday[0].getTitle();
//fetching logic
var eventsLastSevenDays = CalendarApp.getOwnedCalendarById(
"lzh.carey@gmail.com"
).getEvents(firstDayOfMonth, today);
// console.log(eventsLastSevenDays);
eventsThatStartWithDollarSign = [];
for (var i = 0; i < eventsLastSevenDays.length; i++) {
if (eventsLastSevenDays[i].getTitle().startsWith("$")) {
/**
* IMPENDING UGLY CODE: THE FOLLOWING LINE PERFORMS 3 FUNCTIONS:
* reference title of each event
* replace dollar sign in the title
* pushes replaced title into new array*/
eventsThatStartWithDollarSign.push(
parseInt(eventsLastSevenDays[i].getTitle().replace("$", ""))
);
//console.log(eventsThatStartWithDollarSign);
}
}
console.log(
"Month: ",
today.getMonth(),
" Spendings to date: ",
eventsThatStartWithDollarSign.reduce((a, b) => a + b, 0)
);
console.log("test push from clasp");
}