Java Code Examples for net.sf.mpxj.ProjectCalendar#getWork()

The following examples show how to use net.sf.mpxj.ProjectCalendar#getWork() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MSPDIReader.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test to determine if this is a split task.
 *
 * @param calendar current calendar
 * @param list timephased resource assignment list
 * @return boolean flag
 */
private boolean isSplit(ProjectCalendar calendar, List<TimephasedWork> list)
{
   boolean result = false;
   for (TimephasedWork assignment : list)
   {
      if (calendar != null && assignment.getTotalAmount().getDuration() == 0)
      {
         Duration calendarWork = calendar.getWork(assignment.getStart(), assignment.getFinish(), TimeUnit.MINUTES);
         if (calendarWork.getDuration() != 0)
         {
            result = true;
            break;
         }
      }
   }
   return result;
}
 
Example 2
Source File: DateHelper.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This utility method calculates the difference in working
 * time between two dates, given the context of a task.
 *
 * @param task parent task
 * @param date1 first date
 * @param date2 second date
 * @param format required format for the resulting duration
 * @return difference in working time between the two dates
 */
public static Duration getVariance(Task task, Date date1, Date date2, TimeUnit format)
{
   Duration variance = null;

   if (date1 != null && date2 != null)
   {
      ProjectCalendar calendar = task.getEffectiveCalendar();
      if (calendar != null)
      {
         variance = calendar.getWork(date1, date2, format);
      }
   }

   if (variance == null)
   {
      variance = Duration.getInstance(0, format);
   }

   return (variance);
}
 
Example 3
Source File: MPPAbstractTimephasedWorkNormaliser.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Retrieves the pro-rata work carried out on a given day.
 *
 * @param calendar current calendar
 * @param assignment current assignment.
 * @return assignment work duration
 */
private Duration getAssignmentWork(ProjectCalendar calendar, TimephasedWork assignment)
{
   Date assignmentStart = assignment.getStart();

   Date splitStart = assignmentStart;
   Date splitFinishTime = calendar.getFinishTime(splitStart);
   Date splitFinish = DateHelper.setTime(splitStart, splitFinishTime);

   Duration calendarSplitWork = calendar.getWork(splitStart, splitFinish, TimeUnit.MINUTES);
   Duration assignmentWorkPerDay = assignment.getAmountPerDay();
   Duration splitWork;

   double splitMinutes = assignmentWorkPerDay.getDuration();
   splitMinutes *= calendarSplitWork.getDuration();
   splitMinutes /= (8 * 60); // this appears to be a fixed value
   splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES);
   return splitWork;
}
 
Example 4
Source File: MultiDayExceptionsTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test an individual project.
 *
 * @param file project file
 */
private void testMultiDayExceptions(File file) throws Exception
{
   ProjectReader reader = ProjectReaderUtility.getProjectReader(file.getName());
   if (reader instanceof MPDDatabaseReader)
   {
      assumeJvm();
   }

   DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
   ProjectFile project = reader.read(file);
   ProjectCalendar calendar = project.getCalendarByName("Standard");

   Date startDate = DateHelper.getDayStartDate(df.parse("23/12/2019"));
   Date endDate = DateHelper.getDayEndDate(df.parse("08/01/2020"));

   Duration duration = calendar.getWork(startDate, endDate, TimeUnit.DAYS);

   assertEquals("9.0d", duration.toString());
}