Wrong calculation of duration

Hi there!

I am having trouble with the calculation of the duration in Aspose.Tasks.
As you can see in the following image:
2021-10-12 15_09_46-Innovation_Project_Application.pdf and 15 more pages - Work - Microsoft​ Edge.png (118.2 KB)

all three tasks starting with WP have a duration of 12 months. This is correct. However, the graph on the right side seems wrong. They all start on the first of November (of a different year each), which is displayed correctly. 12 months duration would mean, that they each end at the end of October of the following year. However, they all end at the end of September. This can be confirmed in the graph as well as the “End” column.

Each task is defined like this

var taskWorkPackages = _rootTask!.Children.Add(workPackage.Number.ToString());
taskWorkPackages.Set(Tsk.Name, $"{workPackage.Number} {workPackage.Name}");
taskWorkPackages.Set(Tsk.Start, workPackage.StartDate);
taskWorkPackages.Set(Tsk.DurationText, workPackage.Name);
taskWorkPackages.Set(Tsk.Duration, _project.GetDuration(workPackage.DurationInMonths, TimeUnitType.Month));

where workPackage.StartDate, for example, a DateTime with the value 2021-11-01 00:00:00 and DurationInMonths is 12.

I just don’t get it, am I doing something wrong, or not seeing anything?

Also, the summary’s total duration shows 39.2 months instead of 36 - how is that? I haven’t been able to figure that out either.

And, question number 3: what does “mons” mean? Shouldn’t that be “months”? Is there a way to change that? Customer doesn’t like “mons”.

Thanks in advance for your help!
Dave

@davidedesantis

Can you please share the source file along with working sample code and generated output reproducing the issue on your end. We will be able to proceed further with investigation on our end on provision of requested information.

Hello @mudassir.fayyaz

Thank you for your quick reply.
I have created a test solution and project where it is possible to replicate my issue exactly.
Here’s the file:
Aspose.Tasks.Issue.zip (497.2 KB)

Of course, for security reasons, I have removed the Aspose license data in AsposeLicense.cs, so you’ll have to enter it there in order to use the tool.
The generated chart is saved in the current executing path (in /bin/…) into the Output directory.
You can see that I have left one output file there for you to see the result.

Thanks for your help.

Best,
Davide

@davidedesantis

Thank you for sharing the information. I have created a ticket with ID TASKSNET-10388 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Hello @mudassir.fayyaz

thank you very much for your support. I hope this can be resolved quickly.
I’ll keep an eye on it.

@davidedesantis

We will keep you posted with updates.

1 Like

Hello @davidedesantis.

The behavior of Aspose.Tasks repeats the behavior of MS Project.
Thus 1 month is 20 working days consisting of 8 working hours (in case of default settings).
So 12 MS Project’s months are not equal to 1 calendar year.

You can check the explanation of the same behavior in MS Project:
https://answers.microsoft.com/en-us/msoffice/forum/all/microsoft-project-durations-not-aligned-with-dates/6cb44806-27ac-426b-9c10-0b267d050d06

In order to align finish dates, one can calculate duration using the following code:

(GanttChartGenerator.AddWorkPackage(DateTime, GanttChartWorkPackageDto) method).

taskWorkPackages.Set(Tsk.Start, startTime.AddMonths(workPackage.StartMonth - 1));
taskWorkPackages.Set(Tsk.DurationText, workPackage.Name);

// Get default calendar for the project. For simplicity we take the first calendar.
var calendar = this._project.Calendars.First();
var alignedDuration = calendar.GetWorkingHours(
taskWorkPackages.Get(Tsk.Start),
taskWorkPackages.Get(Tsk.Start).AddMonths(workPackage.DurationInMonths)).WorkingHours;
taskWorkPackages.Set(Tsk.Duration, _project.GetDuration(alignedDuration, TimeUnitType.Month));

The summary’s total is incorrect due to the same reason.

As for “mons”, a callback can be passed to constuctor of GanttChartColumn where duration’s value can be formatted in any ways.
For example, this can be done in the following way:

(GanttChartOptions.GetColumns() method)

yield return new GanttChartColumn(“Duration”, 60, t => ((int)t.Get(Tsk.Duration).TimeSpan.TotalHours / (8 * 20) + " months"));