private List < TimephasedWork > splitWork ( CostRateTable table , ProjectCalendar calendar , TimephasedWork work , int rateIndex ) { List < TimephasedWork > result = new LinkedList < TimephasedWork > ( ) ; work . setTotalAmount ( Duration . getInstance ( 0 , work . getAmountPerDay ( ) . getUnits ( ) ) ) ; while ( true ) { CostRateTableEntry rate = table . get ( rateIndex ) ; Date splitDate = rate . getEndDate ( ) ; if ( splitDate . getTime ( ) >= work . getFinish ( ) . getTime ( ) ) { result . add ( work ) ; break ; } Date currentPeriodEnd = calendar . getPreviousWorkFinish ( splitDate ) ; TimephasedWork currentPeriod = new TimephasedWork ( work ) ; currentPeriod . setFinish ( currentPeriodEnd ) ; result . add ( currentPeriod ) ; Date nextPeriodStart = calendar . getNextWorkStart ( splitDate ) ; work . setStart ( nextPeriodStart ) ; ++ rateIndex ; } return result ; }
Splits timephased work segments in line with cost rates . Note that this is an approximation - where a rate changes during a working day the second rate is used for the whole day .