List of usage examples for org.joda.time DateTimeFieldType getField
public abstract DateTimeField getField(Chronology chronology);
From source file:ch.oakmountain.tpa.solver.PeriodicalTimeFrame.java
License:Apache License
/** * Get the value of one of the fields of a datetime. * <p/>/*from ww w . j ava 2 s. com*/ * This method gets the value of the specified field. * For example: * <pre> * DateTime dt = new DateTime(); * int year = dt.get(DateTimeFieldType.year()); * </pre> * * @param type a field type, usually obtained from DateTimeFieldType, not null * @return the value of that field * @throws IllegalArgumentException if the field type is null */ public int get(DateTimeFieldType type) { if (type == null) { throw new IllegalArgumentException("The DateTimeFieldType must not be null"); } return type.getField(getChronology()).get(getLocalMillis()); }
From source file:ch.oakmountain.tpa.solver.PeriodicalTimeFrame.java
License:Apache License
/** * Checks if the field type specified is supported by this * local datetime and chronology.// w w w . ja v a 2 s . c om * This can be used to avoid exceptions in {@link #get(DateTimeFieldType)}. * * @param type a field type, usually obtained from DateTimeFieldType * @return true if the field type is supported */ public boolean isSupported(DateTimeFieldType type) { if (type == null) { return false; } return type.getField(getChronology()).isSupported(); }
From source file:ch.oakmountain.tpa.solver.PeriodicalTimeFrame.java
License:Apache License
/** * Gets the property object for the specified type, which contains many * useful methods.// ww w. j a v a 2s. com * * @param fieldType the field type to get the chronology for * @return the property object * @throws IllegalArgumentException if the field is null or unsupported */ public Property property(DateTimeFieldType fieldType) { if (fieldType == null) { throw new IllegalArgumentException("The DateTimeFieldType must not be null"); } if (isSupported(fieldType) == false) { throw new IllegalArgumentException("Field '" + fieldType + "' is not supported"); } return new Property(this, fieldType.getField(getChronology())); }
From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.SemLeidmiseAbimeetodid.java
License:Open Source License
/** * Tagastab antud kalendriv2ljaga seotud ekstreemum (min v6i max) v22rtuse; *///from w w w. j a v a 2 s .co m public static int getLocalDateTimeFieldExtremum(BaseLocal partial, DateTimeFieldType type, boolean getMax) { DateTimeField field = type.getField(partial.getChronology()); return (getMax) ? (field.getMaximumValue(partial)) : (field.getMinimumValue(partial)); }
From source file:org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategy.java
License:Open Source License
/** * Determines the starting point ("anchor") for a period. * * To produce repeatable rotation points in time, the period is "snapped" to a "grid" of time. * For example, an hourly index rotation would be anchored to the last full hour, instead of happening at whatever minute * the first rotation was started./* w w w. ja v a 2 s. c o m*/ * * This "snapping" is done accordingly with the other parts of a period. * * For highly irregular periods (those that do not have a small zero component) * * @param period the rotation period * @return the anchor DateTime to calculate rotation periods from */ protected static DateTime determineRotationPeriodAnchor(@Nullable DateTime lastAnchor, Period period) { final Period normalized = period.normalizedStandard(); int years = normalized.getYears(); int months = normalized.getMonths(); int weeks = normalized.getWeeks(); int days = normalized.getDays(); int hours = normalized.getHours(); int minutes = normalized.getMinutes(); int seconds = normalized.getSeconds(); if (years == 0 && months == 0 && weeks == 0 && days == 0 && hours == 0 && minutes == 0 && seconds == 0) { throw new IllegalArgumentException("Invalid rotation period specified"); } // find the largest non-zero stride in the period. that's our anchor type. statement order matters here! DateTimeFieldType largestStrideType = null; if (seconds > 0) largestStrideType = secondOfMinute(); if (minutes > 0) largestStrideType = minuteOfHour(); if (hours > 0) largestStrideType = hourOfDay(); if (days > 0) largestStrideType = dayOfMonth(); if (weeks > 0) largestStrideType = weekOfWeekyear(); if (months > 0) largestStrideType = monthOfYear(); if (years > 0) largestStrideType = year(); if (largestStrideType == null) { throw new IllegalArgumentException("Could not determine rotation stride length."); } final DateTime anchorTime = MoreObjects.firstNonNull(lastAnchor, Tools.nowUTC()); final DateTimeField field = largestStrideType.getField(anchorTime.getChronology()); // use normalized here to make sure we actually have the largestStride type available! see https://github.com/Graylog2/graylog2-server/issues/836 int periodValue = normalized.get(largestStrideType.getDurationType()); final long fieldValue = field.roundFloor(anchorTime.getMillis()); final int fieldValueInUnit = field.get(fieldValue); if (periodValue == 0) { // https://github.com/Graylog2/graylog2-server/issues/836 log.warn( "Determining stride length failed because of a 0 period. Defaulting back to 1 period to avoid crashing, but this is a bug!"); periodValue = 1; } final long difference = (fieldValueInUnit % periodValue); final long newValue = field.add(fieldValue, -1 * difference); return new DateTime(newValue, DateTimeZone.UTC); }
From source file:org.graylog2.indexer.rotation.TimeBasedRotationStrategy.java
License:Open Source License
/** * Determines the starting point ("anchor") for a period. * * To produce repeatable rotation points in time, the period is "snapped" to a "grid" of time. * For example, an hourly index rotation would be anchored to the last full hour, instead of happening at whatever minute * the first rotation was started./*from ww w . j a v a 2s .co m*/ * * This "snapping" is done accordingly with the other parts of a period. * * For highly irregular periods (those that do not have a small zero component) * * @param period the rotation period * @return the anchor DateTime to calculate rotation periods from */ protected static DateTime determineRotationPeriodAnchor(Period period) { final Period normalized = period.normalizedStandard(); int years = normalized.getYears(); int months = normalized.getMonths(); int weeks = normalized.getWeeks(); int days = normalized.getDays(); int hours = normalized.getHours(); int minutes = normalized.getMinutes(); int seconds = normalized.getSeconds(); if (years == 0 && months == 0 && weeks == 0 && days == 0 && hours == 0 && minutes == 0 && seconds == 0) { throw new IllegalArgumentException("Invalid rotation period specified"); } // find the largest non-zero stride in the period. that's our anchor type. statement order matters here! DateTimeFieldType largestStrideType = null; if (seconds > 0) largestStrideType = secondOfMinute(); if (minutes > 0) largestStrideType = minuteOfHour(); if (hours > 0) largestStrideType = hourOfDay(); if (days > 0) largestStrideType = dayOfMonth(); if (weeks > 0) largestStrideType = weekOfWeekyear(); if (months > 0) largestStrideType = monthOfYear(); if (years > 0) largestStrideType = year(); if (largestStrideType == null) { throw new IllegalArgumentException("Could not determine rotation stride length."); } final DateTime now = Tools.iso8601(); final DateTimeField field = largestStrideType.getField(now.getChronology()); // use normalized here to make sure we actually have the largestStride type available! see https://github.com/Graylog2/graylog2-server/issues/836 int periodValue = normalized.get(largestStrideType.getDurationType()); final long fieldValue = field.roundFloor(now.getMillis()); final int fieldValueInUnit = field.get(fieldValue); if (periodValue == 0) { // https://github.com/Graylog2/graylog2-server/issues/836 log.warn( "Determining stride length failed because of a 0 period. Defaulting back to 1 period to avoid crashing, but this is a bug!"); periodValue = 1; } final long difference = (fieldValueInUnit % periodValue); final long newValue = field.add(fieldValue, -1 * difference); return new DateTime(newValue, DateTimeZone.UTC); }
From source file:TVShowTimelineMaker.ui.ConstraintEditors.IntervalConstraintEditor.java
private void listFieldsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listFieldsValueChanged DateTimeFieldType mDateTimeFieldType = this.listFields.getSelectedValue(); Chronology chronology = this.mInterval.getChronology(); DateTimeField mDateTimeField = mDateTimeFieldType.getField(chronology); this.mStartSpinnerNumberModel.setMaximum(mDateTimeField.getMaximumValue()); this.mStartSpinnerNumberModel.setMinimum(mDateTimeField.getMinimumValue()); this.mEndSpinnerNumberModel.setMaximum(mDateTimeField.getMaximumValue()); this.mEndSpinnerNumberModel.setMinimum(mDateTimeField.getMinimumValue()); this.spinValueStart.setValue(this.mStartDateTime.get(this.listFields.getSelectedValue())); this.spinValueEnd.setValue(this.mEndDateTime.get(this.listFields.getSelectedValue())); }
From source file:TVShowTimelineMaker.ui.ConstraintEditors.PartialTimeConstraintEditor.java
private void listFieldsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listFieldsValueChanged DateTimeFieldType mDateTimeFieldType = this.listFields.getSelectedValue(); Chronology chronology = this.mPartial.getChronology(); DateTimeField mDateTimeField = mDateTimeFieldType.getField(chronology); this.mSpinnerNumberModel.setMaximum(mDateTimeField.getMaximumValue()); this.mSpinnerNumberModel.setMinimum(mDateTimeField.getMinimumValue()); if ((Integer) this.spinValue.getValue() > mDateTimeField.getMaximumValue()) { this.spinValue.setValue(mDateTimeField.getMaximumValue()); }//from ww w .j av a 2 s. com if ((Integer) this.spinValue.getValue() < mDateTimeField.getMinimumValue()) { this.spinValue.setValue(mDateTimeField.getMinimumValue()); } }
From source file:TVShowTimelineMaker.ui.Joda.DateTimeEditor.java
private void listFieldsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listFieldsValueChanged DateTimeFieldType mDateTimeFieldType = this.listFields.getSelectedValue(); Chronology chronology = this.mDateTime.getChronology(); DateTimeField mDateTimeField = mDateTimeFieldType.getField(chronology); this.mSpinnerNumberModel.setMaximum(mDateTimeField.getMaximumValue()); this.mSpinnerNumberModel.setMinimum(mDateTimeField.getMinimumValue()); this.spinValue.setValue(this.mDateTime.get(this.listFields.getSelectedValue())); }