Hello,
In the following code dt_start and dt_end are java.util.Date. The variable is_file is a file.mpp.
After I set Start and Finish date of the task, the task start date(1/28/2017) is printing one day before(1/27/2017).
I already tried also using Calendar but I got the same result.
Project project = new Project(is_file);
try {
Task task = project.getRootTask().getChildren().add(s_task);
if (dt_start != null)
task.set(Tsk.START, dt_start);
if (dt_end != null)
task.set(Tsk.FINISH, dt_end);
project.save(is_file, SaveFileFormat.MPP);
Hi,
Thank you for your interest in Aspose.
We tried executing your code with the latest version 16.11.0, but were not able to observe any such problem. Please share your sample project along with the sample MPP file to reproduce the issue at our end. We’ll look into it to analyze the issue further and assist you accordingly.
Hello Maria Shahid,
Thank you for your quick answer.
Attached is the mpp file. Is an empty project.
The code is the same as before but inside a function. The parameters of the function are name of the task, the start date and the end date.
Best regards,
Hi,
Thank you for sharing the sample file.
We tried the below sample code with your shared MPP file but still could not observe any such issue. Using the below code, start date of the task is set to 30 JAN rather than 28 JAN, due to the fact that the start date we have passed falls on a weekend. We have attached output MPP file for your reference.
Project project = new Project(dataDir + "template.mpp");
java.util.Calendar startDate = java.util.Calendar.getInstance();
startDate.set(2017, 0, 28);
java.util.Calendar endDate = java.util.Calendar.getInstance();
startDate.set(2017, 0, 30, 17, 0, 0);
project.set(Prj.START_DATE, startDate.getTime());
Task task = project.getRootTask().getChildren().add("new task");
if (startDate
!= null)
task.set(Tsk.START,
startDate.getTime());
if (endDate
!= null)
task.set(Tsk.FINISH,
endDate.getTime());
System.out.println(startDate.getTime());
System.out.println(task.get(Tsk.START));
project.save(dataDir + "output.mpp", SaveFileFormat.MPP);
The sample code you have shared earlier does not seem sufficient to reproduce the issue at our end. Since we cannot make out the exact values you are passing for start and finish dates neither that helps identify which version of the API you are currently using at your end. Please try the below suggestions at your end and see if the issue is resolved.
- Rather than setting the Finish date, please try setting the duration of the task since setting it calculates the task’s Finish date automatically and eliminates any confusion of the start date being reset.
- Please try your code with the latest version of the API i.e. 16.11.0.
If the issue still persists, please let us know JDK and Aspose.Tasks version you are using at your end. We’ll look into it further to assist you accordingly.
Attached is a project that is ready to be run as a java application. It will print the values of the startDate(java.util.date) and the value of the Tsk.START. They should be the same because I am setting the Tsk.START with the satrtDate value. For some reason they are different. I also attached a sample of the output I am getting in a screenshot.
I am using jdk 1.8.0_60 and the aspose-tasks-16.11.0-jdk18.jar.
Hi,
Thank you for sharing the sample project. The issue however does not seem to be a limitation of the API, rather the date is changed to next day due to the scheduling engine. Since the date you are setting for task start does not have enough working hours in the day according to the Standard calendar used by the project, therefore the start date is changed to the next working day. Please let us know if you have any further query in this regard.
Hello Mary,
As you mentioned before the issue was a setup in mpp file.
Thank you very much.
Best regards
You are welcome.