MPP duration problem

Hello

We are using Aspose Tasks version 17.5 (jdk16) for Java.

After creating MPP file (using the file attached) using Aspose Task API we observe, that duration values shown in MS Project 2016 are not the ones we expect. In the attached ‘screenshot1.png’ the duration values are 41.13 and 21.13, but what we expect are values 40 and 20 respectively.
The problem is caused by “Default Start Time”/“Default End Time” set in an exported MSProject file (by default they are: 9:00 AM - 6:00 PM accordingly). But during the export we need to set it to 9:00 AM - 5:00 PM so that MS Project has automatically those values set as shown in ‘screenshot2.png’.

Is it possible to set those values in exported MPP file using Aspose Tasks API?
If so can you provide some example code?

files.zip (489.0 KB)

@SoftwarePlant,

Could you also please share your sample code you are using at your end? We are also looking into it and will share our findings with you here soon.

Here is some snippet of our code:

Project project = new Project(inputStream);
project.set(Prj.UID, Integer.toString(ganttData.getId()));
project.set(Prj.NAME, ganttData.getSummary());
project.set(Prj.START_DATE, ganttData.getStartDate().toDate());
project.set(Prj.TIMESCALE_START, ganttData.getStartDate().plusDays(-2).toDate());
project.set(Prj.TIMESCALE_FINISH, ganttData.getEndDate().plusDays(2).toDate());
project.set(Prj.CURRENT_DATE, LocalDate.now().toDate());
project.set(Prj.TITLE, ganttData.getDescription());
project.set(Prj.DURATION_FORMAT, TimeUnitType.Day);
project.set(Prj.WORK_FORMAT, TimeUnitType.Day);
project.set(Prj.DEFAULT_TASK_TYPE, TaskType.FixedDuration);
project.set(Prj.SCHEDULE_FROM_START, NullableBool.to_NullableBool(true));
project.setCalculationMode(CalculationMode.Manual);

// Calendar
setCalendar(project, ganttData.getCalendar());
// Tasks
setTasks(project, ganttData.getTasks());
// Links
setLinks(project, ganttData.getTaskLinks())

project.calcResourceFields();

saveProject(targetFileFormat, project, outputStream);

InputStream is just a stream of our empty MPP project (attached project.zip).

project.zip (25.5 KB)

@SoftwarePlant,

Thank you for sharing details. Let me update you that we have tried to reproduce the issue at our end but the code snippet that you have shared is just a part of complete code. With setCalendar, setTasks and setLinks calls in the code, we are unclear. Please share complete code snippet which contains following calls:

task.Set(Tsk.Duration, <value>)

or

task.Set(Tsk.Start, <value>) and task.Set(Task.Finish, <value>)

Sorry for the delay.

Here is the code:

private com.aspose.tasks.Task generateTask(TaskCollection taskCollection, Project project, CustomTask customTask) {
	com.aspose.tasks.Task resultTask = taskCollection.add(customTask.getName());
	resultTask.set(Tsk.UID, customTask.getId());
	resultTask.set(Tsk.START, customTask.getStartDate().toDate());
	resultTask.set(Tsk.ACTUAL_START, customTask.getStartDate().toDate());
	resultTask.set(Tsk.TYPE, TaskType.FixedDuration);
	resultTask.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
	resultTask.set(Tsk.DURATION, project.getDuration(getWorkingDaysDuration(customTask).doubleValue(), TimeUnitType.Day));
	resultTask.set(Tsk.IS_MILESTONE, NullableBool.to_NullableBool(customTask.isMilestone()));
	return resultTask;
}

private int getWorkingDaysDuration(CustomTask customTask) {
	DateTime startDate = customTask.getStartDate();
	DateTime endDate = customTask.getEndDate();
	int duration = 0;
	while (startDate.getMillis() <= endDate.getMillis()) {
		if (isWorkingDay(startDate)) {
			duration++;
		}
		startDate = startDate.plusDays(1);
	}
	return Math.max(duration, 1);
}

// isWorkingDay() method just checks, if a given day is a working day or a holiday

@SoftwarePlant,

Thank you for providing sample code however it is not sufficient to re-produce the issue. It seems that you are setting the default start and finish time but not the calendar working hours. In your template project, times are from 9 am to 1 pm and 2 pm to 6 pm. However after export you want to change the time from 9 am to 5 pm which may conflict with the working hours in the calendar. In this case you may create new calendar or change the existing calendar working hours and then try the scenario.

If issue is not resolved, please send us a complete sample console application where all the references are resolved and source tasks data is also part of the code. It will help us to compile and execute the application without any error or missing references and observe the issue to provide assistance accordingly.

Can you provide some example code showing how to set calendar working hours so that the end result is the time from 9am to 5pm as on the image ‘screenshot2.png’ i provided earlier?

@SoftwarePlant,

We have tried following sample code but facing some issue in the line with comment. We have requested our product team to look into it and provide assistance. We will write back here as soon as some feedback is received.

Project proj = new Project(“project.mpp”);
java.util.Calendar FromTime = java.util.Calendar.getInstance();
FromTime.set(1, java.util.Calendar.JANUARY, 1, 9, 0, 0);

java.util.Calendar ToTime = java.util.Calendar.getInstance();
ToTime.set(1, java.util.Calendar.JANUARY, 1, 17, 0, 0);

proj.set(Prj.DEFAULT_START_TIME, FromTime.getTime());
proj.set(Prj.DEFAULT_FINISH_TIME, ToTime.getTime());

Calendar NewCal = proj.getCalendars().add(“NewCal”);
for (int i = 0; i < 7; i++)
{
WeekDay day = NewCal.getWeekDays().toList().get(i);
if ( day.getDayType() != DayType.Exception &&
day.getDayType() != DayType.Saturday &&
day.getDayType() != DayType.Sunday)
{

    day.getWorkingTimes().remove(day.getWorkingTimes().toList().get(0));
    day.getWorkingTimes().remove(day.getWorkingTimes().toList().get(0));

    WorkingTime wt = new WorkingTime();
    wt.setFromTime(FromTime.getTime());
    wt.setToTime(ToTime.getTime());

    day.getWorkingTimes().add(wt);//THIS LINE DOES NOT WORK
}

}
proj.set(Prj.CALENDAR, NewCal);
proj.save(“NewOutputJava.mpp”, SaveFileFormat.MPP);

Thank you. It will be very helpful.

@SoftwarePlant,

We are investigating this issue at our end via issue id: TASKSNET-2225 and will update you here once there is some update or a fix version available in this regard.

@SoftwarePlant,

The issue reported under id: TASKSJAVA-472 has been fixed in Aspose.Tasks for Java 17.11 release.