private TimephasedWork[] splitFirstDay(ProjectCalendar calendar, TimephasedWork assignment)
   {
      TimephasedWork[] result = new TimephasedWork[2];

      //
      // Retrieve data used to calculate the pro-rata work split
      //
      Date assignmentStart = assignment.getStart();
      Date assignmentFinish = assignment.getFinish();
      Duration calendarWork = calendar.getWork(assignmentStart, assignmentFinish, TimeUnit.MINUTES);
      Duration assignmentWork = assignment.getTotalAmount();

      if (calendarWork.getDuration() != 0)
      {
         //
         // Split the first day
         //
         Date splitFinish;
         double splitMinutes;
         if (calendar.isWorkingDate(assignmentStart))
         {
            Date splitStart = assignmentStart;
            Date splitFinishTime = calendar.getFinishTime(splitStart);
            splitFinish = DateHelper.setTime(splitStart, splitFinishTime);

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

            if (calendarSplitWork.durationComponentEquals(calendarWorkPerDay))
            {
               {
                  if (calendarSplitWork.durationComponentEquals(assignmentWorkPerDay))
                  {
                     splitWork = assignmentWorkPerDay;
                     splitMinutes = splitWork.getDuration();
                  }
                  else
                  {
                     splitMinutes = assignmentWorkPerDay.getDuration();
                     splitMinutes *= calendarSplitWork.getDuration();
                     splitMinutes /= (8 * 60); // this appears to be a fixed value
                     splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES);
                  }
               }
            }
            else
            {
               splitMinutes = assignmentWorkPerDay.getDuration();
               splitMinutes *= calendarSplitWork.getDuration();
               splitMinutes /= (8 * 60); // this appears to be a fixed value
               splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES);
            }

            TimephasedWork split = new TimephasedWork();
            split.setStart(splitStart);
            split.setFinish(splitFinish);
            split.setTotalAmount(splitWork);

            result[0] = split;
         }
         else
         {
            splitFinish = assignmentStart;
            splitMinutes = 0;
         }

         //
         // Split the remainder
         //
         Date splitStart = calendar.getNextWorkStart(splitFinish);
         splitFinish = assignmentFinish;
         TimephasedWork split;
         if (splitStart.getTime() > splitFinish.getTime())
         {
            split = null;
         }
         else
         {
            splitMinutes = assignmentWork.getDuration() - splitMinutes;
            Duration splitWork = Duration.getInstance(splitMinutes, TimeUnit.MINUTES);

            split = new TimephasedWork();
            split.setStart(splitStart);
            split.setFinish(splitFinish);
            split.setTotalAmount(splitWork);
            split.setAmountPerDay(assignment.getAmountPerDay());
         }

         result[1] = split;
      }
      return result;
   }
private TimephasedWork [ ] splitFirstDay ( ProjectCalendar calendar , TimephasedWork assignment ) { TimephasedWork [ ] result = new TimephasedWork [ 2 ] ; Date assignmentStart = assignment . getStart ( ) ; Date assignmentFinish = assignment . getFinish ( ) ; Duration calendarWork = calendar . getWork ( assignmentStart , assignmentFinish , TimeUnit . MINUTES ) ; Duration assignmentWork = assignment . getTotalAmount ( ) ; if ( calendarWork . getDuration ( ) != 0 ) { Date splitFinish ; double splitMinutes ; if ( calendar . isWorkingDate ( assignmentStart ) ) { Date splitStart = assignmentStart ; Date splitFinishTime = calendar . getFinishTime ( splitStart ) ; splitFinish = DateHelper . setTime ( splitStart , splitFinishTime ) ; Duration calendarSplitWork = calendar . getWork ( splitStart , splitFinish , TimeUnit . MINUTES ) ; Duration calendarWorkPerDay = calendar . getWork ( splitStart , TimeUnit . MINUTES ) ; Duration assignmentWorkPerDay = assignment . getAmountPerDay ( ) ; Duration splitWork ; if ( calendarSplitWork . durationComponentEquals ( calendarWorkPerDay ) ) { { if ( calendarSplitWork . durationComponentEquals ( assignmentWorkPerDay ) ) { splitWork = assignmentWorkPerDay ; splitMinutes = splitWork . getDuration ( ) ; } else { splitMinutes = assignmentWorkPerDay . getDuration ( ) ; splitMinutes *= calendarSplitWork . getDuration ( ) ; splitMinutes /= ( 8 * 60 ) ; splitWork = Duration . getInstance ( splitMinutes , TimeUnit . MINUTES ) ; } } } else { splitMinutes = assignmentWorkPerDay . getDuration ( ) ; splitMinutes *= calendarSplitWork . getDuration ( ) ; splitMinutes /= ( 8 * 60 ) ; splitWork = Duration . getInstance ( splitMinutes , TimeUnit . MINUTES ) ; } TimephasedWork split = new TimephasedWork ( ) ; split . setStart ( splitStart ) ; split . setFinish ( splitFinish ) ; split . setTotalAmount ( splitWork ) ; result [ 0 ] = split ; } else { splitFinish = assignmentStart ; splitMinutes = 0 ; } Date splitStart = calendar . getNextWorkStart ( splitFinish ) ; splitFinish = assignmentFinish ; TimephasedWork split ; if ( splitStart . getTime ( ) > splitFinish . getTime ( ) ) { split = null ; } else { splitMinutes = assignmentWork . getDuration ( ) - splitMinutes ; Duration splitWork = Duration . getInstance ( splitMinutes , TimeUnit . MINUTES ) ; split = new TimephasedWork ( ) ; split . setStart ( splitStart ) ; split . setFinish ( splitFinish ) ; split . setTotalAmount ( splitWork ) ; split . setAmountPerDay ( assignment . getAmountPerDay ( ) ) ; } result [ 1 ] = split ; } return result ; }
This method splits the first day off of a time span.

@param calendar current calendar
@param assignment timephased assignment span
@return first day and remainder assignments