Example usage for org.joda.time Interval getStart

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

Introduction

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

Prototype

public DateTime getStart() 

Source Link

Document

Gets the start of this time interval, which is inclusive, as a DateTime.

Usage

From source file:com.tkmtwo.timex.Intervals.java

License:Apache License

public static Interval noMillis(Interval i) {
    return new Interval(DateTimes.noMillis(i.getStart()), DateTimes.noMillis(i.getEnd()));
}

From source file:com.tkmtwo.timex.Intervals.java

License:Apache License

/**
 * Print the Interval in ISO basic format with no milliseconds
 * in the UTC time zone./*from  w w  w.  ja  va2  s. c  om*/
 *
 * The format is START/END with a slash in between.
 *
 * This is a good format to use for human-readable applications
 * like error messages or application logs.
 *
 * @param i an Interval value
 * @return a String value
 */
public static String printBasic(Interval i) {

    checkNotNull(i, "Input interval is null.");
    return DateTimes.getBasicFormatter().print(i.getStart()) + "/"
            + DateTimes.getBasicFormatter().print(i.getEnd());

}

From source file:com.tkmtwo.timex.Intervals.java

License:Apache License

/**
 * Print the Interval in ISO extended format with no milliseconds
 * in the UTC time zone.// ww w.ja  v  a 2  s.c o  m
 *
 * The format is START/END with a slash in between.
 *
 * This is a good format to use for human-readable applications
 * like error messages or application logs.
 *
 * @param i an Interval value
 * @return a String value
 */
public static String printExtended(Interval i) {

    checkNotNull(i, "Input interval is null.");
    return DateTimes.getExtendedFormatter().print(i.getStart()) + "/"
            + DateTimes.getExtendedFormatter().print(i.getEnd());

}

From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java

License:Open Source License

/**
 * Adds or deletes a displayable from the days its occupies
 * //from   ww  w .  jav  a2  s  .  co m
 * @param e
 * @param add
 */
protected void traverseDisplayable(Displayable e, Lambda<MonthDay> func) {
    // get and normalize the range of the disp
    Interval ival = e.getInterval();
    MutableDateTime startDay = new MutableDateTime(ival.getStart());
    MutableDateTime endDay = new MutableDateTime(ival.getEnd());
    endDay.setMillisOfDay(0);
    startDay.setMillisOfDay(0);

    // bound it inside this visible month
    if (startDay.isBefore(firstOnMonth))
        startDay = new MutableDateTime(firstOnMonth);
    if (endDay.isAfter(lastOnMonth))
        endDay = new MutableDateTime(lastOnMonth);

    // go from start to end and add it to all the days in the way
    while (!endDay.isBefore(startDay)) {
        MonthDay md = this.days.get(startDay.getDayOfYear());
        if (md != null)
            func.call(md);
        startDay.addDays(1);
    }
}

From source file:com.tmathmeyer.sentinel.ui.views.year.YearCalendar.java

License:Open Source License

@Override
public void updateDisplayable(Displayable event, boolean added) {
    Interval ival = event.getInterval();
    MutableDateTime start = new MutableDateTime(ival.getStart());

    while (start.isBefore(ival.getEnd())) {
        if (!added) {
            int day = start.getDayOfYear();
            Integer ec = this.events.get(day);
            int eventCount = (ec == null || ec <= 0) ? 0 : ec - 1;
            this.events.put(day, eventCount);
        } else {//from   www .  j  av  a2 s .com
            int day = start.getDayOfYear();
            Integer ec = this.events.get(day);
            int eventCount = (ec == null) ? 1 : ec + 1;
            this.events.put(day, eventCount);
        }
        start.addDays(1);
    }
}

From source file:com.wealdtech.jackson.modules.IntervalSerializer.java

License:Open Source License

@Override
public void serialize(final Interval value, final JsonGenerator gen, final SerializerProvider provider)
        throws IOException {
    gen.writeStartObject();//w  w  w  .j a v  a  2 s .c o  m
    gen.writeStringField("startdatetime", formatter.print(value.getStart()));
    gen.writeStringField("starttimezone", value.getStart().getZone().toString());
    gen.writeStringField("enddatetime", formatter.print(value.getEnd()));
    gen.writeStringField("endtimezone", value.getEnd().getZone().toString());
    gen.writeEndObject();
}

From source file:com.wealdtech.utils.IntervalOrdering.java

License:Open Source License

@Override
public int compare(final Interval left, final Interval right) {
    return ComparisonChain.start().compare(left.getStart(), right.getStart())
            .compare(left.getEnd(), right.getEnd()).result();
}

From source file:com.yahoo.bard.webservice.data.time.TimeGrain.java

License:Apache License

/**
 * Determines if this interval corresponds with time grain boundaries.
 *
 * @param interval  An interval to test against the time grain boundary
 *
 * @return true if the interval starts and stop on a time grain boundaries.
 *//*  w  w w . j  a v a2 s  . co m*/
default boolean aligns(Interval interval) {
    return aligns(interval.getStart()) && aligns(interval.getEnd());
}

From source file:com.yahoo.bard.webservice.metadata.DataSourceMetadata.java

License:Apache License

/**
 * Build the range set of intervals for the entries.
 *
 * @param entries  Entries to build the intervals for
 * @param interval  Interval to add to each of the entries
 * @param container  Map into which to build the interval sets
 *///from www .  j  a v a  2s .com
private static void buildRangeSet(List<String> entries, Interval interval,
        Map<String, RangeSet<DateTime>> container) {
    entries.stream().map(entry -> container.computeIfAbsent(entry, ignored -> TreeRangeSet.create()))
            .forEach(set -> set.add(Range.closedOpen(interval.getStart(), interval.getEnd())));
}

From source file:com.yahoo.bard.webservice.util.DateTimeUtils.java

License:Apache License

/**
 * Merge all contiguous and overlapping intervals in a set together and return the set with the merged intervals.
 *
 * @param unmergedIntervals A set of intervals that may abut or overlap
 *
 * @return The set of merged intervals//  w  w w .  ja va  2s. c om
 */
public static Set<Interval> mergeIntervalSet(Set<Interval> unmergedIntervals) {
    // Create a self sorting set of intervals
    TreeSet<Interval> sortedIntervals = new TreeSet<>(IntervalStartComparator.INSTANCE);

    for (Interval mergingInterval : unmergedIntervals) {
        Iterator<Interval> it = sortedIntervals.iterator();
        while (it.hasNext()) {
            Interval sortedInterval = it.next();
            if (mergingInterval.overlaps(sortedInterval) || mergingInterval.abuts(sortedInterval)) {
                // Remove the interval being merged with
                it.remove();
                // find start and end of new interval
                DateTime start = (mergingInterval.getStart().isBefore(sortedInterval.getStart()))
                        ? mergingInterval.getStart()
                        : sortedInterval.getStart();
                DateTime end = (mergingInterval.getEnd().isAfter(sortedInterval.getEnd()))
                        ? mergingInterval.getEnd()
                        : sortedInterval.getEnd();
                mergingInterval = new Interval(start, end);
            }
        }
        sortedIntervals.add(mergingInterval);
    }
    return sortedIntervals;
}