Splits timephased data into individual days.

@param calendar current calendar
@param list list of timephased assignment data
@param first first planned assignment
@param last last completed assignment
@return list of timephased data ready for output
428638
private List<TimephasedWork> splitDays(ProjectCalendar calendar, List<TimephasedWork> list, TimephasedWork first, TimephasedWork last)
   {
      List<TimephasedWork> result = new LinkedList<TimephasedWork>();

      for (TimephasedWork assignment : list)
      {
         Date startDate = assignment.getStart();
         Date finishDate = assignment.getFinish();
         Date startDay = DateHelper.getDayStartDate(startDate);
         Date finishDay = DateHelper.getDayStartDate(finishDate);
         if (startDay.getTime() == finishDay.getTime())
         {
            Date startTime = calendar.getStartTime(startDay);
            Date currentStart = DateHelper.setTime(startDay, startTime);
            if (startDate.getTime() > currentStart.getTime())
            {
               boolean paddingRequired = true;

               if (last != null)
               {
                  Date lastFinish = last.getFinish();
                  if (lastFinish.getTime() == startDate.getTime())
                  {
                     paddingRequired = false;
                  }
                  else
                  {
                     Date lastFinishDay = DateHelper.getDayStartDate(lastFinish);
                     if (startDay.getTime() == lastFinishDay.getTime())
                     {
                        currentStart = lastFinish;
                     }
                  }
               }

               if (paddingRequired)
               {
                  Duration zeroHours = Duration.getInstance(0, TimeUnit.HOURS);
                  TimephasedWork padding = new TimephasedWork();
                  padding.setStart(currentStart);
                  padding.setFinish(startDate);
                  padding.setTotalAmount(zeroHours);
                  padding.setAmountPerDay(zeroHours);
                  result.add(padding);
               }
            }

            result.add(assignment);

            Date endTime = calendar.getFinishTime(startDay);
            Date currentFinish = DateHelper.setTime(startDay, endTime);
            if (finishDate.getTime() < currentFinish.getTime())
            {
               boolean paddingRequired = true;

               if (first != null)
               {
                  Date firstStart = first.getStart();
                  if (firstStart.getTime() == finishDate.getTime())
                  {
                     paddingRequired = false;
                  }
                  else
                  {
                     Date firstStartDay = DateHelper.getDayStartDate(firstStart);
                     if (finishDay.getTime() == firstStartDay.getTime())
                     {
                        currentFinish = firstStart;
                     }
                  }
               }

               if (paddingRequired)
               {
                  Duration zeroHours = Duration.getInstance(0, TimeUnit.HOURS);
                  TimephasedWork padding = new TimephasedWork();
                  padding.setStart(finishDate);
                  padding.setFinish(currentFinish);
                  padding.setTotalAmount(zeroHours);
                  padding.setAmountPerDay(zeroHours);
                  result.add(padding);
               }
            }
         }
         else
         {
            Date currentStart = startDate;
            boolean isWorking = calendar.isWorkingDate(currentStart);
            while (currentStart.getTime() < finishDate.getTime())
            {
               if (isWorking)
               {
                  Date endTime = calendar.getFinishTime(currentStart);
                  Date currentFinish = DateHelper.setTime(currentStart, endTime);
                  if (currentFinish.getTime() > finishDate.getTime())
                  {
                     currentFinish = finishDate;
                  }

                  TimephasedWork split = new TimephasedWork();
                  split.setStart(currentStart);
                  split.setFinish(currentFinish);
                  split.setTotalAmount(assignment.getAmountPerDay());
                  split.setAmountPerDay(assignment.getAmountPerDay());
                  result.add(split);
               }

               Calendar cal = DateHelper.popCalendar(currentStart);
               cal.add(Calendar.DAY_OF_YEAR, 1);
               currentStart = cal.getTime();
               isWorking = calendar.isWorkingDate(currentStart);
               if (isWorking)
               {
                  Date startTime = calendar.getStartTime(currentStart);
                  DateHelper.setTime(cal, startTime);
                  currentStart = cal.getTime();
               }
               DateHelper.pushCalendar(cal);
            }
         }
      }

      return result;
   }
557649
private void writeCalendars(Project project)
   {
      //
      // Create the new MSPDI calendar list
      //
      Project.Calendars calendars = m_factory.createProjectCalendars();
      project.setCalendars(calendars);
      List<Project.Calendars.Calendar> calendar = calendars.getCalendar();

      //
      // Process each calendar in turn
      //
      for (ProjectCalendar cal : m_projectFile.getCalendars())
      {
         calendar.add(writeCalendar(cal));
      }
   }
432955
private void writeCalendars(List<ProjectCalendar> records)
   {

      //
      // Write project calendars
      //
      for (ProjectCalendar record : records)
      {
         m_buffer.setLength(0);
         m_buffer.append("CLDR ");
         m_buffer.append(SDEFmethods.lset(record.getUniqueID().toString(), 2)); // 2 character used, USACE allows 1
         String workDays = SDEFmethods.workDays(record); // custom line, like NYYYYYN for a week
         m_buffer.append(SDEFmethods.lset(workDays, 8));
         m_buffer.append(SDEFmethods.lset(record.getName(), 30));
         m_writer.println(m_buffer);
      }
   }
