How to set Google Tasks Due Date

前端 未结 2 1896
长发绾君心
长发绾君心 2021-01-21 17:52

How do you set the due date for a task with the google tasks service in apps script?

Tasks Service

Trying to set this value to a given date, but this seems to on

2条回答
  •  隐瞒了意图╮
    2021-01-21 18:32

    In accordance with the Google Tasks API documentation for the Task resource, the due parameter must be an RFC 3339 timestamp. So instead of "Tue Apr 10 20:45:26 GMT-04:00 2018" it should be "2018-04-11T0:45:26.000Z". See related question: Generate an RFC 3339 timestamp similar to Google Tasks API?

    This is the same format used by other datetime properties of the task, so if one were to log the task:

    console.log(Tasks.Tasks.get(listId, taskId));
    

    Then the due, completed and updated properties, if present, would indicate the required format.

    From a native Javascript Date in Google Apps Script, this is easiest done as:

    function getExtension(listId, taskId) {
      var now = new Date();
      var deadline = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 7));
      var newTask = {
        due: Utilities.formatDate(deadline, "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'")
      };
      // Since we supply only a partial resource, call .patch() rather than .update()
      Tasks.Tasks.patch(newTask, listId, taskId);
    }
    

提交回复
热议问题