List of usage examples for org.joda.time DateTime property
public Property property(DateTimeFieldType type)
From source file:org.apereo.portal.events.aggr.AggregationInterval.java
License:Apache License
/** * Determine the starting DateTime (inclusive) of an interval based on an instant in time * * @param instant The instant in time to get the interval starting value for * @return The start of this interval in relation to the provided instant *//*from w w w. j a v a2 s . com*/ public DateTime determineStart(DateTime instant) { if (this.dateTimeFieldType != null) { return instant.property(this.dateTimeFieldType).roundFloorCopy(); } if (this == AggregationInterval.FIVE_MINUTE) { return instant.hourOfDay().roundFloorCopy().plusMinutes((instant.getMinuteOfHour() / 5) * 5); } throw new IllegalArgumentException("Cannot compute interval start time for " + this + " please use " + AggregationIntervalHelper.class); }
From source file:org.apereo.portal.events.aggr.AggregationInterval.java
License:Apache License
/** * Determine the ending DateTime (exclusive) of an interval based on an instant in time * * @param instant The start of an instant * @return// w w w. j a v a 2s . c om */ public DateTime determineEnd(DateTime instant) { if (this.dateTimeFieldType != null) { final DateTime start = instant.property(this.dateTimeFieldType).roundFloorCopy(); return start.property(this.dateTimeFieldType).addToCopy(1); } if (this == AggregationInterval.FIVE_MINUTE) { final DateTime start = instant.hourOfDay().roundFloorCopy() .plusMinutes((instant.getMinuteOfHour() / 5) * 5); return start.plusMinutes(5); } throw new IllegalArgumentException( "Cannot compute interval end time for " + this + " please use " + AggregationIntervalHelper.class); }
From source file:org.sleuthkit.autopsy.timeline.utils.RangeDivisionInfo.java
License:Open Source License
/** * Static factory method./*from w w w.j a v a 2 s .c o m*/ * * Determine the period size, number of periods, whole period bounds, and * formatters to use to visualize the given timerange. * * @param timeRange * * @return */ public static RangeDivisionInfo getRangeDivisionInfo(Interval timeRange) { //Check from largest to smallest unit //TODO: make this more generic... reduce code duplication -jm DateTimeFieldType timeUnit; final DateTime startWithZone = timeRange.getStart().withZone(TimeLineController.getJodaTimeZone()); final DateTime endWithZone = timeRange.getEnd().withZone(TimeLineController.getJodaTimeZone()); if (Years.yearsIn(timeRange).isGreaterThan(Years.THREE)) { timeUnit = DateTimeFieldType.year(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Years.yearsIn(timeRange).get(timeUnit.getDurationType()) + 1, TimeUnits.YEARS, ISODateTimeFormat.year(), lower, upper); } else if (Months.monthsIn(timeRange).isGreaterThan(Months.THREE)) { timeUnit = DateTimeFieldType.monthOfYear(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Months.monthsIn(timeRange).getMonths() + 1, TimeUnits.MONTHS, DateTimeFormat.forPattern("YYYY'-'MMMM"), lower, upper); // NON-NLS } else if (Days.daysIn(timeRange).isGreaterThan(Days.THREE)) { timeUnit = DateTimeFieldType.dayOfMonth(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Days.daysIn(timeRange).getDays() + 1, TimeUnits.DAYS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd"), lower, upper); // NON-NLS } else if (Hours.hoursIn(timeRange).isGreaterThan(Hours.THREE)) { timeUnit = DateTimeFieldType.hourOfDay(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Hours.hoursIn(timeRange).getHours() + 1, TimeUnits.HOURS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH"), lower, upper); // NON-NLS } else if (Minutes.minutesIn(timeRange).isGreaterThan(Minutes.THREE)) { timeUnit = DateTimeFieldType.minuteOfHour(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Minutes.minutesIn(timeRange).getMinutes() + 1, TimeUnits.MINUTES, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm"), lower, upper); // NON-NLS } else { timeUnit = DateTimeFieldType.secondOfMinute(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Seconds.secondsIn(timeRange).getSeconds() + 1, TimeUnits.SECONDS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm':'ss"), lower, upper); // NON-NLS } }
From source file:TVShowTimelineMaker.timeConstraints.FieldChangeConstraint.java
public Event[] increaseWhat(DateTime inFirstDay, DateTime inSecondDay) { this.makeToPeriodIfNull(); DateTime minForFirstEvent = inSecondDay.minus(this.toPeriod); DateTime minForSecondEvent = inFirstDay.plus(this.toPeriod); if (this.lowerFields == null) { this.lowerFields = lowerFields(this.mDateTimeFieldType); }/*from w ww. j ava2 s . co m*/ for (DateTimeFieldType curDateTimeFieldType : this.lowerFields) { minForFirstEvent = minForFirstEvent.property(curDateTimeFieldType).withMinimumValue(); minForSecondEvent = minForSecondEvent.property(curDateTimeFieldType).withMinimumValue(); } if (inFirstDay.isBefore(minForFirstEvent)) { return new Event[] { this.firstEpisode }; } else if (inSecondDay.isBefore(minForSecondEvent)) { return new Event[] { this.secondEpisode }; } else { return new Event[] {}; } }
From source file:TVShowTimelineMaker.timeConstraints.FieldChangeConstraint.java
@Override public boolean applyConstraint() { boolean changed = false; this.makeToPeriodIfNull(); DateTime minForFirstEvent = this.secondEpisode.getEarliestPossibleStartTime().minus(this.toPeriod); DateTime minForSecondEvent = this.firstEpisode.getEarliestPossibleStartTime().plus(this.toPeriod); DateTime maxForFirstEvent = this.secondEpisode.getLatestPossibleEndTime().minus(this.toPeriod); DateTime maxForSecondEvent = this.firstEpisode.getLatestPossibleEndTime().plus(this.toPeriod); if (this.lowerFields == null) { this.lowerFields = lowerFields(this.mDateTimeFieldType); }/*from ww w. jav a2s. c o m*/ for (DateTimeFieldType curDateTimeFieldType : this.lowerFields) { minForFirstEvent = minForFirstEvent.property(curDateTimeFieldType).withMinimumValue(); minForSecondEvent = minForSecondEvent.property(curDateTimeFieldType).withMinimumValue(); maxForFirstEvent = maxForFirstEvent.property(curDateTimeFieldType).withMaximumValue(); maxForSecondEvent = maxForSecondEvent.property(curDateTimeFieldType).withMaximumValue(); } if (!this.firstEpisode.isAfter(minForFirstEvent)) { changed = this.firstEpisode.setAfter(minForFirstEvent) || changed; } if (!this.secondEpisode.isAfter(minForSecondEvent)) { changed = this.secondEpisode.setAfter(minForSecondEvent) || changed; } if (!this.firstEpisode.isBefore(maxForFirstEvent)) { changed = this.firstEpisode.setBefore(maxForFirstEvent) || changed; } if (!this.secondEpisode.isBefore(maxForSecondEvent)) { changed = this.secondEpisode.setBefore(maxForSecondEvent) || changed; } return changed; }