Date Issue

Hi,

I'd like to improve the performance, so I changed the CalculationMode to "None", and I got some issue, please run the code as below, the "Start Date" and "Finish Date" can not be set correctly.

public class TestCreateActual {
private static SimpleDateFormat formatter2 = new SimpleDateFormat("MM/dd/yy hh:mm:ss");
public static void main(String[] args) throws ParseException {
FileInputStream fstream = null;
try {
// Create a stream object containing the license file
fstream = new FileInputStream("Aspose.Tasks.lic");
// Instantiate the License class
License license = new License();
// Set the license through the stream object
license.setLicense(fstream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
fstream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Project asProject = new Project("Empty_MPP_Template.mpp");
asProject.set(Prj.START_DATE, formatter2.parse("09/27/02 08:00:00"));
asProject.set(Prj.FINISH_DATE, formatter2.parse("12/30/02 08:00:00"));
asProject.setCalculationMode(CalculationMode.None);

Task f1 = asProject.getRootTask().getChildren().add("Release 5.0");
f1.set(Tsk.START, formatter2.parse("09/28/02 08:00:00"));
f1.set(Tsk.FINISH, formatter2.parse("09/29/02 08:00:00"));
f1.set(Tsk.DURATION, asProject.getDuration(1, TimeUnitType.Day));
Task f1_1_1_1 = f1.getChildren().add("Top-Down Project Planning");
f1_1_1_1.set(Tsk.START, formatter2.parse("09/28/02 08:00:00"));
f1_1_1_1.set(Tsk.FINISH, formatter2.parse("09/29/02 08:00:00"));
f1_1_1_1.set(Tsk.DURATION, asProject.getDuration(1, TimeUnitType.Day));
f1_1_1_1.set(Tsk.WORK, asProject.getDuration(4, TimeUnitType.Hour));
asProject.recalculate();
asProject.save("test_create_actual.mpp", SaveFileFormat.MPP);
System.out.println("ok");
}
}

Best Regards!
zhencheng.guo

Hi Zhencheng,


Thank you for writing to Aspose support team.

You may use constraint date and type as well to get the proper date here. Please give try to the following sample code and share the feedback.

Project asProject = new Project("Empty_Project.mpp");

asProject.set(Prj.
START_DATE, formatter2.parse("09/27/02 08:00:00"));
asProject.set(Prj.
FINISH_DATE, formatter2.parse("12/30/02 08:00:00"));

asProject.setCalculationMode(CalculationMode.
None);

Task f1 = asProject.getRootTask().getChildren().add(
"Release 5.0");
f1.set(Tsk.
START, formatter2.parse("09/27/02 08:00:00"));
f1.set(Tsk.
FINISH, formatter2.parse("09/28/02 08:00:00"));
f1.set(Tsk.
DURATION, asProject.getDuration(1, TimeUnitType.Day));

Task f1_1_1_1 = f1.getChildren().add(
"Top-Down Project Planning");
f1_1_1_1.set(Tsk.
START, formatter2.parse("09/27/02 08:00:00"));
f1_1_1_1.set(Tsk.
FINISH, formatter2.parse("09/28/02 08:00:00"));
f1_1_1_1.set(Tsk.
DURATION, asProject.getDuration(1, TimeUnitType.Day));
f1_1_1_1.set(Tsk.
WORK, asProject.getDuration(4, TimeUnitType.Hour));
f1_1_1_1.set(Tsk.
CONSTRAINT_DATE, formatter2.parse("09/27/02 08:00:00"));
f1_1_1_1.set(Tsk.
CONSTRAINT_TYPE, ConstraintType.StartNoEarlierThan);
asProject.recalculate();

asProject.save(
"test_create_actual.mpp", SaveFileFormat.MPP);
System.
out.println("ok");

Hi kashif,


The Finish date is still incorrect, I set it “09/28/02”, but the result is “09/27/02”, please check it again, thanks!


Best Regards!
zhencheng.guo

Hi Kashif,


Thanks for your input. What’s the reason we need to set a constraint to get a correct start and end date? Why won’t it work to just set the task fields to this value?

In MS Project we can set the start/end date fields of a task directly without having to create a constraint, so why won’t it work with Aspose?


Actually, even if I set the constraint, it doesn’t work.

Hi Zhencheng,


Your calendar working times are 8 a.m. to 5 p.m. When you set start time 09/27/02 08:00 am and finish time to 09/28/02 08:00 am, this is actually one day task (08 hours) and automatically sets to 05 pm on the start date. Please set time according to the calendar workings hours using Aspose.Tasks and compare the behavior with MSP also.

Please feel free to write us back if you have any other query in this regard.

Hi Jay,


Thank you for writing to Aspose support team.

When a task is created, it contains constraint type “AsSoonAsPossible” however when Tsk.Finish flag is used to set the finish date of the task, the constraint type is set to “FinishNoEarlierThan”. That is why dates are changed. You may please use constraint like StartNoEarlierThan etc. to achieve the desired results.
kashif.iqbal:
Hi Zhencheng,
Thank you for writing to Aspose support team.

You may use constraint date and type as well to get the proper date here. Please give try to the following sample code and share the feedback.

Project asProject = new Project("Empty_Project.mpp");

asProject.set(Prj.
START_DATE, formatter2.parse("09/27/02 08:00:00"));
asProject.set(Prj.
FINISH_DATE, formatter2.parse("12/30/02 08:00:00"));

asProject.setCalculationMode(CalculationMode.
None);

Task f1 = asProject.getRootTask().getChildren().add(
"Release 5.0");
f1.set(Tsk.
START, formatter2.parse("09/27/02 08:00:00"));
f1.set(Tsk.
FINISH, formatter2.parse("09/28/02 08:00:00"));
f1.set(Tsk.
DURATION, asProject.getDuration(1, TimeUnitType.Day));

Task f1_1_1_1 = f1.getChildren().add(
"Top-Down Project Planning");
f1_1_1_1.set(Tsk.
START, formatter2.parse("09/27/02 08:00:00"));
f1_1_1_1.set(Tsk.
FINISH, formatter2.parse("09/28/02 08:00:00"));
f1_1_1_1.set(Tsk.
DURATION, asProject.getDuration(1, TimeUnitType.Day));
f1_1_1_1.set(Tsk.
WORK, asProject.getDuration(4, TimeUnitType.Hour));
f1_1_1_1.set(Tsk.
CONSTRAINT_DATE, formatter2.parse("09/27/02 08:00:00"));
f1_1_1_1.set(Tsk.
CONSTRAINT_TYPE, ConstraintType.StartNoEarlierThan);
asProject.recalculate();

asProject.save(
"test_create_actual.mpp", SaveFileFormat.MPP);
System.
out.println("ok");


Hi kashif,

I have ran the code you provided, but the finish date is still incorrect, could you check it again? Thanks!


Best Regards!
zhencheng.guo

Hi Zhencheng,


I have executed the above code and output XML/MPP files are attached here for your reference. Could you please identify the problem in this output? Sep 27, 2002 is Friday and if we set start to 8 am on 27th Sep and finish date to 8 am on 28th Sep, its actually one day task and finish date will set to Sep 27, 2002 5pm. Please give it a try and share the feedback.