Example usage for org.joda.time Interval Interval

List of usage examples for org.joda.time Interval Interval

Introduction

In this page you can find the example usage for org.joda.time Interval Interval.

Prototype

public Interval(Object interval, Chronology chronology) 

Source Link

Document

Constructs a time interval by converting or copying from another object, overriding the chronology.

Usage

From source file:google.registry.monitoring.metrics.MetricPoint.java

License:Open Source License

/**
 * Returns a new {@link MetricPoint} representing a value at a specific {@link Instant}.
 *
 * <p>Callers should insure that the count of {@code labelValues} matches the count of labels for
 * the given metric./*w ww .j a v a2s.c  o  m*/
 */
static <V> MetricPoint<V> create(Metric<V> metric, ImmutableList<String> labelValues, Instant timestamp,
        V value) {
    MetricsUtils.checkLabelValuesLength(metric, labelValues);

    return new AutoValue_MetricPoint<>(metric, labelValues, new Interval(timestamp, timestamp), value);
}

From source file:google.registry.monitoring.metrics.MetricPoint.java

License:Open Source License

/**
 * Returns a new {@link MetricPoint} representing a value over an {@link Interval} from {@code
 * startTime} to {@code endTime}.//from w w w . j a  v  a 2 s.  co m
 *
 * <p>Callers should insure that the count of {@code labelValues} matches the count of labels for
 * the given metric.
 */
static <V> MetricPoint<V> create(Metric<V> metric, ImmutableList<String> labelValues, Instant startTime,
        Instant endTime, V value) {
    MetricsUtils.checkLabelValuesLength(metric, labelValues);

    return new AutoValue_MetricPoint<>(metric, labelValues, new Interval(startTime, endTime), value);
}

From source file:google.registry.tools.params.IntervalParameter.java

License:Open Source License

@Override
public Interval convert(String value) {
    // Interval.parse(null) creates an interval with both start and end times set to now.
    // Do something a little more reasonable.
    if (value == null) {
        throw new NullPointerException();
    }/*from  ww  w .ja  v  a  2s  .com*/
    Interval interval = Interval.parse(value);
    // Interval does not have a way to set the time zone, so create a new interval with the
    // start and end times of the parsed interval converted to UTC.
    return new Interval(interval.getStart().withZone(DateTimeZone.UTC),
            interval.getEnd().withZone(DateTimeZone.UTC));
}

From source file:graph.inference.module.LaterThanWorker.java

License:Open Source License

private Interval parseDate(DAGNode date, DateTime now) {
    String dateStr = date.toString();
    if (dateStr.equals("Now") || dateStr.equals("Now-Generally"))
        return new Interval(now.getMillis(), now.getMillis() + 1);
    if (dateStr.equals("Today-Indexical"))
        return new Interval(now.dayOfYear().roundFloorCopy(), now.dayOfYear().roundCeilingCopy());
    if (dateStr.equals("Tomorrow-Indexical")) {
        return new Interval(now.plusDays(1).dayOfYear().roundFloorCopy(),
                now.plusDays(1).dayOfYear().roundCeilingCopy());
    }//from www .  j a v  a 2  s.com
    if (dateStr.equals("Yesterday-Indexical")) {
        return new Interval(now.minusDays(1).dayOfYear().roundFloorCopy(),
                now.minusDays(1).dayOfYear().roundCeilingCopy());
    }
    if (dateStr.equals("TheYear-Indexical")) {
        return new Interval(now.year().roundFloorCopy(), now.year().roundCeilingCopy());
    }

    // Parse the date from the DAGNode
    String parsePattern = null;
    for (int i = DATE_PARSE_INTERVALS.length - 1; i >= 0; i--) {
        StringBuilder newPattern = new StringBuilder("(" + DATE_PARSE_INTERVALS[i]);
        if (parsePattern != null)
            newPattern.append(" " + parsePattern);
        newPattern.append(")");
        parsePattern = newPattern.toString();

        DateTimeFormatter dtf = DateTimeFormat.forPattern(parsePattern);
        try {
            DateTime dateTime = dtf.parseDateTime(dateStr);
            if (dateTime != null) {
                switch (i) {
                case 0:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusSeconds(1).minusMillis(1).getMillis());
                case 1:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusMinutes(1).minusMillis(1).getMillis());
                case 2:
                    return new Interval(dateTime.getMillis(), dateTime.plusHours(1).minusMillis(1).getMillis());
                case 3:
                    return new Interval(dateTime.getMillis(), dateTime.plusDays(1).minusMillis(1).getMillis());
                case 4:
                    return new Interval(dateTime.getMillis(),
                            dateTime.plusMonths(1).minusMillis(1).getMillis());
                case 5:
                    return new Interval(dateTime.getMillis(), dateTime.plusYears(1).minusMillis(1).getMillis());
                }
            }
        } catch (Exception e) {
        }
    }
    return null;
}

