updateTask fails with invalid date format

Hi,

I am having an issue with the updateTask method throwing an invalid date format when I attempt to call this method with an existing task.

The code snippet is below:

if (!gantt.isTaskExists(task.id)) {
    task.duration = self.getTaskDuration(task);
    task.id = self.addNewTask(task);
} else {
    gantt.updateTask(task.id, task);
}

The task object being passed to updateTask is:

{ color: "#f2552c"
  duration: 90
  end_date: "2021-04-01 00:00:00"
  id: 137
  open: true
  parent: ""
  start_date: "2021-01-01 00:00:00"
  text: "Task A"
 }

The gantt.config.date_format value is set to:

gantt.config.date_format = "%Y-%m-%d %H:%M:%S";

The error thrown is:

dhtmlxgantt.js:11 Uncaught Error: Invalid start_date argument for getDuration method
at Object._getStartEndConfig (dhtmlxgantt.js:11)
at Object.getDurationArguments (dhtmlxgantt.js:11)
at a.calculateDuration (dhtmlxgantt.js:11)
at Object.calculateDuration (dhtmlxgantt.js:11)
at Object.t._init_task_timing (dhtmlxgantt.js:11)
at Object.<anonymous> (dhtmlxgantt.js:11)
at Object.i (dhtmlxgantt.js:11)
at Object.t.callEvent (dhtmlxgantt.js:11)
at s.<anonymous> (dhtmlxgantt.js:11)
at s.i (dhtmlxgantt.js:11)
at s.t.callEvent (dhtmlxgantt.js:11)
at s.updateItem (dhtmlxgantt.js:11)
at Object.updateTask (dhtmlxgantt.js:11)

I have also tried all of the following formats but they all fail as invalid date format:

  • an instance of Date()
  • converted to ISO string using toISOString()
  • converted to UTC string using toUTCString()
  • converted to string using toString()

I would appreciate any guidance that would help me resolve this error.

Hello Johnny,
When you pass the task object as the second parameter, it should have all the necessary parameters:
https://docs.dhtmlx.com/gantt/desktop__loading.html#dataproperties
The start_date and end_date parameters should have the Date format. And also, you need to include the $source and $target parameters:
https://docs.dhtmlx.com/gantt/api__gantt_updatetask.html
These parameters are related to the links. If a task doesn’t have the links, these parameters should have an empty array.

Here is an example of how it works:
http://snippet.dhtmlx.com/5/3df48f59b

If that doesn’t help you, please, add your configuration in the following snippet and make sure that the issue is reproduced there:
https://snippet.dhtmlx.com/38ee1b370
Then, click on the Share button and send me the link.
Or send me a ready demo with all the necessary Javascript and CSS files so that I can reproduce the issue locally.