Package org.joda.time

Examples of org.joda.time.Duration


            from = DateTime.parse(histogram.getHistogramBoundaries().getFrom());
        }
        final DateTime to = DateTime.parse(histogram.getHistogramBoundaries().getTo());
        final MutableDateTime currentTime = new MutableDateTime(from);

        final Duration step = estimateIntervalStep(histogram.getInterval());
        final int dataPoints = (int) ((to.getMillis() - from.getMillis()) / step.getMillis());

        // using the absolute value guarantees, that there will always be enough values for the given resolution
        final int factor = (maxDataPoints != -1 && dataPoints > maxDataPoints) ? dataPoints / maxDataPoints : 1;

        int index = 0;
View Full Code Here


                throw new IllegalArgumentException("Invalid duration specified: " + interval);
        }
    }

    private Duration estimateIntervalStep(String interval) {
        Duration step;
        switch (interval) {
            case "minute":
                step = Minutes.ONE.toStandardDuration();
                break;
            case "hour":
View Full Code Here

   
    public void testGetDurationConverter() {
        DurationConverter c = ConverterManager.getInstance().getDurationConverter(new Long(0L));
        assertEquals(Long.class, c.getSupportedType());
       
        c = ConverterManager.getInstance().getDurationConverter(new Duration(123L));
        assertEquals(ReadableDuration.class, c.getSupportedType());
       
        c = ConverterManager.getInstance().getDurationConverter(new Interval(0L, 1000L));
        assertEquals(ReadableInterval.class, c.getSupportedType());
       
View Full Code Here

   
    public void testGetPeriodConverter() {
        PeriodConverter c = ConverterManager.getInstance().getPeriodConverter(new Period(1, 2, 3, 4, 5, 6, 7, 8));
        assertEquals(ReadablePeriod.class, c.getSupportedType());
       
        c = ConverterManager.getInstance().getPeriodConverter(new Duration(123L));
        assertEquals(ReadableDuration.class, c.getSupportedType());
       
        c = ConverterManager.getInstance().getPeriodConverter(new Interval(0L, 1000L));
        assertEquals(ReadableInterval.class, c.getSupportedType());
       
View Full Code Here

        assertEquals(ReadableDuration.class, ReadableDurationConverter.INSTANCE.getSupportedType());
    }

    //-----------------------------------------------------------------------
    public void testGetDurationMillis_Object() throws Exception {
        assertEquals(123L, ReadableDurationConverter.INSTANCE.getDurationMillis(new Duration(123L)));
    }
View Full Code Here

    }

    //-----------------------------------------------------------------------
    public void testGetPeriodType_Object() throws Exception {
        assertEquals(PeriodType.standard(),
            ReadableDurationConverter.INSTANCE.getPeriodType(new Duration(123L)));
    }
View Full Code Here

            ReadableDurationConverter.INSTANCE.getPeriodType(new Duration(123L)));
    }

    public void testSetInto_Object() throws Exception {
        MutablePeriod m = new MutablePeriod(PeriodType.yearMonthDayTime());
        ReadableDurationConverter.INSTANCE.setInto(m, new Duration(
            3L * DateTimeConstants.MILLIS_PER_DAY +
            4L * DateTimeConstants.MILLIS_PER_MINUTE + 5L
        ), null);
        assertEquals(0, m.getYears());
        assertEquals(0, m.getMonths());
View Full Code Here

     *
     * @param nonceValue
     */
    private void validateNonce(String nonceValue) {
        Nonce nonce = nonceCache.getUnchecked(nonceValue);
        Duration tolerance = new Duration(nonce.timestamp, new DateTime());
        if (tolerance.isLongerThan(Duration.millis(NONCE_CHECK_TOLERANCE_IN_MILLIS))) {
            LOG.error("Nonce value was not unique: {}", nonceValue);
            throw new AuthorizationException("Nonce value is not unique");
        }
    }
View Full Code Here

  @Test
  public void convertShouldReturnTheDurationInMillisecondsIfTheLastSegmentOfThePathIsADuration()
      throws Exception {
    long expectedMillis = 19L;
    TreePath path = new TreePath(new Object[]{"a", new Duration(expectedMillis)});
    assertThat(converter.convert(path), is(expectedMillis));
  }
View Full Code Here

    assertThat(converter.convert(path), is(expectedMillis));
  }

  @Test
  public void convertShouldReturn0IfTheDurationElementIsNotTheLastSegmentOfThePath() {
    TreePath path = new TreePath(new Object[]{new Duration(10L), "a"});
    assertThat(converter.convert(path), is(0L));
  }
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.