Value of Gantt duration field not being submitted correctly when updating task

Hi, I have a custom lightbox implementation which works fine, besides the duration.

When editing a task, the duration field is submitted correctly, however the end date is not calculating this correctly and is reflecting the tasks as having a 0 days duration.
Upon refreshing the page completely this displays fine.

Is there anything that may be causing this? I can see the value is being picked up correctly as i am logging or alerting the value at various points in the process.

My showLightbox code
http://snippet.dhtmlx.com/b160c54ed

Save() function:
http://snippet.dhtmlx.com/b61335eaf

I have fixed this by setting task.end_date to null in the save() function, as this was being populated with a random date and was overriding the duration field.

edit: this works when creating a new task but not when editing a task, same behaviour occurs