/** * Constructor. * * @param type the field type * @param unitMillis the average duration unit milliseconds */ public ImpreciseDateTimeField(DateTimeFieldType type, long unitMillis) { super(type); iUnitMillis = unitMillis; iDurationField = new LinkedDurationField(type.getDurationType()); }
/** * Constructor. * * @param type the field type * @param unitMillis the average duration unit milliseconds */ public ImpreciseDateTimeField(DateTimeFieldType type, long unitMillis) { super(type); iUnitMillis = unitMillis; iDurationField = new LinkedDurationField(type.getDurationType()); }
public static boolean isMoreSpecific(DateTimeFieldType df1, DateTimeFieldType df2, Chronology chronology) { DurationFieldType df1DurationFieldType = df1.getDurationType(); DurationFieldType df2DurationFieldType = df2.getDurationType(); if (!df2DurationFieldType.equals(df1DurationFieldType)) { DurationField df2Unit = df2DurationFieldType.getField(chronology); DurationFieldType p = df1.getRangeDurationType(); if (p != null) { DurationField df1Unit = df1DurationFieldType.getField(chronology); int cmp = df1Unit.compareTo(df2Unit); if (cmp < 0) { return true; } } } return false; }
public static boolean isMoreGeneral(DateTimeFieldType df1, DateTimeFieldType df2, Chronology chronology) { DurationFieldType df1DurationFieldType = df1.getDurationType(); DurationFieldType df2DurationFieldType = df2.getDurationType(); if (!df2DurationFieldType.equals(df1DurationFieldType)) { DurationField df1Unit = df1DurationFieldType.getField(chronology); DurationFieldType p = df2.getRangeDurationType(); if (p != null) { DurationField df2Unit = df2DurationFieldType.getField(chronology); int cmp = df1Unit.compareTo(df2Unit); if (cmp > 0) { return true; } } } return false; }
public static Set<DurationFieldType> getSupportedDurationFields(Partial p) { Set<DurationFieldType> supportedDurations = Generics.newHashSet(); for (int i = 0; i < p.size(); i++) { supportedDurations.add(p.getFieldType(i).getDurationType()); } return supportedDurations; } public static Period getUnsupportedDurationPeriod(Partial p, Period offset)
/** * Gets the index of the first fields to have the specified duration, * or -1 if the field is unsupported. * * @param type the type to check, may be null which returns -1 * @return the index of the field, -1 if unsupported */ protected int indexOf(DurationFieldType type) { for (int i = 0, isize = size(); i < isize; i++) { if (getFieldType(i).getDurationType() == type) { return i; } } return -1; }
/** * Gets the index of the first fields to have the specified duration, * or -1 if the field is unsupported. * * @param type the type to check, may be null which returns -1 * @return the index of the field, -1 if unsupported */ protected int indexOf(DurationFieldType type) { for (int i = 0, isize = size(); i < isize; i++) { if (getFieldType(i).getDurationType() == type) { return i; } } return -1; }
private void initDatePartitionFromPattern(State state) { String partitionPattern = null; try { partitionPattern = state.getProp(DATE_PARTITIONED_SOURCE_PARTITION_PATTERN); if (partitionPattern != null) { this.partitionPatternFormatter = DateTimeFormat.forPattern(partitionPattern).withZone(DateTimeZone.getDefault()); this.incrementalUnit = DatePartitionType.getLowestIntervalUnit(partitionPattern).getDurationType(); } } catch (Exception e) { throw new IllegalArgumentException("Invalid source partition pattern: " + partitionPattern, e); } }
private void initDatePartitionFromGranularity(State state) { String granularityProp = state.getProp(PartitionedFileSourceBase.DATE_PARTITIONED_SOURCE_PARTITION_GRANULARITY); DatePartitionType partitionType = null; if (granularityProp == null) { partitionType = PartitionedFileSourceBase.DEFAULT_DATE_PARTITIONED_SOURCE_PARTITION_GRANULARITY; } else { Optional<DatePartitionType> partitionTypeOpt = Enums.getIfPresent(DatePartitionType.class, granularityProp.toUpperCase()); Preconditions .checkState(partitionTypeOpt.isPresent(), "Invalid source partition granularity: " + granularityProp); partitionType = partitionTypeOpt.get(); } this.partitionPatternFormatter = DateTimeFormat.forPattern(partitionType.getDateTimePattern()); this.incrementalUnit = partitionType.getDateTimeFieldType().getDurationType(); }
/** * Get the number of milliseconds associated with a partition type. Eg * getUnitMilliseconds() of DatePartitionType.MINUTE = 60,000. */ public long getUnitMilliseconds() { return dateTimeField.getDurationType().getField(ISOChronology.getInstance()).getUnitMillis(); }
} else { iDurationField = new ScaledDurationField( unitField, type.getDurationType(), divisor);
/** * Checks if the field type specified is supported by this * local time and chronology. * 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; } if (isSupported(type.getDurationType()) == false) { return false; } DurationFieldType range = type.getRangeDurationType(); return (isSupported(range) || range == DurationFieldType.days()); }
} else { iDurationField = new ScaledDurationField( unitField, type.getDurationType(), divisor);
/** * Checks if the field type specified is supported by this * local time and chronology. * 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; } if (isSupported(type.getDurationType()) == false) { return false; } DurationFieldType range = type.getRangeDurationType(); return (isSupported(range) || range == DurationFieldType.days()); }
/** * Checks if the field type specified is supported by this * local date and chronology. * 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; } DurationFieldType durType = type.getDurationType(); if (DATE_DURATION_TYPES.contains(durType) || durType.getField(getChronology()).getUnitMillis() >= getChronology().days().getUnitMillis()) { return type.getField(getChronology()).isSupported(); } return false; }
/** * Checks if the field type specified is supported by this * local date and chronology. * 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; } DurationFieldType durType = type.getDurationType(); if (DATE_DURATION_TYPES.contains(durType) || durType.getField(getChronology()).getUnitMillis() >= getChronology().days().getUnitMillis()) { return type.getField(getChronology()).isSupported(); } return false; }
protected static Period getJodaTimePeriod(Partial p) { if (p.size() > 0) { DateTimeFieldType dtType = p.getFieldType(p.size()-1); DurationFieldType dType = dtType.getDurationType(); Period period = new Period(); if (period.isSupported(dType)) { return period.withField(dType, 1); } else { DurationField df = dType.getField(p.getChronology()); if (df instanceof ScaledDurationField) { ScaledDurationField sdf = (ScaledDurationField) df; return period.withField(sdf.getWrappedField().getType(), sdf.getScalar()); } // PeriodType.forFields(new DurationFieldType[]{dType}); // return new Period(df.getUnitMillis(), PeriodType.forFields(new DurationFieldType[]{dType})); } } return null; } public static Partial combineMoreGeneralFields(Partial p1, Partial p2) {
DurationFieldType df = mostGeneral.getRangeDurationType(); if (df == null) { df = mostGeneral.getDurationType();
public static Partial discardMoreSpecificFields(Partial p, DurationFieldType dft) { DurationField df = dft.getField(p.getChronology()); Partial res = new Partial(); for (int i = 0; i < p.size(); i++) { DateTimeFieldType fieldType = p.getFieldType(i); DurationField f = fieldType.getDurationType().getField(p.getChronology()); int cmp = df.compareTo(f); if (cmp <= 0) { res = res.with(fieldType, p.getValue(i)); } } return res; }
public static Partial resolveDowToDay(Partial p) { if (p.isSupported(DateTimeFieldType.dayOfWeek())) { if (!p.isSupported(DateTimeFieldType.dayOfMonth())) { if (p.isSupported(DateTimeFieldType.weekOfWeekyear()) && (p.isSupported(DateTimeFieldType.year()))) { // Convert from year to weekyear (to avoid weirdness when the weekyear and year don't match at the beginning of the year) Partial pwy = withWeekYear(p); Instant t2 = getInstant(pwy); DateTime t1 = pwy.toDateTime(t2); Partial res = getPartial(t1.toInstant(), EMPTY_ISO_PARTIAL); DateTimeFieldType mostSpecific = getMostSpecific(p); res = discardMoreSpecificFields(res, mostSpecific.getDurationType()); return res; } } } return p; }