Package org.joda.time

Examples of org.joda.time.Duration


      preferred = new ArrayList<Weight>();
    }
   
    // get the duration of the activity
    Long durationLong = activity.withConstraints().withTime().getDuration();
    Duration duration = null;
    if (durationLong != null) {
      duration = new Duration(durationLong);
    } else {
      // TODO: give error when duration is not defined?
      duration = Duration.standardHours(1);
    }
   
View Full Code Here


        return rc;
    }

    private static void printScriptRunTime(DateTime startTime) {
        DateTime endTime = new DateTime();
        Duration duration = new Duration(startTime, endTime);
        Period period = duration.toPeriod().normalizedStandard(PeriodType.time());
        log.info("Pig script completed in "
                + PeriodFormat.getDefault().print(period)
                + " (" + duration.getMillis() + " ms)");
    }
View Full Code Here

    try {
      if ( dt == null ) {
        dt = new DateTime();
        return true;
      }
      Duration interval = new Duration(dt, new Instant());
      dt = new DateTime();
      //  check if filter called within an interval of 1 second or less. If so, we
      //  just detected a blast. Return false to invalidate the route and dispose the
      //  message
      if ( interval.isShorterThan(Duration.standardSeconds(1)) ) {
        //System.out.println("...... BlasTGuard ON ... Disposing Message .... Interval Since the Last Message:"+interval.toString());
        logger.warn(methodName, null,"...... BlasTGuard ON ... Disposing Message .... Interval Since the Last Message:"+interval.toString());
        return false;
      }
      result = true;
    } catch( Throwable e) {
      e.printStackTrace();
View Full Code Here

     * @param timestamp the timestamp specified on the request (in standard ISO8601 format)
     * @return true if the timestamp is valid
     */
    private boolean validateTimestamp(String timestamp) {
        DateTime requestTime = TimeUtils.parse(timestamp);
        long difference = Math.abs(new Duration(requestTime, nowInUTC()).getMillis());
        return difference <= allowedTimestampRange;
    }
View Full Code Here

        }
      }
      catch (IOException | ChannelException e) {
        log.warn(e, "Exception submitting action for task[%s]", task.getId());

        final Duration delay = retryPolicy.getAndIncrementRetryDelay();
        if (delay == null) {
          throw e;
        } else {
          try {
            final long sleepTime = delay.getMillis();
            log.info("Will try again in [%s].", new Duration(sleepTime).toString());
            Thread.sleep(sleepTime);
          }
          catch (InterruptedException e2) {
            throw Throwables.propagate(e2);
          }
View Full Code Here

    // -1 (in past), 1d, 4d, 1w, 2w, 1m, 2m, -
    private String getUpfrontReservationTime(Long dateInMillis) {
        DateTime now = new DateTime(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC")));
        DateTime event = new DateTime(dateInMillis, DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC")));
        Duration duration = new Duration(now, event);

        if (duration.getMillis() < 0) {
            return "-1";
        } else if (duration.getStandardSeconds() < 86400) {
            return "1d";
        } else if (duration.getStandardDays() < 4) {
            return "4d";
        } else if (duration.getStandardDays() < 7) {
            return "1w";
        } else if (duration.getStandardDays() < 14) {
            return "2w";
        } else if (duration.getStandardDays() < 28) {
            return "4w";
        } else if (duration.getStandardDays() < 56) {
            return "8w";
        } else {
            return "-";
        }
    }
View Full Code Here

 
  public void test247SLAA() {
    DateTime lastCalculated = new DateTime(2009, 6, 19, 19, 0, 0, 0);
    DateTime now = new DateTime(2009, 6, 19, 21, 0, 0, 0);

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

  public void test247SLAB() {
    DateTime lastCalculated = new DateTime(2009, 6, 19, 19, 0, 0, 0);
    DateTime now = new DateTime(2009, 6, 26, 21, 5, 0, 0);

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

 
  public void testStringToDurationConversion() {
   
    final String responseSLA = "PT8H30M";
    final Period period = ISOPeriodFormat.standard().parsePeriod(responseSLA);
    final Duration duration = period.toDurationFrom(new DateTime());
    System.out.println(duration);
  }
View Full Code Here

    {
            return null;
    }
        assertObjectImplementsType(Period.class, customFieldObject);
        Period period = (Period) customFieldObject;
        final Duration durationFrom = period.toDurationFrom(new DateTime());
    final Double dbVal = new Double(durationFrom.getMillis());

    return dbVal;
  }
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.