Example usage for org.joda.time Interval getEnd

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

Introduction

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

Prototype

public DateTime getEnd() 

Source Link

Document

Gets the end of this time interval, which is exclusive, as a DateTime.

Usage

From source file:com.almende.eve.agent.MeetingAgent.java

License:Apache License

/**
 * Gets the office hours.//from   w w w  . ja  v a  2 s  . c  o m
 * 
 * @param timeMin
 *            the time min
 * @param timeMax
 *            the time max
 * @return the office hours
 */
public ArrayNode getOfficeHours(@Name("timeMin") final String timeMin, @Name("timeMax") final String timeMax) {
    final List<Interval> available = IntervalsUtil.getOfficeHours(new DateTime(timeMin), new DateTime(timeMax));

    // convert to JSON array
    final ArrayNode array = JOM.createArrayNode();
    for (final Interval interval : available) {
        final ObjectNode obj = JOM.createObjectNode();
        obj.put("start", interval.getStart().toString());
        obj.put("end", interval.getEnd().toString());
        array.add(obj);
    }
    return array;
}

From source file:com.almende.pi5.common.PowerTimeLine.java

License:Apache License

/**
 * Make this TL discrete, returning the TL;
 * As a side effect, removes values outside the start and end times.
 *
 * @param start/*  www  . ja v  a  2  s. co  m*/
 *            the start
 * @param end
 *            the end
 * @param stepSize
 *            the step size
 * @return this
 */
@JsonIgnore
public PowerTimeLine discrete(final DateTime start, final DateTime end, final Duration stepSize) {
    final PowerTimeLine newTL = new PowerTimeLine();
    newTL.timestamp = this.timestamp;
    final ArrayList<PowerTime> steps = new ArrayList<PowerTime>();

    long offset = new Duration(timestamp, start).getMillis();
    Interval interval = stepSize.toIntervalFrom(start);
    while (interval.getEnd().isBefore(end) || interval.getEnd().isEqual(end)) {
        steps.add(new PowerTime(offset, 0));
        offset += interval.toDurationMillis();
        interval = stepSize.toIntervalFrom(timestamp.plusMillis((int) offset));
    }
    newTL.setSeries(steps);
    this.add(newTL).zeroBefore(start).zeroFrom(end);

    final Duration diff = new Duration(start, end);
    if (series.size() > (diff.getMillis() / stepSize.getMillis())) {
        int index = 0;
        long expectedOffset = new Duration(timestamp, start).getMillis() + stepSize.getMillis();
        while (index < series.size() - 1) {
            PowerTime pt = series.get(index);
            ArrayList<PowerTime> temp = new ArrayList<PowerTime>();

            int nextIndex = index + 1;
            PowerTime next = series.get(nextIndex);
            while (next.getOffset() < expectedOffset) {
                temp.add(next);
                series.remove(nextIndex);
                if (nextIndex == series.size()) {
                    break;
                }
                next = series.get(nextIndex);
            }
            if (temp.size() > 0) {
                temp.add(0, pt);
                double integral = getIntegral(pt.getOffset(), pt.getOffset() + stepSize.getMillis(), temp);
                series.set(index, new PowerTime(pt.getOffset(), integral / stepSize.getMillis()));
            }
            index++;
            expectedOffset += stepSize.getMillis();
        }
    }

    return this;
}

From source file:com.anasoft.os.daofusion.bitemporal.PersistentInterval.java

License:Apache License

public Object getPropertyValue(Object component, int property) throws HibernateException {
    Interval interval = (Interval) component;
    return (property == 0) ? interval.getStart().toDate() : interval.getEnd().toDate();
}

From source file:com.anasoft.os.daofusion.bitemporal.PersistentInterval.java

License:Apache License

public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    if (value == null) {
        statement.setNull(index, Hibernate.TIMESTAMP.sqlType());
        statement.setNull(index + 1, Hibernate.TIMESTAMP.sqlType());
        return;//from   w ww . j a  v a2  s  . co  m
    }
    Interval interval = (Interval) value;
    statement.setTimestamp(index, asTimeStamp(interval.getStart()));
    statement.setTimestamp(index + 1, asTimeStamp(interval.getEnd()));
}

From source file:com.excilys.ebi.bank.dao.impl.OperationDaoImpl.java

License:Apache License

private BooleanExpression addOperationYearMonthExpression(BooleanExpression predicate, QOperation operation,
        YearMonth yearMonth) {/*from   w  w  w  .  j av a  2 s .c o  m*/

    if (yearMonth == null)
        return predicate;
    else {
        Interval range = yearMonth.toInterval();
        return predicate.and(operation.date.between(range.getStart(), range.getEnd()));
    }
}

From source file:com.flipkart.foxtrot.core.querystore.impl.ElasticsearchUtils.java

License:Apache License

@VisibleForTesting
public static String[] getIndices(final String table, final ActionRequest request, final Interval interval) {
    DateTime start = interval.getStart().toLocalDate().toDateTimeAtStartOfDay();
    if (start.getYear() <= 1970) {
        logger.warn("Request of type {} running on all indices", request.getClass().getSimpleName());
        return new String[] { getIndices(table) };
    }/*from  www  .  java 2  s . c o m*/
    List<String> indices = Lists.newArrayList();
    final DateTime end = interval.getEnd().plusDays(1).toLocalDate().toDateTimeAtStartOfDay();
    while (start.getMillis() < end.getMillis()) {
        final String index = getCurrentIndex(table, start.getMillis());
        indices.add(index);
        start = start.plusDays(1);
    }
    logger.info("Request of type {} on indices: {}", request.getClass().getSimpleName(), indices);
    return indices.toArray(new String[indices.size()]);
}

