Java Code Examples for java.time.temporal.TemporalUnit#isTimeBased()
The following examples show how to use
java.time.temporal.TemporalUnit#isTimeBased() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChronoLocalDateTimeImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public long until(Temporal endExclusive, TemporalUnit unit) { Objects.requireNonNull(endExclusive, "endExclusive"); @SuppressWarnings("unchecked") ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive); if (unit instanceof ChronoUnit) { if (unit.isTimeBased()) { long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY); switch ((ChronoUnit) unit) { case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break; case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break; case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break; case SECONDS: amount = Math.multiplyExact(amount, SECONDS_PER_DAY); break; case MINUTES: amount = Math.multiplyExact(amount, MINUTES_PER_DAY); break; case HOURS: amount = Math.multiplyExact(amount, HOURS_PER_DAY); break; case HALF_DAYS: amount = Math.multiplyExact(amount, 2); break; } return Math.addExact(amount, time.until(end.toLocalTime(), unit)); } ChronoLocalDate endDate = end.toLocalDate(); if (end.toLocalTime().isBefore(time)) { endDate = endDate.minus(1, ChronoUnit.DAYS); } return date.until(endDate, unit); } Objects.requireNonNull(unit, "unit"); return unit.between(this, end); }
Example 2
Source File: ChronoLocalDateTimeImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public long until(Temporal endExclusive, TemporalUnit unit) { Objects.requireNonNull(endExclusive, "endExclusive"); @SuppressWarnings("unchecked") ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive); if (unit instanceof ChronoUnit) { if (unit.isTimeBased()) { long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY); switch ((ChronoUnit) unit) { case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break; case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break; case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break; case SECONDS: amount = Math.multiplyExact(amount, SECONDS_PER_DAY); break; case MINUTES: amount = Math.multiplyExact(amount, MINUTES_PER_DAY); break; case HOURS: amount = Math.multiplyExact(amount, HOURS_PER_DAY); break; case HALF_DAYS: amount = Math.multiplyExact(amount, 2); break; } return Math.addExact(amount, time.until(end.toLocalTime(), unit)); } ChronoLocalDate endDate = end.toLocalDate(); if (end.toLocalTime().isBefore(time)) { endDate = endDate.minus(1, ChronoUnit.DAYS); } return date.until(endDate, unit); } Objects.requireNonNull(unit, "unit"); return unit.between(this, end); }
Example 3
Source File: ChronoLocalDateTimeImpl.java From j2objc with Apache License 2.0 | 5 votes |
@Override public long until(Temporal endExclusive, TemporalUnit unit) { Objects.requireNonNull(endExclusive, "endExclusive"); @SuppressWarnings("unchecked") ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive); if (unit instanceof ChronoUnit) { if (unit.isTimeBased()) { long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY); switch ((ChronoUnit) unit) { case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break; case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break; case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break; case SECONDS: amount = Math.multiplyExact(amount, SECONDS_PER_DAY); break; case MINUTES: amount = Math.multiplyExact(amount, MINUTES_PER_DAY); break; case HOURS: amount = Math.multiplyExact(amount, HOURS_PER_DAY); break; case HALF_DAYS: amount = Math.multiplyExact(amount, 2); break; } return Math.addExact(amount, time.until(end.toLocalTime(), unit)); } ChronoLocalDate endDate = end.toLocalDate(); if (end.toLocalTime().isBefore(time)) { endDate = endDate.minus(1, ChronoUnit.DAYS); } return date.until(endDate, unit); } Objects.requireNonNull(unit, "unit"); return unit.between(this, end); }
Example 4
Source File: ChronoLocalDateTimeImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public long until(Temporal endExclusive, TemporalUnit unit) { Objects.requireNonNull(endExclusive, "endExclusive"); @SuppressWarnings("unchecked") ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive); if (unit instanceof ChronoUnit) { if (unit.isTimeBased()) { long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY); switch ((ChronoUnit) unit) { case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break; case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break; case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break; case SECONDS: amount = Math.multiplyExact(amount, SECONDS_PER_DAY); break; case MINUTES: amount = Math.multiplyExact(amount, MINUTES_PER_DAY); break; case HOURS: amount = Math.multiplyExact(amount, HOURS_PER_DAY); break; case HALF_DAYS: amount = Math.multiplyExact(amount, 2); break; } return Math.addExact(amount, time.until(end.toLocalTime(), unit)); } ChronoLocalDate endDate = end.toLocalDate(); if (end.toLocalTime().isBefore(time)) { endDate = endDate.minus(1, ChronoUnit.DAYS); } return date.until(endDate, unit); } Objects.requireNonNull(unit, "unit"); return unit.between(this, end); }
Example 5
Source File: Instant.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this date-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * <li>{@code DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased() || unit == DAYS; } return unit != null && unit.isSupportedBy(this); }
Example 6
Source File: LocalTime.java From Java8CN with Apache License 2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 7
Source File: LocalTime.java From JDKSourceCode1.8 with MIT License | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 8
Source File: Instant.java From JDKSourceCode1.8 with MIT License | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this date-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * <li>{@code DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased() || unit == DAYS; } return unit != null && unit.isSupportedBy(this); }
Example 9
Source File: Instant.java From Java8CN with Apache License 2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this date-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * <li>{@code DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased() || unit == DAYS; } return unit != null && unit.isSupportedBy(this); }
Example 10
Source File: LocalTime.java From jdk8u60 with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 11
Source File: LocalTime.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this date-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 12
Source File: LocalTime.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 13
Source File: LocalTime.java From desugar_jdk_libs with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 14
Source File: LocalTime.java From openjdk-8 with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this date-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 15
Source File: LocalTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this date-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 16
Source File: LocalTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 17
Source File: Instant.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this date-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * <li>{@code DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased() || unit == DAYS; } return unit != null && unit.isSupportedBy(this); }
Example 18
Source File: OffsetTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this offset-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 19
Source File: OffsetTime.java From desugar_jdk_libs with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this offset-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }
Example 20
Source File: OffsetTime.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this date-time. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. * <p> * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: * <ul> * <li>{@code NANOS} * <li>{@code MICROS} * <li>{@code MILLIS} * <li>{@code SECONDS} * <li>{@code MINUTES} * <li>{@code HOURS} * <li>{@code HALF_DAYS} * </ul> * All other {@code ChronoUnit} instances will return false. * <p> * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} * passing {@code this} as the argument. * Whether the unit is supported is determined by the unit. * * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ @Override // override for Javadoc public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isTimeBased(); } return unit != null && unit.isSupportedBy(this); }