614175
public static Calendar previous(Calendar self) {
        Calendar result = (Calendar) self.clone();
        result.add(Calendar.DATE, -1);
        return result;
    }
717942
@Override public List<TimephasedWork> getData()
   {
      if (m_raw)
      {
         m_normaliser.normalise(m_calendar, m_data);
         m_raw = false;
      }
      return m_data;
   }
88326
public void processCalendars(List<Row> rows)
   {
      for (Row row : rows)
      {
         processCalendar(row);
      }

      if (m_defaultCalendarID != null)
      {
         ProjectCalendar defaultCalendar = m_calMap.get(m_defaultCalendarID);
         // Primavera XER files can sometimes not contain a definition of the default
         // project calendar so only try to set if we find a definition.
         if (defaultCalendar != null)
         {
            m_project.setDefaultCalendar(defaultCalendar);
         }
      }
   }
1325570
private void processCalendarHours(ProjectCalendar calendar, Record dayRecord)
   {
      // ... for each day of the week
      Day day = Day.getInstance(Integer.parseInt(dayRecord.getField()));
      // Get hours
      List<Record> recHours = dayRecord.getChildren();
      if (recHours.size() == 0)
      {
         // No data -> not working
         calendar.setWorkingDay(day, false);
      }
      else
      {
         calendar.setWorkingDay(day, true);
         // Read hours
         ProjectCalendarHours hours = calendar.addCalendarHours(day);
         for (Record recWorkingHours : recHours)
         {
            addHours(hours, recWorkingHours);
         }
      }
   }
749189
public static int getNumberOfDays(Date first, Date second)
      {
          Calendar c = Calendar.getInstance();
          int result = 0;
          int compare = first.compareTo(second);
          if (compare > 0) return 0;
          if (compare == 0) return 1;

          c.setTime(first);
          int firstDay = c.get(Calendar.DAY_OF_YEAR);
          int firstYear = c.get(Calendar.YEAR);
          int firstDays = c.getActualMaximum(Calendar.DAY_OF_YEAR);

          c.setTime(second);
          int secondDay = c.get(Calendar.DAY_OF_YEAR);
          int secondYear = c.get(Calendar.YEAR);

          // if dates in the same year
          if (firstYear == secondYear)
          {
              result = secondDay-firstDay+1;
          }

          // different years
          else
          {
              // days from the first year
              result += firstDays - firstDay + 1;

              // add days from all years between the two dates years
              for (int i = firstYear+1; i< secondYear; i++)
              {
                  c.set(i,0,0);
                  result += c.getActualMaximum(Calendar.DAY_OF_YEAR);
              }

              // days from last year
              result += secondDay;
          }

          return result;
      }
307216
public void selectRange(final CalendarDay firstDay, final CalendarDay lastDay) {
    if (firstDay == null || lastDay == null) {
      return;
    } else if (firstDay.isAfter(lastDay)) {
      adapter.selectRange(lastDay, firstDay);
      dispatchOnRangeSelected(adapter.getSelectedDates());
    } else {
      adapter.selectRange(firstDay, lastDay);
      dispatchOnRangeSelected(adapter.getSelectedDates());
    }
  }
276499
public void layoutCalendar(Date dateTarget)
    {
        calendar.setTime(dateTarget);
        calendar.set(Calendar.HOUR_OF_DAY, 12);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        targetPanelDate = calendar.getTime();
        calendar.set(Calendar.DATE, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date dateFirstOfMonth = calendar.getTime();
        calendar.setTime(dateFirstOfMonth);
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.DATE, -1);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        Date dateLastOfMonth = calendar.getTime();
        Date dateCalendarFirstDate = this.getFirstDateInCalendar(dateFirstOfMonth);
        Date dateCalendar = new Date(dateCalendarFirstDate.getTime());

        targetComponent = (int)((targetDate.getTime() - dateCalendarFirstDate.getTime()) / KMS_IN_A_DAY);
        if (targetComponent < 0)
            targetComponent--;

        String strYear = this.getDateString(dateTarget, DateFormat.YEAR_FIELD);
        String strMonth = this.getDateString(dateTarget, DateFormat.MONTH_FIELD);
        monthLabel.setText(strMonth);
        yearLabel.setText(strYear);
        int iDayOfWeekComponent = 0;
        int iDayComponent = 7;
        for (; iDayComponent < panelDays.getComponentCount(); iDayOfWeekComponent++, iDayComponent++)
        {
            if (iDayOfWeekComponent < 7)
            {
                JLabel labelDayOfWeek = (JLabel)panelDays.getComponent(iDayOfWeekComponent);
                String strWeek = this.getDateString(dateCalendar, DateFormat.DAY_OF_WEEK_FIELD);
                if ((strWeek != null) && (strWeek.length() > 0))
                    labelDayOfWeek.setText(strWeek.substring(0, 1));
                else
                    labelDayOfWeek.setText(Integer.toString(iDayOfWeekComponent));
            }
            JLabel labelDay = (JLabel)panelDays.getComponent(iDayComponent);
            String strDay = this.getDateString(dateCalendar, DateFormat.DATE_FIELD);
            labelDay.setText(strDay);
            if ((dateCalendar.before(dateFirstOfMonth))
                || (dateCalendar.after(dateLastOfMonth)))
                    labelDay.setForeground(Color.GRAY);
            else
                    labelDay.setForeground(Color.BLACK);
            labelDay.setBackground(panelDays.getBackground());
            if (targetComponent == iDayComponent - 7)
                labelDay.setBorder(SELECTED_BORDER);
            else
                labelDay.setBorder(EMPTY_BORDER);

            calendar.setTime(dateCalendar);
            calendar.add(Calendar.DATE, 1);
            dateCalendar = calendar.getTime();

            if (firstTime)
            {
                labelDay.addMouseListener(this);
                labelDay.setName(Integer.toString(iDayComponent - 7));
            }
        }
        firstTime = false;
    }
