Hi,
Please run the below code:
public class TestTaskWithTwoResource {
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_Project.mpp");
asProject.set(Prj.START_DATE, formatter2.parse("7/6/16 08:00:00"));
asProject.setCalculationMode(CalculationMode.Automatic);
com.aspose.tasks.Resource test1Resource = asProject.getResources().add("test1");
com.aspose.tasks.Resource test2Resource = asProject.getResources().add("test2");
Task f1 = asProject.getRootTask().getChildren().add("Sub Task");
Date startDate = formatter2.parse("7/6/16 08:00:00");
f1.set(Tsk.START, startDate);
f1.set(Tsk.DURATION, asProject.getDuration(2, TimeUnitType.Day));
ResourceAssignment ra1 = asProject.getResourceAssignments().add(f1, test1Resource);
ra1.set(Asn.START, startDate);
ra1.set(Asn.WORK, asProject.getDuration(16, TimeUnitType.Hour));
ra1.set(Asn.PERCENT_WORK_COMPLETE, 100);
ResourceAssignment ra2 = asProject.getResourceAssignments().add(f1, test2Resource);
ra2.set(Asn.START, startDate);
ra2.set(Asn.WORK, asProject.getDuration(16, TimeUnitType.Hour));
ra2.set(Asn.PERCENT_WORK_COMPLETE, 100);
//asProject.recalculate();
asProject.save("test_task_with_two_resource.mpp", SaveFileFormat.MPP);
System.out.println("ok");
}
}
The Duration, Finish and Actual Finish is incorrect. I think the correct value of Duration is 2 days, Finish and Actual Finish is 7/7/16.
The attachment is the output file.
Best Regards!
zhencheng.guo