本文整理汇总了Java中java.time.temporal.ChronoField.isDateBased方法的典型用法代码示例。如果您正苦于以下问题:Java ChronoField.isDateBased方法的具体用法?Java ChronoField.isDateBased怎么用?Java ChronoField.isDateBased使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.temporal.ChronoField
的用法示例。
在下文中一共展示了ChronoField.isDateBased方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSupported
import java.time.temporal.ChronoField; //导入方法依赖的package包/类
@Override
public boolean isSupported(TemporalField field) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
return f.isDateBased() || f.isTimeBased();
}
return field != null && field.isSupportedBy(this);
}
示例2: range
import java.time.temporal.ChronoField; //导入方法依赖的package包/类
/**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
* This date is used to enhance the accuracy of the returned range.
* If it is not possible to return the range, because the field is not supported
* or for some other reason, an exception is thrown.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The {@link #isSupported(TemporalField) supported fields} will return
* appropriate range instances.
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
* is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
* passing {@code this} as the argument.
* Whether the range can be obtained is determined by the field.
*
* @param field the field to query the range for, not null
* @return the range of valid values for the field, not null
* @throws DateTimeException if the range for the field cannot be obtained
* @throws UnsupportedTemporalTypeException if the field is not supported
*/
@Override
public ValueRange range(TemporalField field) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
if (f.isDateBased()) {
switch (f) {
case DAY_OF_MONTH: return ValueRange.of(1, lengthOfMonth());
case DAY_OF_YEAR: return ValueRange.of(1, lengthOfYear());
case ALIGNED_WEEK_OF_MONTH: return ValueRange.of(1, getMonth() == Month.FEBRUARY && isLeapYear() == false ? 4 : 5);
case YEAR_OF_ERA:
return (getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE));
}
return field.range();
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
示例3: isSupported
import java.time.temporal.ChronoField; //导入方法依赖的package包/类
/**
* Checks if the specified field is supported.
* <p>
* This checks if this date-time can be queried for the specified field.
* If false, then calling the {@link #range(TemporalField) range},
* {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
* methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
* <ul>
* <li>{@code NANO_OF_SECOND}
* <li>{@code NANO_OF_DAY}
* <li>{@code MICRO_OF_SECOND}
* <li>{@code MICRO_OF_DAY}
* <li>{@code MILLI_OF_SECOND}
* <li>{@code MILLI_OF_DAY}
* <li>{@code SECOND_OF_MINUTE}
* <li>{@code SECOND_OF_DAY}
* <li>{@code MINUTE_OF_HOUR}
* <li>{@code MINUTE_OF_DAY}
* <li>{@code HOUR_OF_AMPM}
* <li>{@code CLOCK_HOUR_OF_AMPM}
* <li>{@code HOUR_OF_DAY}
* <li>{@code CLOCK_HOUR_OF_DAY}
* <li>{@code AMPM_OF_DAY}
* <li>{@code DAY_OF_WEEK}
* <li>{@code ALIGNED_DAY_OF_WEEK_IN_MONTH}
* <li>{@code ALIGNED_DAY_OF_WEEK_IN_YEAR}
* <li>{@code DAY_OF_MONTH}
* <li>{@code DAY_OF_YEAR}
* <li>{@code EPOCH_DAY}
* <li>{@code ALIGNED_WEEK_OF_MONTH}
* <li>{@code ALIGNED_WEEK_OF_YEAR}
* <li>{@code MONTH_OF_YEAR}
* <li>{@code PROLEPTIC_MONTH}
* <li>{@code YEAR_OF_ERA}
* <li>{@code YEAR}
* <li>{@code ERA}
* </ul>
* All other {@code ChronoField} instances will return false.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
* is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
* passing {@code this} as the argument.
* Whether the field is supported is determined by the field.
*
* @param field the field to check, null returns false
* @return true if the field is supported on this date-time, false if not
*/
@Override
public boolean isSupported(TemporalField field) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
return f.isDateBased() || f.isTimeBased();
}
return field != null && field.isSupportedBy(this);
}