Issue with decimal duration when exporting to msproject

Hello,

I have a case when using the export to msproject method, the generated xml brings me the correct start and end dates of the tasks, but the duration of some tasks are wrong when importing that xml in msproject, the duration value does not match the values shown in gantt.


Hello Mariana,
Internally, Gantt stores the duration in integer values, and there is no way to change that. You can only change what is displayed to the users with the formatters.
So, when you export the data, Gantt adds the duration from the duration parameter of the task object, not from what you see in the formatter.
If the duration_unit parameter is set to "hour", you should get the value in hours.

Also, if you use custom working time settings, they are applied to Gantt, but there is no way to set them for the duration formatter. You can only specify the number of working hours per week and similar parameters:
https://docs.dhtmlx.com/gantt/desktop__formatters_ext.html#durationformatter:~:text=hoursPerWeek%3F%20-%20(number)%20-%20defines%20how%20duration%20values%20will%20be%20converted%20from%20hours%20to%20weeks%20and%20vice-versa.%20Default%20value%3A%2040

If I enable the working time calculation and set the start_date and end_date parameters, I get almost the same duration value as on your screenshot in MS Project (the difference should be because of working hours):


Here is the snippet:
https://snippet.dhtmlx.com/e19bmcja

Moreover, if I use the configuration with the default working time settings, I get the same duration as on your screenshot in MS Project:


Here is the snippet:
https://snippet.dhtmlx.com/tqykbztx

So, maybe there is something wrong with the formatter configuration, but it is hard to suggest what might be wrong as I don’t see your code.

Please add your configuration to the following snippet and make sure that the issue is reproduced there:

Then, click on the Save 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.

Hi Ramil,

The case uses a custom working time setting. I tried to modify the working hours per week but did not get good results, because it takes information from a global calendar. When I import the xml into msproject it takes those default values and the results are different from the ones in the gantt.

I would like to know, how can I modify that general information of the calendar related to the project so that it takes the configuration of the custom work times ? or somehow prevent the duration from going through that additional calculation, so that it is not affected by the properties of the global calendar ?

I leave part of the code in the snippet so you can see the general settings, with different values but the same problem case is played.

https://snippet.dhtmlx.com/o5fixi9h

Hello Mariana,
Thank you for sharing the configuration.
I see that you create a custom calendar but don’t apply the settings to the tasks. And then you show values in the grid using the custom calendar while all the tasks have the global calendar. As I said earlier, when you export the data, what you see in the grid doesn’t matter at all. Gantt uses the values from the duration parameter.

As a result, you get different duration values in MS Project. I couldn’t open the exported files in MS Project because of the duration out of range error, so I used an online service to compare the difference:


And the _getWorktimeSettings function only modifies the calendar settings for the exported file. It doesn’t affect actual task duration at all.
Unfortunately, right now, you cannot export custom calendars, only the global calendar is exported. If all tasks in the chart have the same calendar, you can copy the calendar settings to the global calendar, but you also need to recalculate the task dates after changing the calendar:
https://docs.dhtmlx.com/gantt/desktop__working_time.html#changingcalendardynamically

Another thing that affects the duration for MS Project are the different working time settings that are not used by Gantt, namely HoursPerDay and MinutesPerDay. You need to specify these parameters in the project parameter of the export function:
https://docs.dhtmlx.com/gantt/desktop__export_msproject.html#:~:text=Getting%20properties%20of%20the%20Project

When you calculate HoursPerDay for the duration column, you choose the date when the task starts. But the task may start on Sunday where you have 13:14 working hours or it can start on another working day that has only 7:33 working hours. And as a result, you get different results. It doesn’t work that way in MS Project. You need to specify the common value that doesn’t depend on the task date.

After I specified the following settings, I get the same results in the exported file:

gantt.exportToMSProject({
  project: {
    HoursPerDay: function () {
        return 7;
    },
    MinutesPerDay: function () {
        return 7 * 60 + 33;
    }
  }
})


Here is the updated snippet:
https://snippet.dhtmlx.com/4dxtefcp

Hi Ramil,

Thanks for your reply.

I tried to specify the properties ‘HoursPerDay’ and ‘MinutesPerDay’, and copy the calendar configuration to the global calendar, but when configuring the ‘HoursPerDay’ property, the custom times configured there are lost, and it remains a static value for all days. That solution does not work for me.

Gantt is already showing me the correct values, the problem arises when importing the resulting xml to msproject, with the calendar configuration. When I modify those values I am affecting the working time, I can not handle the working time that the user specifies in the custom calendar.

It would be great to be able to export that information from the customized calendar, and have it take into account the working times. Would there be any way to request that functionality to support?

Hello Mariana,
Probably, the first thing to do is to check if you can do the same things in MS Project. You can create a few tasks there and add different working time settings for different dates. If it shows the correct duration values and there is only one calendar, you can send me an XML file, and I will check if there is a way to get the same result when you export the data from Gantt.

Right now, there is no way to export with different calendar settings. The dev team will add that functionality in the future, but I cannot give you any ETA.