Package org.joda.time

Examples of org.joda.time.Duration


      }
      //**
//      log.debug("lastCalculatedTime "+lastCalculatedTime);


      final Duration timeElapsedDuration = timeElapsedVal == null ? null : timeElapsedVal.toDurationTo(new DateTime());
      long upTilNow = timeElapsedDuration == null ? 0 : timeElapsedDuration.getMillis();
      //**
//      log.warn("Elapsed time so far" + upTilNow);

      //**
//      log.debug("upTilNow "+upTilNow);

      final Duration elapsedTime = calculateElapsedTime(lastCalculatedTime, calculationTime, slaConfig.getSlaOperatingHours());
      //**
//      log.warn("Elapsed time since last calculation" + upTilNow);

      //**
//      log.debug("elapsedTime "+upTilNow);

      long elapsedTimeInMillis = upTilNow + elapsedTime.getMillis();
      //**
//      log.warn("Elapsed time since last calculation + prev elapsed time" + elapsedTimeInMillis);

      if (slaLastCalculated.hasValue(issue)) {
        slaLastCalculated.updateValue(null, issue, new ModifiedValue(slaLastCalculatedVal, calculationTime), new DefaultIssueChangeHolder());
        //**
//        log.warn("Updating last calculated time" + calculationTime);

      } else {
        slaLastCalculated.createValue(issue, calculationTime);
      }
      //**
//      log.debug("Updated sla last calculated time");

      final Duration duration = new Duration(elapsedTimeInMillis);
      final Period period = duration.toPeriodTo(new DateTime());
      if (timeElapsed.hasValue(issue)) {
        //**
//        log.warn("Updating total elapsed time to" + period);
        timeElapsed.updateValue(null, issue, new ModifiedValue(timeElapsedVal, period), new DefaultIssueChangeHolder());
      } else {
View Full Code Here


    if (fixKPI == null)
    {
      log.debug("No value for the fix kpi has been specified for client " + clientSLAConfig.getClientName() + " not applying a KPI to the client.");
      fixKPI = VERY_LARGE_SLA;
    }
    final Duration duration = getDurationForISOPeriod(fixKPI);
    slaInMillis = duration.getMillis()
    return slaInMillis;
  }
View Full Code Here

    if (responseSLA == null)
    {
      log.debug("No value for the response sla has been specified for client " + clientSLAConfig.getClientName() + " not applying an SLA to the client.");
      responseSLA = VERY_LARGE_SLA;
    }
    final Duration duration = getDurationForISOPeriod(responseSLA);
    slaInMillis = duration.getMillis()
 
    return slaInMillis;
  }
View Full Code Here

   * @param periodString
   * @return
   */
  private static Duration getDurationForISOPeriod(final String periodString) {
    final Period period = ISOPeriodFormat.standard().parsePeriod(periodString);
    final Duration duration = period.toDurationFrom(new DateTime());
    return duration;
  }
View Full Code Here

   * @param slaOperatingHours
   * @return
   */
  private static Duration calculateElapsedTime(Timestamp lastCalculatedTime, Timestamp calculationTime, int slaOperatingHours) {
    SLATimeCalculator calculator = new SLATimeCalculator();
    final Duration elapsedTime = calculator.calculateElapsedTime(lastCalculatedTime, calculationTime, slaOperatingHours);
    return elapsedTime;
  }
View Full Code Here

   */
  public Duration calculateElapsedTime(DateTime lastCalculated, DateTime now,
      int slaWorkingHours) {
    DateMidnight dateBeingProcessed = new DateMidnight(lastCalculated);
    Interval processingInterval = getEntireDayIntervalForDate(dateBeingProcessed);
    Duration duration = new Duration(null);
    while (processingInterval.contains(now)
        || processingInterval.isBefore(now)) {
      Interval workingHours = getWorkingIntervalForDate(
          dateBeingProcessed, slaWorkingHours);

      // process the day
      // if the last calculated date is within the current 24hours being
      // processed.
      if (processingInterval.contains(lastCalculated)) {
        // set start to last calc'd or start or working period if after
        // last calced
        if (workingHours.getStart().isAfter(lastCalculated)) {
          // leave start of working hours as is
        } else if (workingHours.contains(lastCalculated)) {
          workingHours = workingHours.withStart(lastCalculated);
        } else if (workingHours.getEnd().isBefore(lastCalculated)) {
          workingHours = new Interval(lastCalculated, lastCalculated); // zero
          // time
          // duration
        }
      }
      if (processingInterval.contains(now)) {
        // set end to now if now in working period
        if (workingHours.getStart().isAfter(now)) {
          workingHours = new Interval(now, now); // zero time duration
        } else if (workingHours.contains(now)) {
          workingHours = workingHours.withEnd(now);
        } else if (workingHours.getEnd().isBefore(now)) {
          // leave end of working hours as is
        }
      }
      duration = duration.plus(workingHours.toDuration());
      dateBeingProcessed = dateBeingProcessed.plusDays(1);
      processingInterval = getEntireDayIntervalForDate(dateBeingProcessed);
    }
    System.out.println(duration.toPeriod());
    return duration;
  }
View Full Code Here

  public void testStartBeforeEndInWorkingHours() {
    DateTime lastCalculated = new DateTime(2009, 6, 22, 8, 55, 0, 0);
    DateTime now = new DateTime(2009, 6, 22, 12, 00, 0, 0);

    Duration elapsedTime = calculator.calculateElapsedTime(lastCalculated, now, SLAWorkingHours.OFFICE_HOURS_9_TO_5_30);
    Assert.assertEquals("PT3H", elapsedTime.toPeriod().toString());
  }
View Full Code Here

  public void testStartBeforeEndAfterWorkingHours() {
    DateTime lastCalculated = new DateTime(2009, 6, 22, 8, 55, 0, 0);
    DateTime now = new DateTime(2009, 6, 22, 18, 00, 0, 0);

    Duration elapsedTime = calculator.calculateElapsedTime(lastCalculated, now, SLAWorkingHours.OFFICE_HOURS_9_TO_5_30);
    Assert.assertEquals("PT8H30M", elapsedTime.toPeriod().toString());
  }
View Full Code Here

  public void testStartInEndInWorkingHours() {
    DateTime lastCalculated = new DateTime(2009, 6, 22, 14, 05, 0, 0);
    DateTime now = new DateTime(2009, 6, 22, 14, 17, 0, 0);

    Duration elapsedTime = calculator.calculateElapsedTime(lastCalculated, now, SLAWorkingHours.OFFICE_HOURS_9_TO_5_30);
    Assert.assertEquals("PT12M", elapsedTime.toPeriod().toString());
  }
View Full Code Here

  public void testSpanTwoDaysOfOfficHoursA() {
    DateTime lastCalculated = new DateTime(2009, 6, 22, 9, 5, 0, 0);
    DateTime now = new DateTime(2009, 6, 24, 9, 5, 0, 0);

    Duration elapsedTime = calculator.calculateElapsedTime(lastCalculated, now, SLAWorkingHours.OFFICE_HOURS_9_TO_5_30);
    Assert.assertEquals("PT17H", elapsedTime.toPeriod().toString());
  }
View Full Code Here

TOP

Related Classes of org.joda.time.Duration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.