-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gs
54 lines (49 loc) · 1.38 KB
/
main.gs
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
// Simple GAS for move the overdue tasks with today date and add [OVERDUE] to the title
// Author : [email protected]
function index() {
// I get all my list
var lists = listTaskLists();
if(lists != -1) {
// For each list i get all the tasks
for(var i=0;i < lists.items.length;i++) {
var tasks = listTasks(lists.items[i].id);
//I check each task to see if is overdue and change it for today
if (tasks != -1) {
for(var j=0;j < tasks.items.length;j++) {
var now = new Date();
now.setHours(0,0,0,0);
if(tasks.items[j].due < now.toISOString()) {
//If the task is older
move(lists.items[i].id,tasks.items[j].id,tasks.items[j].title);
}
//tasks with no due date are gives TRUE
}
Tasks.Tasks.clear(lists.items[i].id);
}
}
}
}
function listTaskLists() {
var taskLists = Tasks.Tasklists.list();
if (taskLists.items) {
return taskLists;
} else {
return -1;
}
}
function listTasks(taskListId) {
var tasks = Tasks.Tasks.list(taskListId);
if (tasks.items) {
return tasks;
} else {
return -1;
}
}
function move(taskListId, taskId,title) {
var task = Tasks.newTask();
task.setDue(new Date().toISOString());
if(title.indexOf('[OVERDUE]') < 0) {
task.setTitle('[OVERDUE] '+ title);
}
Tasks.Tasks.patch(task, taskListId, taskId);
}