/** * Checks whether this field supported in the given Chronology. * * @param chronology the chronology to use, null means ISOChronology in default zone * @return true if supported */ public boolean isSupported(Chronology chronology) { return getField(chronology).isSupported(); }
/** * Checks whether this field supported in the given Chronology. * * @param chronology the chronology to use, null means ISOChronology in default zone * @return true if supported */ public boolean isSupported(Chronology chronology) { return getField(chronology).isSupported(); }
/** * Checks if the duration type specified is supported by this * local datetime and chronology. * * @param type a duration type, usually obtained from DurationFieldType * @return true if the field type is supported */ public boolean isSupported(DurationFieldType type) { if (type == null) { return false; } return type.getField(getChronology()).isSupported(); }
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; }
/** * Checks if the duration type specified is supported by this * local datetime and chronology. * * @param type a duration type, usually obtained from DurationFieldType * @return true if the field type is supported */ public boolean isSupported(DurationFieldType type) { if (type == null) { return false; } return type.getField(getChronology()).isSupported(); }
public static Period discardMoreSpecificFields(Period p, DurationFieldType dft, Chronology chronology) { DurationField df = dft.getField(chronology); Period res = new Period(); for (int i = 0; i < p.size(); i++) { DurationFieldType fieldType = p.getFieldType(i); DurationField f = fieldType.getField(chronology); int cmp = df.compareTo(f); if (cmp <= 0) { res = res.withField(fieldType, p.getValue(i)); } } return res; }
/** * Adds to the instant specifying the duration and multiple to add. * * @param type a field type, usually obtained from DateTimeFieldType, not null * @param amount the amount to add of this duration * @throws IllegalArgumentException if the value is null or invalid * @throws ArithmeticException if the result exceeds the capacity of the instant */ public void add(DurationFieldType type, int amount) { if (type == null) { throw new IllegalArgumentException("Field must not be null"); } if (amount != 0) { setMillis(type.getField(getChronology()).add(getMillis(), amount)); } }
@Override long fromMillis(long millisSinceEpoch) { return DurationFieldType.months().getField(ISOChronology.getInstanceUTC()).getDifference(millisSinceEpoch, 0L); } }, YEARS {
@Override public long fromMillis(long millisSinceEpoch) { return DurationFieldType.weeks().getField(ISOChronology.getInstanceUTC()).getDifference(millisSinceEpoch, 0L); } },
@Override public long fromMillis(long millisSinceEpoch) { return DurationFieldType.years().getField(ISOChronology.getInstanceUTC()).getDifference(millisSinceEpoch, 0L); } };
@Override long fromMillis(long millisSinceEpoch) { return DurationFieldType.weeks().getField(ISOChronology.getInstanceUTC()).getDifference(millisSinceEpoch, 0L); } }, MONTHS {
@Override public long fromMillis(long millisSinceEpoch) { return DurationFieldType.months().getField(ISOChronology.getInstanceUTC()).getDifference(millisSinceEpoch, 0L); } },
/** * Calculates the number of whole units between the two specified datetimes. * * @param start the start instant, validated to not be null * @param end the end instant, validated to not be null * @param field the field type to use, must not be null * @return the period * @throws IllegalArgumentException if the instants are null or invalid */ protected static int between(ReadableInstant start, ReadableInstant end, DurationFieldType field) { if (start == null || end == null) { throw new IllegalArgumentException("ReadableInstant objects must not be null"); } Chronology chrono = DateTimeUtils.getInstantChronology(start); int amount = field.getField(chrono).getDifference(end.getMillis(), start.getMillis()); return amount; }
@Override long fromMillis(long millisSinceEpoch) { return DurationFieldType.years().getField(ISOChronology.getInstanceUTC()).getDifference(millisSinceEpoch, 0L); } };
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; }
/** * Checks if the duration type specified is supported by this * local date and chronology. * * @param type a duration type, usually obtained from DurationFieldType * @return true if the field type is supported */ public boolean isSupported(DurationFieldType type) { if (type == null) { return false; } DurationField field = type.getField(getChronology()); if (DATE_DURATION_TYPES.contains(type) || field.getUnitMillis() >= getChronology().days().getUnitMillis()) { return field.isSupported(); } return false; }
/** * Converts this object to an <code>Interval</code> encompassing * the whole of this day. * <p> * The interval starts at midnight 00:00 and ends at 00:00 the following day, * (which is not included in the interval, as intervals are half-open). * * @return an interval over the day */ public Interval toInterval() { Chronology chrono = getChronology(); long start = getMillis(); long end = DurationFieldType.days().getField(chrono).add(start, 1); return new Interval(start, end, chrono); }
/** * Converts this object to an <code>Interval</code> encompassing * the whole of this day. * <p> * The interval starts at midnight 00:00 and ends at 00:00 the following day, * (which is not included in the interval, as intervals are half-open). * * @return an interval over the day */ public Interval toInterval() { Chronology chrono = getChronology(); long start = getMillis(); long end = DurationFieldType.days().getField(chrono).add(start, 1); return new Interval(start, end, chrono); }
private static long millisBetween(ReadableInstant start, ReadableInstant end) { requireNonNull(start, "start is null"); requireNonNull(end, "end is null"); return millis().getField(getInstantChronology(start)).getDifferenceAsLong(end.getMillis(), start.getMillis()); }