From source file:com.github.dbourdette.otto.data.DataTableUtils.java

License:Apache License

/**
 * Finds best Duration of rows for a {@link SimpleDataTable} based on given table interval
 *//* w  w  w .j  a v a 2 s .  co m*/
public static Duration findBest(Interval interval) {
    Duration duration = new Duration(interval.getStart(), interval.getEnd());

    if (duration.isShorterThan(ONE_DAY) || duration.equals(ONE_DAY)) {
        return Duration.standardMinutes(5);
    } else if (duration.isShorterThan(FIVE_DAYS) || duration.equals(FIVE_DAYS)) {
        return Duration.standardMinutes(30);
    } else {
        return Duration.standardDays(1);
    }
}

From source file:com.github.dbourdette.otto.data.SimpleDataTable.java

License:Apache License

public void setupRows(Interval interval, Duration step) {
    rows.clear();//w  ww  .  ja v  a2 s .  c om

    DateTime current = interval.getStart();

    while (current.isBefore(interval.getEnd())) {
        rows.add(new SimpleDataTableRow(new Interval(current, step)));

        current = current.plus(step);
    }
}

From source file:com.google.sampling.experiential.server.DSQueryBuilder.java

License:Open Source License

private void compareDateRange(String key, String range, DateTimeZone jodaTimeZone) {
    DateTime startDate = null;/*  w  w  w . j  a  v  a 2  s .  c  o  m*/
    DateTime endDate = null;

    boolean keyCannedDateRange = isKeyCannedDateRange(key);
    boolean rangeCannedDateRange = isCannedDateRange(range);
    if (keyCannedDateRange || rangeCannedDateRange) {
        String rangeName = null;
        if (keyCannedDateRange) {
            rangeName = key.substring(1);
        } else {
            rangeName = range;
        }
        Interval interval;
        if (rangeName.equals("last_week")) {
            interval = getLastWeek(jodaTimeZone);
        } else if (rangeName.equals("last_month")) {
            interval = getLast4Weeks(jodaTimeZone);
        } else {
            throw new IllegalArgumentException("Unknown date range");
        }
        startDate = interval.getStart();
        endDate = interval.getEnd().plusDays(1);

    } else {
        Iterable<String> iterable = Splitter.on("-").split(range);
        Iterator<String> iter = iterable.iterator();
        if (!iter.hasNext()) {
            throw new IllegalArgumentException("Illformed Date Range: " + range);
        }
        String firstDate = iter.next();
        String secondDate = null;
        if (iter.hasNext()) {
            secondDate = iter.next();
        }

        startDate = newDateTimeFromString(firstDate, jodaTimeZone);
        endDate = null;
        if (secondDate != null && !secondDate.isEmpty()) {
            endDate = newDateTimeFromString(secondDate, jodaTimeZone).plusDays(1);
        } else {
            endDate = startDate.plusDays(1);
        }
    }
    jdoQuery.addFilters("when >= startDateParam", "when <= endDateParam");
    jdoQuery.declareParameters("java.util.Date startDateParam", "java.util.Date endDateParam");
    jdoQuery.addParameterObjects(startDate.toDate(), endDate.toDate());
}

From source file:com.google.sampling.experiential.server.JDOQueryBuilder.java

License:Open Source License

private void compareDateRange(String key, String range, DateTimeZone jodaTimeZone) {
    DateTime startDate = null;/* w w w  .j a va  2  s.com*/
    DateTime endDate = null;

    boolean keyCannedDateRange = isKeyCannedDateRange(key);
    boolean rangeCannedDateRange = isCannedDateRange(range);
    if (keyCannedDateRange || rangeCannedDateRange) {
        String rangeName = null;
        if (keyCannedDateRange) {
            rangeName = key.substring(1);
        } else {
            rangeName = range;
        }
        Interval interval;
        if (rangeName.equals("last_week")) {
            interval = getLastWeek(jodaTimeZone);
        } else if (rangeName.equals("last_month")) {
            interval = getLast4Weeks(jodaTimeZone);
        } else {
            throw new IllegalArgumentException("Unknown date range");
        }
        startDate = interval.getStart();
        endDate = interval.getEnd().plusDays(1);

    } else {
        Iterable<String> iterable = Splitter.on("-").split(range);
        Iterator<String> iter = iterable.iterator();
        if (!iter.hasNext()) {
            throw new IllegalArgumentException("Illformed Date Range: " + range);
        }
        String firstDate = iter.next();
        String secondDate = null;
        if (iter.hasNext()) {
            secondDate = iter.next();
        }

        startDate = newDateTimeFromDateString(firstDate, jodaTimeZone);
        endDate = null;
        if (secondDate != null && !secondDate.isEmpty()) {
            endDate = newDateTimeFromDateString(secondDate, jodaTimeZone).plusDays(1);
        } else {
            endDate = startDate.plusDays(1);
        }
    }
    jdoQuery.addFilters("when >= startDateParam", "when <= endDateParam");
    jdoQuery.declareParameters("java.util.Date startDateParam", "java.util.Date endDateParam");
    jdoQuery.addParameterObjects(startDate.toDate(), endDate.toDate());
}