LoginSignup
1
2

More than 1 year has passed since last update.

Google Tasks で前週未消化タスクを次週にリスケする

Last updated at Posted at 2022-11-28

目的

Google カレンダー上でタスク管理をするのに Google Tasks を使っています。

1週間ビューで見ていると、前週未消化タスクを次週にリスケするのが大変なので、自動化します。

(2週間ビューでみると、ドラッグ & ドロップで移動できるという話もあります)

前提条件

Google App Script

rescheduleTasksNextWeek.js
function rescheduleTasksNextWeek() {
  const tasks = Tasks.Tasklists.list();
  const taskLists = tasks.items;
  //console.log(taskLists);
  const taskListId = taskLists[0].id // タスクリスト My Task を取得
  //console.log(taskListId);
  const alltodos = Tasks.Tasks.list(taskListId).items; // My Task 内のすべてのタスクを取得
  //console.log(alltodos[0]);
  /*
  { due: '2022-12-16T00:00:00.000Z',
  kind: 'tasks#task',
  position: '00000000000000000000',
  status: 'needsAction',
  id: 'dll2S3lDaVFyMzBEZ1ZYag',
  etag: '"LTEyMTAxNzgwNDc"',
  selfLink: 'https://www.googleapis.com/tasks/v1/lists/taskListId/tasks/taskId',
  links: [],
  updated: '2022-11-27T06:55:00.000Z',
  title: 'test todo' }
  */
  //console.log(alltodos[0].due) //--> string '2022-12-16T00:00:00.000Z'
  
  const today = new Date()// 今日の時間をセット
  //console.log(`today = ${today}`)
  //console.log(`todayISO = ${today.toISOString()}`)
  const weekbefore = new Date() // 1週間前の時間をセット
  weekbefore.setDate(weekbefore.getDate() - 7);
  //console.log(`weekbefore = ${weekbefore}`)

  // 前週のタスクをフィルター
  const thisweektodos = alltodos.filter(function(todo) {
    const tododue = new Date(todo.due);
    if (tododue < today) {
      if (tododue > weekbefore){
        //console.log(tododue)
        return true;
      }
    }
    return false;
  });
  //console.log(thisweektodos)

  // タスク期限を1週間後にアップデート
  for( let i = 0; i < thisweektodos.length; i++ ){
    //console.log(thisweektodos[i].title);
    //console.log(thisweektodos[i].due);
    const thisweektodoid = thisweektodos[i].id;
    //console.log(thisweektodoid)
    const thisweektododue = new Date(thisweektodos[i].due);
    thisweektododue.setDate(thisweektododue.getDate() + 7);
    Tasks.Tasks.patch({due:thisweektododue.toISOString()},taskListId,thisweektodoid)
  }
}

スケジュール実行

以下のようにトリガー指定で毎週土曜に実行させられます。

image-20221128114507116

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2