/** * Return the maximum value of a field, closest to the reference time */ public static int maximumValue(DateTimeFieldType type, ReadableDateTime reference){ return reference.toDateTime().property(type).getMaximumValue(); }
/** * Return the minimum value of a field, closest to the reference time */ public static int minimumValue(DateTimeFieldType type, ReadableDateTime reference){ return reference.toDateTime().property(type).getMinimumValue(); } /**
/** * Gets the start instant given the event instant, interval length * and the time zone for this interval type. * * @param instant the event time instant. * @param length the interval length * * @return the start instant of the interval of given length that contains * the supplied time instant in the supplied time zone */ public DateTime getTimeIntervalStart(DateTime instant, long length) { validateValue(instant.getZone(), length); // Reset all the fields DateTime periodStart = instant.property(truncateFieldType) .roundFloorCopy(); // figure out the which time interval does the instant lie in Period period = new Period(periodStart, instant, periodType); DurationField durationField = fieldType.getField(instant.getChronology()).getDurationField(); int diff = period.get(durationField.getType()); long startDelta = (diff / length) * length; return periodStart.withFieldAdded(durationField.getType(), FieldUtils.safeToInt(startDelta)); }
int year = 2012; DateTime dt = new DateTime(year, 01, 01, 00, 00, 00, 00); for (int i = 0; i < 12; i++) { System.out.println(dt.toString() + " " + dt.property(DateTimeFieldType.dayOfWeek()).getAsText()); dt = dt.plusMonths(1); }
public static int[] getValues(org.joda.time.DateTime dt, int numElements) { List<Integer> values = new ArrayList<Integer>(); for (int i = 0; i < numElements; ++i) { values.add(dt.property(DateTime.getField(i)).get()); } return values.stream().mapToInt(i -> i).toArray(); }
/** * Return the maximum value of a field, closest to the reference time */ public static int maximumValue(DateTimeFieldType type, ReadableDateTime reference){ return reference.toDateTime().property(type).getMaximumValue(); }
/** * Return the minimum value of a field, closest to the reference time */ public static int minimumValue(DateTimeFieldType type, ReadableDateTime reference){ return reference.toDateTime().property(type).getMinimumValue(); } /**
/** * Return the maximum value of a field, closest to the reference time */ public static int maximumValue(DateTimeFieldType type, ReadableDateTime reference){ return reference.toDateTime().property(type).getMaximumValue(); }
/** * Return the minimum value of a field, closest to the reference time */ public static int minimumValue(DateTimeFieldType type, ReadableDateTime reference){ return reference.toDateTime().property(type).getMinimumValue(); } /**
/** * Determine the ending DateTime (exclusive) of an interval based on an instant in time * * @param instant The start of an instant * @return */ 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); } }
/** * 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 */ 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); }
protected DateTime every(DateTime currentTime, DateTimeFieldType unit, int offset, int interval) { DateTime d = currentTime.property(unit).roundFloorCopy(); d = d.withFieldAdded(unit.getDurationType(), offset); return d.withField(unit, (d.get(unit) / interval) * interval); }
public IterableInterval(Interval interval, DTimeUnit per) { if (per == DTimeUnit.ALL_TIME) { this.increment = period(1, PeriodType.millis()); this.end = interval.getStart(); this.currentInstant = end.minus(increment); } else { this.increment = period(1, per.toPeriodType()); this.end = interval.getEnd().property(per.toDateTimeFieldType()).roundFloorCopy(); this.currentInstant = interval.getStart().minus(increment); } }