long bestTime = early.getTime() + ((i+1)*CHUNK_DAYS*MILLIS_PER_DAY); if (bestTime > best.getTime())
long bestTime = early.getTime() + ((long)daysSoFar)*MILLIS_PER_DAY; if (bestTime > best.getTime()) { if (isInfoEnabled()) info (getName () + ".getSubtasks - had to correct bestTime, was " + new Date (bestTime) + " now " + best);
  public Vector getSubtasks(Task parentTask) {        Vector childTasks = new Vector ();    // create the d.o.    Asset supplyAsset = parentTask.getDirectObject();    Preference pref = prefHelper.getPrefWithAspectType (parentTask, AlpineAspectType.DEMANDRATE);    double rate = prefHelper.getPreferenceBestValue (pref)*SECS_PER_DAY; // base number is in quantity per second!    Date readyAt = prefHelper.getReadyAt   (parentTask);    Date early   = getEarlyDate (parentTask);    Date best    = prefHelper.getBestDate  (parentTask);    Date late    = getLateDate  (parentTask);    long window = best.getTime () - readyAt.getTime();    long numSubtasks = window/(CHUNK_DAYS*MILLIS_PER_DAY);    if (window - (numSubtasks * CHUNK_DAYS*MILLIS_PER_DAY) != 0)      numSubtasks++;    if (isDebugEnabled ())      debug (getName () + ".getSubtasks - task " + parentTask.getUID () + 	     " from " + readyAt + 	     " to " + best + 	     " will produce " + numSubtasks + " subtasks.");    // create one subtask for every chunk set of days, with an asset that is the total    // delivered over the period = days*rate    for (int i = 0; i < (int) numSubtasks; i++) {      Asset deliveredAsset = createDeliveredAsset (parentTask, supplyAsset, rate, CHUNK_DAYS);      // set item id pg to show it's a reservation, and not a normal task's asset      ItemIdentificationPG itemIDPG = (ItemIdentificationPG) supplyAsset.getItemIdentificationPG();      NewItemIdentificationPG newItemIDPG = (NewItemIdentificationPG) PropertyGroupFactory.newItemIdentificationPG();      String itemID = itemIDPG.getItemIdentification();      String itemNomen = itemIDPG.getNomenclature ();      if (itemID == null) {	TypeIdentificationPG typeID = supplyAsset.getTypeIdentificationPG ();	itemID = typeID.getTypeIdentification();      }      if (itemNomen == null) {	TypeIdentificationPG typeID = supplyAsset.getTypeIdentificationPG ();	itemID = typeID.getNomenclature();      }      newItemIDPG.setItemIdentification (itemID    + "_Reservation_" + total);      newItemIDPG.setNomenclature       (itemNomen + "_Reservation_" + (total++));      deliveredAsset.setItemIdentificationPG (newItemIDPG);          Task subTask = makeTask (parentTask, deliveredAsset);      long bestTime = early.getTime() + ((i+1)*CHUNK_DAYS*MILLIS_PER_DAY);      if (bestTime > best.getTime())	bestTime = best.getTime();      if (isDebugEnabled ())	debug (getName () + ".getSubtasks - making task " + subTask.getUID() + 	       " with best arrival " + new Date(bestTime));      prefHelper.replacePreference((NewTask)subTask, 				   prefHelper.makeEndDatePreference (ldmf,								     early, 								     new Date (bestTime),								     late));      prefHelper.removePrefWithAspectType (subTask, AlpineAspectType.DEMANDRATE); // we've included it in the d.o.      prepHelper.removePrepNamed (subTask, Constants.Preposition.MAINTAINING);      prepHelper.removePrepNamed (subTask, Constants.Preposition.REFILL);      childTasks.addElement (subTask);    }    return childTasks;  }