Task dates are incorrect on setting CalculationMode to Npne (C# .NET)

When we use Calculation.Mode = Calculation Mode.None, the task dates are incorrect.

        License license = new License();
        license.SetLicense("Aspose.Tasks.lic");

        Project project = new Project("Template.mpp");
        project.CalculationMode = CalculationMode.None;

        Task tsk1 = project.RootTask.Children.Add("Task 1");
        tsk1.Set(Tsk.IsManual, false);
        tsk1.Set(Tsk.Start, DateTime.ParseExact("2018-01-05", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        tsk1.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));

        Task tsk2 = project.RootTask.Children.Add("Task 2");
        tsk2.Set(Tsk.IsManual, false);
        tsk2.Set(Tsk.Start, DateTime.ParseExact("2018-02-13", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        tsk2.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));

        project.Save(@"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
        project.Save(@"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);

Here is the result:
DateAuto.png (2.8 KB)

        License license = new License();
        license.SetLicense("Aspose.Tasks.lic");

        Project project = new Project("Template.mpp");
        project.CalculationMode = CalculationMode.None;

        Task tsk1 = project.RootTask.Children.Add("Task 1");
        tsk1.Set(Tsk.IsManual, true);
        tsk1.Set(Tsk.Start, DateTime.ParseExact("2018-01-05", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        tsk1.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));

        Task tsk2 = project.RootTask.Children.Add("Task 2");
        tsk2.Set(Tsk.IsManual, true);
        tsk2.Set(Tsk.Start, DateTime.ParseExact("2018-02-13", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        tsk2.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));

        project.Save(@"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
        project.Save(@"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);

Here is the result:
DateMan.png (3.1 KB)

Could you help us?

@FabioMartins,

When CalculationMode.None is used, please use ConstraintType as StartNoEarlierThan and provide ConstraintDate also.

In case of Tsk.IsManual = true, Date and time shall be complete i.e. date and time both are required like “2018-01-05 08:00:00”. Similarly for this scenario set ManualStart and ManualDuration.

We are facing issue with MPP file output for IsManual = true. This issue is logged under Id:TASKSNET-2388 for detailed analysis. We will write back here once feedback is ready to share.

private static void Tasks_175500A()
{
    Project project = new Project(@"Blank2010.mpp");
    project.CalculationMode = CalculationMode.None;

    Task tsk1 = project.RootTask.Children.Add("Task 1");
    tsk1.Set(Tsk.IsManual, false);

    DateTime start = DateTime.ParseExact("2018-01-05", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
    tsk1.Set(Tsk.Start, start);
    tsk1.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
    tsk1.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
    tsk1.Set(Tsk.ConstraintDate, start);

    Task tsk2 = project.RootTask.Children.Add("Task 2");
    tsk2.Set(Tsk.IsManual, false);
    start = DateTime.ParseExact("2018-02-13", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
    tsk2.Set(Tsk.Start, start);
    tsk2.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
    tsk2.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
    tsk2.Set(Tsk.ConstraintDate, start);

    project.Recalculate();
    project.Save(@"output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
    project.Save(@"output.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
}
private static void Tasks_175500B()
{
    Project project = new Project(@"Blank2010.mpp");
    project.CalculationMode = CalculationMode.None;

    Task tsk1 = project.RootTask.Children.Add("Task 1");
    tsk1.Set(Tsk.IsManual, true);

    DateTime start = DateTime.ParseExact("2018-01-05 08:00:00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

    tsk1.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
    tsk1.Set(Tsk.ConstraintDate, start);

    tsk1.Set(Tsk.Start, start);
    tsk1.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));

    tsk1.Set(Tsk.ManualStart, start);
    tsk1.Set(Tsk.ManualDuration, project.GetDuration(2, TimeUnitType.Day));


    Task tsk2 = project.RootTask.Children.Add("Task 2");
    tsk2.Set(Tsk.IsManual, true);
    start = DateTime.ParseExact("2018-02-13 08:00:00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

    tsk2.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
    tsk2.Set(Tsk.ConstraintDate, start);

    tsk2.Set(Tsk.Start, start);
    tsk2.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));

    tsk2.Set(Tsk.ManualStart, start);
    tsk2.Set(Tsk.ManualDuration, project.GetDuration(2, TimeUnitType.Day));

    project.Recalculate();
    project.Save(@"output2.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
    project.Save(@"output2.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
}
1 Like

Hello! The issue TASKSNET-2388 has been fixed in Aspose.Tasks for .NET 18.6.