List of usage examples for org.joda.time Interval getEnd
public DateTime 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./*from w w w . j av a 2 s . co 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 w ww .ja va 2s . c o 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 ava 2 s . c o m*/ 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 ww .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. *//*from ww w . ja v a 2 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 w w w . j a v a2s . c o m 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/*from ww w.j a v a 2 s .com*/ */ 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; }
From source file:com.yahoo.bard.webservice.util.DateTimeUtils.java
License:Apache License
/** * Converts an interval to a specified string format. * * @param interval interval to be formatted * @param formatter date time formatter for the * @param separator string to separate interval start and end * * @return formatted interval string//from w w w.ja va 2 s .c om */ public static String intervalToString(Interval interval, DateTimeFormatter formatter, String separator) { return interval.getStart().toString(formatter) + separator + interval.getEnd().toString(formatter); }
From source file:com.yahoo.bard.webservice.util.DateTimeUtils.java
License:Apache License
/** * Slices the intervals into smaller intervals of the timeGrain duration. * * @param interval interval to be sliced * @param timeGrain size of the slice//from ww w . j a va 2s .c o m * * @return list of intervals obtained by slicing the larger interval * * @throws java.lang.IllegalArgumentException if the interval is not an even multiple of the time grain */ public static List<Interval> sliceIntervals(Interval interval, TimeGrain timeGrain) { // TODO: Refactor me to use a Period DateTime intervalEnd = interval.getEnd(); DateTime sliceStart = interval.getStart(); DateTime periodStart = timeGrain.roundFloor(sliceStart); if (!sliceStart.equals(periodStart)) { LOG.info("Interval {} is not aligned to TimeGrain {} starting {}", interval, timeGrain, periodStart); throw new IllegalArgumentException("Interval must be aligned to the TimeGrain starting " + periodStart); } List<Interval> intervalSlices = new ArrayList<>(); while (sliceStart.isBefore(intervalEnd)) { // Find the end of the next slice DateTime sliceEnd = DateTimeUtils.addTimeGrain(sliceStart, timeGrain); // Make the next slice Interval slicedInterval = new Interval(sliceStart, sliceEnd); // Make sure that our slice is fully contained within our interval if (!interval.contains(slicedInterval)) { LOG.info("Interval {} is not a multiple of TimeGrain {}", interval, timeGrain); throw new IllegalArgumentException("Interval must be a multiple of the TimeGrain"); } // Add the slice intervalSlices.add(slicedInterval); // Move the slicer forward sliceStart = sliceEnd; } LOG.debug("Sliced interval {} into {} slices of {} grain", interval, intervalSlices.size(), timeGrain); return intervalSlices; }