/** * @inheritdoc */ public function isUnitSupported(TemporalUnit $unit) { if ($unit instanceof ChronoUnit) { return $unit->isDateBased(); } return $unit != null && $unit->isSupportedBy($this); }
/** * Checks if the specified unit is supported. * <p> * This checks if the specified unit can be added to, or subtracted from, this year. * 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 YEARS} * <li>{@code DECADES} * <li>{@code CENTURIES} * <li>{@code MILLENNIA} * <li>{@code ERAS} * </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 TemporalUnit $unit the unit to check, null returns false * @return bool true if the unit can be added/subtracted, false if not */ public function isUnitSupported(TemporalUnit $unit) { if ($unit instanceof ChronoUnit) { return $unit == ChronoUnit::YEARS() || $unit == ChronoUnit::DECADES() || $unit == ChronoUnit::CENTURIES() || $unit == ChronoUnit::MILLENNIA() || $unit == ChronoUnit::ERAS(); } return $unit != null && $unit->isSupportedBy($this); }