Split Task Dates Incorrect on .mpp Export/Import

Hi everyone ! :slight_smile:

When I export a .mpp file using Aspose.Tasks (C#, .NET 8), the split task dates appear incorrect when I import the file back into my application or another tool. However, if I open the exported .mpp file in Microsoft Project and save it (without making any changes), the dates are then correct on re-import.

  • All dates (task start/end, split segments, calendar exceptions) are set with DateTimeKind.Utc before export.
  • The project calendar is assigned to all tasks and to the project.(working hours are 8am to 5pm)
  • The issue only affects split tasks; regular tasks and milestones are imported correctly.

For example, a split task (start : 2023-04-05 00:00:00, end : 2023-04-20 00:00:00) exported with following dates split :

  • Start : 2023-04-05 17:00:00, Finish : 2023-04-17 08:00:00

will be imported with these segments :

  • Start : 2023-04-05 00:00:00, Finish : 2023-04-04 17:00:00
  • Start : 2023-04-14 08:00:00, Finish : 2023-04-18 17:00:00

when it should have been :

  • Start : 2023-04-05 00:00:00, Finish : 2023-04-05 17:00:00
  • Start : 2023-04-17 08:00:00, Finish : 2023-04-19 17:00:00

As stated, when I open the mpp file and save it, then I have the correct segments.

Here are my (hopefully relevant) code snippets :

Export segments :

var currentTask = parentTask.Children.Add(task.Name);
currentTask.Set(Tsk.Calendar, _projectCalendar);
currentTask.Set(Tsk.Start, task.StartDate);
currentTask.Set(Tsk.IsEstimated, false);
currentTask.Set(Tsk.IsManual, false);
currentTask.Set(Tsk.Type, TaskType.FixedDuration);
currentTask.Set(Tsk.Duration, _project.GetDuration((long)task.Duration, TimeUnitType.Day));
var splitResourceAssignment = _project.ResourceAssignments.Add(currentTask, null);
splitResourceAssignment.TimephasedDataFromTaskDuration(_projectCalendar);
for (var i = 1; i < task.Segments.Count; i++)
{
var splitStartDate = task.Segments[i - 1].EndDate.Date;
var splitEndDate = task.Segments[i].StartDate.Date;
splitResourceAssignment.SplitTask(splitStartDate, splitEndDate, _projectCalendar);
}

Import :

List GetSegments(List<Aspose.Tasks.SplitPart> segmentsList, DateTime projectStartDate)
{
var segments = new List();
segmentsList = segmentsList.OrderBy(_ => _.Start).ToList();
for (var i = 0; i < segmentsList.Count; i++)
{
var segment = segmentsList[i];
var startDate = segment.Start;
var endDate = segment.Finish;
segments.Add(new MppImportSegment()
{
Duration = GetWorkingDaysNumberForDateRange(startDate, endDate),
Finish = endDate,
Index = i,
Lag = GetWorkingDaysNumberForDateRange(projectStartDate, startDate) - 1,
Start = startDate
});
}
return segments;
}

2 files attached in the zip : MSExports.zip (69,6 Ko)

  • Planning_Proj 01_ Plan=True, Bill=True, Acc=True_S3 : OK file (opened and saved with MS Project after export)
  • Planning_Proj 01_ Plan=True, Bill=True, Acc=True_S3 (1) : KO file (not opened and saved with MS Project after export)

Any idea is welcomed :slight_smile:
Have a nice day