コード例 #1
0
  // TOOD: SB chek location is the same!!!
  private List<Interval> getRecordedHourIntervals(List<RecordedHour> recHours) {
    List<Interval> intervals = new ArrayList<SBRecordedHoursHelper.Interval>();

    if (recHours.size() > 0) {
      RecordedHour currentIntervalStart = recHours.get(0);
      RecordedHour previousIntervalElm = recHours.get(0);
      RecordedHour currentIntervalEnd = null;

      for (int i = 1; i < recHours.size(); i++) {
        RecordedHour currentIntervalElm = recHours.get(i);

        if ((getDiffInMinutes(previousIntervalElm, currentIntervalElm) < 15)
            && previousIntervalElm.getName().equals(currentIntervalElm.getName())) {
          // continue
          if (i != (recHours.size() - 1)) {
            previousIntervalElm = currentIntervalElm;
          } else {
            // last elm
            currentIntervalEnd = currentIntervalElm;
            createNewInterval(intervals, currentIntervalStart, currentIntervalEnd);
          }
        } else {
          currentIntervalEnd = previousIntervalElm;
          createNewInterval(intervals, currentIntervalStart, currentIntervalEnd);

          // start next interval...
          currentIntervalStart = currentIntervalElm;
          previousIntervalElm = currentIntervalElm;
          currentIntervalEnd = null;
        }
      }
    }

    return intervals;
  }
コード例 #2
0
  private long getDiffInMinutes(RecordedHour previousIntervalElm, RecordedHour currentIntervalElm) {
    if (previousIntervalElm == null
        || previousIntervalElm.getTime() == null
        || currentIntervalElm == null
        || currentIntervalElm.getTime() == null) {
      return 0;
    }

    long time1 = previousIntervalElm.getTime().getTimeInMillis();
    long time2 = currentIntervalElm.getTime().getTimeInMillis();

    long diff = Math.abs(time2 - time1);

    long diffInMinutes = Math.round(diff / 1000 / 60);

    return diffInMinutes;
  }