joniles / mpxj

Primary repository for MPXJ library

Home Page:http://www.mpxj.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing task.getEffectiveCalendar().getStartDate(x, x)

caliworks opened this issue · comments

ProjectCalendar.getStartDate(finishDate, Duration) seems to be missing starting with 12.0.0.

Is there no method like it in the new versions? How can i get the start date based off finish date + duration ?

If not, what do you think about this?

public static LocalDateTime getStartDate(LocalDateTime finishDate, Duration duration, Task task, ProjectFile file) {

	LocalDateTime projectStartDate = file.getEarliestStartDate();

	Duration durationMins = duration.convertUnits(TimeUnit.MINUTES, file.getProjectProperties());

	Duration projectStartMins = task.getEffectiveCalendar().getDuration(projectStartDate, finishDate).convertUnits(TimeUnit.MINUTES, file.getProjectProperties());

	double projectStartToTaskStartMins = projectStartMins.getDuration() - durationMins.getDuration();

	Duration projectStartToTaskStartDuration = Duration.getInstance(projectStartToTaskStartMins, TimeUnit.MINUTES);


    return task.getEffectiveCalendar().getDate(projectStartDate, projectStartToTaskStartDuration, false);

}

Thank you

The original getStartDate method was removed when I switched from java.uti.Date to the java.time.* classes. In response to this issue I've done some tidying up of the ProjectCalendar class. I've added a new version of the getDate method which just takes a date and a duration. It will now work with both positive and negative durations so you can work either way: from a start date to calculate an end date, or from an end date to calculate a start date - just change the sign of the duration to suit your needs.

The original getDate method which took the additional boolean argument has been deprecated in favour of this new version.

These changes have been merged, and will be available as part of the next MPXJ release.

thanks joniles. so for now there is no method to get start date. mpxj duration cannot be .negated() like java.time. i expect this to change in the new version. thank you and look forward to the next release.

@caliworks the new release is available now.

mpxj duration cannot be .negated() like java.time

No, for now you'll just have to create a new Duration instance with a negative value, I'll look into making this more convenient.

yes got it working now with negative value...got the new release too...thanks!