663343
public static Calendar parseCalendar(final String calendar, final String format, final TimeZone timeZone) {
        if (N.isNullOrEmpty(calendar) || (calendar.length() == 4 && "null".equalsIgnoreCase(calendar))) {
            return null;
        }

        return createCalendar(parse(calendar, format, timeZone));
    }
1302597
public static List<Slice> split(LocalDate start, LocalDate end) {
        Objects.requireNonNull(start);
        Objects.requireNonNull(end);
        Preconditions.checkArgument(!start.isAfter(end));

        List<Slice> slices = Lists.newArrayList();

        LocalDate startOfMonth = start.withDayOfMonth(1);
        LocalDate endOfMonth = YearMonth.from(end).atEndOfMonth();

        do {
            slices.add(new Slice(startOfMonth, YearMonth.from(startOfMonth).atEndOfMonth()));
            startOfMonth = startOfMonth.plus(1, ChronoUnit.MONTHS);
        }
        while (startOfMonth.isBefore(endOfMonth) || startOfMonth.isEqual(endOfMonth));

        return slices;
    }
581309
public static Calendar previous(Calendar self) {
        Calendar result = (Calendar) self.clone();
        result.add(Calendar.DAY_OF_YEAR, -1);
        return result;
    }
1171940
public final void splitTo(AbstractNode<E> newNode, List<E> assignmentsToFirst, List<E> assignmentsToSecond) {
    assert (isLeaf() == newNode.isLeaf());
    deleteAllEntries();
    StringBuilder msg = LoggingConfiguration.DEBUG ? new StringBuilder(1000) : null;

    // assignments to this node
    for(E entry : assignmentsToFirst) {
      if(msg != null) {
        msg.append("n_").append(getPageID()).append(' ').append(entry).append('\n');
      }
      addEntry(entry);
    }

    // assignments to the new node
    for(E entry : assignmentsToSecond) {
      if(msg != null) {
        msg.append("n_").append(newNode.getPageID()).append(' ').append(entry).append('\n');
      }
      newNode.addEntry(entry);
    }
    if(msg != null) {
      Logging.getLogger(this.getClass()).fine(msg.toString());
    }
  }
993125
function Calendar(firstweekday) {
      this._firstweekday = typeof(firstweekday) === "undefined" ? 0 : firstweekday;

      if(firstweekday < 0 || firstweekday > 6) {
        throw new IllegalWeekdayError();
      }

      this._oneday = 1000 * 60 * 60 * 24;
      this._onehour = 1000 * 60 * 60;
    }
70100
public static Set<Calendar> toCalendarSet(final Set<Date> dates) {
        return dates.stream().map(Utils::getCal).collect(Collectors.toSet());
    }
404136
protected void mergeSameCost(LinkedList<TimephasedCost> list)
   {
      LinkedList<TimephasedCost> result = new LinkedList<TimephasedCost>();

      TimephasedCost previousAssignment = null;
      for (TimephasedCost assignment : list)
      {
         if (previousAssignment == null)
         {
            assignment.setAmountPerDay(assignment.getTotalAmount());
            result.add(assignment);
         }
         else
         {
            Number previousAssignmentCost = previousAssignment.getAmountPerDay();
            Number assignmentCost = assignment.getTotalAmount();

            if (NumberHelper.equals(previousAssignmentCost.doubleValue(), assignmentCost.doubleValue(), 0.01))
            {
               Date assignmentStart = previousAssignment.getStart();
               Date assignmentFinish = assignment.getFinish();
               double total = previousAssignment.getTotalAmount().doubleValue();
               total += assignmentCost.doubleValue();

               TimephasedCost merged = new TimephasedCost();
               merged.setStart(assignmentStart);
               merged.setFinish(assignmentFinish);
               merged.setAmountPerDay(assignmentCost);
               merged.setTotalAmount(Double.valueOf(total));

               result.removeLast();
               assignment = merged;
            }
            else
            {
               assignment.setAmountPerDay(assignment.getTotalAmount());
            }
            result.add(assignment);
         }

         previousAssignment = assignment;
      }

      list.clear();
      list.addAll(result);
   }