From source file:griffon.plugins.jodatime.editors.IntervalPropertyEditor.java

License:Apache License

private void handleAsList(List list) {
    switch (list.size()) {
    case 2://  w w  w . j  a  va  2 s  .  c o m
        long s = parseValue(list.get(0));
        long e = parseValue(list.get(1));
        super.setValueInternal(new Interval(s, e));
        break;
    default:
        throw illegalValue(list, Interval.class);
    }
}

From source file:griffon.plugins.jodatime.editors.IntervalPropertyEditor.java

License:Apache License

private void handleAsMap(Map map) {
    long s = getMapValue(map, "start", 0L);
    long e = getMapValue(map, "end", 0L);
    super.setValueInternal(new Interval(s, e));
}

From source file:internship.issuetracker.util.DateFormatUtil.java

public static String getFriendlyInterval(Date oldDate) {
    Interval interval = new Interval(new DateTime(oldDate), new DateTime(new Date()));
    TimeUtils time = new TimeUtils(interval, oldDate);
    time.createDate();/*  w  w  w  . j a va2 s . c o m*/
    return appendAgo(time.getResult(), time.getAgoFlag());
}

From source file:io.coala.dsol.util.DsolAccumulator.java

License:Apache License

/** helper method */
protected void updateValue() {
    final DateTime changeTime = getDateTime();
    if (!changeTime.isAfter(this.lastChangeTime))
        return;/*from w  ww  . j  a  v  a 2  s  .co  m*/
    final Interval interval = DsolUtil.crop(new Interval(this.lastChangeTime, changeTime), getTreatment());
    if (interval.getEndMillis() != changeTime.getMillis())
        LOG.warn(String.format("Cropped interval end time %s to %s", changeTime, interval));
    this.lastChangeTime = changeTime;

    final double oldRate = getRate().doubleValue();
    double deltaRate = oldRate;
    if (this.integrateMin != null && this.integrateMin.doubleValue() > deltaRate) {
        // LOG.trace("Integrating " + getRateTitle() + " with minimum "
        // + this.integrateMin);
        deltaRate = this.integrateMin.doubleValue();
    } else if (this.integrateMax != null && deltaRate > this.integrateMax.doubleValue()) {
        // LOG.trace("Integrating " + getRateTitle() + " with maximum "
        // + this.integrateMax);
        deltaRate = this.integrateMax.doubleValue();
    }
    final double deltaValue = DsolUtil
            .toTimeUnit(this.timeUnit, deltaRate * interval.toDurationMillis(), TimeUnitInterface.MILLISECOND)
            .doubleValue();
    addValue(deltaValue);
}

From source file:io.coala.dsol.util.DsolUtil.java

License:Apache License

/** @return the duration between this replication's warm-up and end dates */
public static Interval getWarmupInterval(final Treatment treatment) {
    return new Interval(toDateTime(0.0, treatment), toDateTime(treatment.getWarmupPeriod(), treatment));
}

From source file:io.coala.dsol.util.DsolUtil.java

License:Apache License

/** @return the duration between this replication's warm-up and end dates */
public static Interval getRunInterval(final Treatment treatment) {
    return new Interval(toDateTime(treatment.getWarmupPeriod(), treatment),
            toDateTime(treatment.getRunLength(), treatment));
}