本文整理汇总了Java中java.time.temporal.UnsupportedTemporalTypeException类的典型用法代码示例。如果您正苦于以下问题:Java UnsupportedTemporalTypeException类的具体用法?Java UnsupportedTemporalTypeException怎么用?Java UnsupportedTemporalTypeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnsupportedTemporalTypeException类属于java.time.temporal包,在下文中一共展示了UnsupportedTemporalTypeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: truncate
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
public static long truncate(Instant instant, ChronoUnit unit) {
switch (unit) {
case NANOS:
case MICROS:
case MILLIS:
case SECONDS:
case MINUTES:
case HOURS:
case HALF_DAYS:
case DAYS:
return instant.atZone(systemDefault()).truncatedTo(unit).toEpochSecond() * 1000;
case MONTHS:
return instant.atZone(systemDefault()).truncatedTo(DAYS).withDayOfMonth(1).toEpochSecond() * 1000;
case YEARS:
return instant.atZone(systemDefault()).truncatedTo(DAYS).withDayOfYear(1).toEpochSecond() * 1000;
default:
throw new UnsupportedTemporalTypeException("Invalid unit for truncation: " + unit);
}
}
示例2: renderTemporal
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
/**
* Renders a Temporal value type Field
* @param property Property to render
* @return Field instance
*/
@SuppressWarnings("unchecked")
protected Field<T> renderTemporal(Property<T> property) {
TemporalInputBuilder builder = null;
if (LocalDate.class.isAssignableFrom(property.getType())) {
builder = input.localDate(false);
} else if (LocalDateTime.class.isAssignableFrom(property.getType())) {
builder = input.localDateTime(false);
} else {
throw new UnsupportedTemporalTypeException(
"Temporal type " + property.getType().getName() + " is not supported by default field renderer");
}
final TemporalInputBuilder<Temporal, ?> b = builder;
// set locale from LocalizationContext, if any
LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap((c) -> c.getLocale())
.ifPresent((l) -> b.locale(l));
return postProcessField(b.asField(), property);
}
示例3: get0
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
private int get0(TemporalField field) {
switch ((ChronoField) field) {
case DAY_OF_WEEK: return getDayOfWeek().getValue();
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((day - 1) % 7) + 1;
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;
case DAY_OF_MONTH: return day;
case DAY_OF_YEAR: return getDayOfYear();
case EPOCH_DAY: throw new UnsupportedTemporalTypeException("Invalid field 'EpochDay' for get() method, use getLong() instead");
case ALIGNED_WEEK_OF_MONTH: return ((day - 1) / 7) + 1;
case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;
case MONTH_OF_YEAR: return month;
case PROLEPTIC_MONTH: throw new UnsupportedTemporalTypeException("Invalid field 'ProlepticMonth' for get() method, use getLong() instead");
case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year);
case YEAR: return year;
case ERA: return (year >= 1 ? 1 : 0);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
示例4: range
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public ValueRange range(TemporalField field) {
if (field instanceof ChronoField) {
if (isSupported(field)) {
ChronoField f = (ChronoField) field;
switch (f) {
case DAY_OF_MONTH: return ValueRange.of(1, lengthOfMonth());
case DAY_OF_YEAR: return ValueRange.of(1, lengthOfYear());
case YEAR_OF_ERA: {
Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE);
jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET);
jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth());
return ValueRange.of(1, jcal.getActualMaximum(Calendar.YEAR));
}
}
return getChronology().range(f);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
示例5: range
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public ValueRange range(TemporalField field) {
if (field instanceof ChronoField) {
if (isSupported(field)) {
ChronoField f = (ChronoField) field;
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, 5); // TODO
// TODO does the limited range of valid years cause years to
// start/end part way through? that would affect range
}
return getChronology().range(f);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
示例6: getLong
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public long getLong(TemporalField field) {
if (field instanceof ChronoField) {
switch ((ChronoField) field) {
case DAY_OF_WEEK: return getDayOfWeek();
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((getDayOfWeek() - 1) % 7) + 1;
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;
case DAY_OF_MONTH: return this.dayOfMonth;
case DAY_OF_YEAR: return this.getDayOfYear();
case EPOCH_DAY: return toEpochDay();
case ALIGNED_WEEK_OF_MONTH: return ((dayOfMonth - 1) / 7) + 1;
case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;
case MONTH_OF_YEAR: return monthOfYear;
case PROLEPTIC_MONTH: return getProlepticMonth();
case YEAR_OF_ERA: return prolepticYear;
case YEAR: return prolepticYear;
case ERA: return getEraValue();
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
示例7: with
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public HijrahDate with(TemporalField field, long newValue) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
// not using checkValidIntValue so EPOCH_DAY and PROLEPTIC_MONTH work
chrono.range(f).checkValidValue(newValue, f); // TODO: validate value
int nvalue = (int) newValue;
switch (f) {
case DAY_OF_WEEK: return plusDays(newValue - getDayOfWeek());
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
case DAY_OF_MONTH: return resolvePreviousValid(prolepticYear, monthOfYear, nvalue);
case DAY_OF_YEAR: return plusDays(Math.min(nvalue, lengthOfYear()) - getDayOfYear());
case EPOCH_DAY: return new HijrahDate(chrono, newValue);
case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, dayOfMonth);
case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, monthOfYear, dayOfMonth);
case YEAR: return resolvePreviousValid(nvalue, monthOfYear, dayOfMonth);
case ERA: return resolvePreviousValid(1 - prolepticYear, monthOfYear, dayOfMonth);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return super.with(field, newValue);
}
示例8: plus
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public D plus(long amountToAdd, TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
ChronoUnit f = (ChronoUnit) unit;
switch (f) {
case DAYS: return plusDays(amountToAdd);
case WEEKS: return plusDays(Math.multiplyExact(amountToAdd, 7));
case MONTHS: return plusMonths(amountToAdd);
case YEARS: return plusYears(amountToAdd);
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
}
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return (D) ChronoLocalDate.super.plus(amountToAdd, unit);
}
示例9: until
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public long until(Temporal endExclusive, TemporalUnit unit) {
Objects.requireNonNull(endExclusive, "endExclusive");
ChronoLocalDate end = getChronology().date(endExclusive);
if (unit instanceof ChronoUnit) {
switch ((ChronoUnit) unit) {
case DAYS: return daysUntil(end);
case WEEKS: return daysUntil(end) / 7;
case MONTHS: return monthsUntil(end);
case YEARS: return monthsUntil(end) / 12;
case DECADES: return monthsUntil(end) / 120;
case CENTURIES: return monthsUntil(end) / 1200;
case MILLENNIA: return monthsUntil(end) / 12000;
case ERAS: return end.getLong(ERA) - getLong(ERA);
}
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
Objects.requireNonNull(unit, "unit");
return unit.between(this, end);
}
示例10: calculate
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
public DateCalculatorResult calculate(String text) {
final DateCalcExpressionParser parser = new DateCalcExpressionParser();
final Queue<Token> tokens = parser.parse(text);
try {
if (!tokens.isEmpty()) {
if (tokens.peek() instanceof DateToken) {
return handleDateExpression(tokens);
} else if (tokens.peek() instanceof TimeToken) {
return handleTimeExpression(tokens);
}
}
} catch (UnsupportedTemporalTypeException utte) {
throw new DateCalcException(utte.getLocalizedMessage());
}
throw new DateCalcException("An invalid expression was given: " + text);
}
示例11: range
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public ValueRange range(TemporalField field) {
if (field instanceof ChronoField) {
if (isSupported(field)) {
ChronoField f = (ChronoField) field;
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, month == 13 ? 1 : 5);
case YEAR:
case YEAR_OF_ERA: return (prolepticYear <= 0 ?
ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE)); // TODO
}
return getChronology().range(f);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
示例12: getLong
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public long getLong(TemporalField field) {
Objects.requireNonNull(field, "field");
Long value = fieldValues.get(field);
if (value != null) {
return value;
}
if (date != null && date.isSupported(field)) {
return date.getLong(field);
}
if (time != null && time.isSupported(field)) {
return time.getLong(field);
}
if (field instanceof ChronoField) {
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
示例13: getLong
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public long getLong(TemporalField field) {
if (field instanceof ChronoField) {
switch ((ChronoField) field) {
case DAY_OF_WEEK: return Math.floorMod(toEpochDay() + 3, 7) + 1;
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((day - 1) % 7) + 1;
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((get(ChronoField.DAY_OF_YEAR) - 1) % 7) + 1;
case DAY_OF_MONTH: return day;
case DAY_OF_YEAR: return (month - 1) * 30 + day;
case EPOCH_DAY: return toEpochDay();
case ALIGNED_WEEK_OF_MONTH: return ((day - 1) / 7) + 1;
case ALIGNED_WEEK_OF_YEAR: return ((get(ChronoField.DAY_OF_YEAR) - 1) / 7) + 1;
case MONTH_OF_YEAR: return month;
case YEAR_OF_ERA: return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear);
case YEAR: return prolepticYear;
case ERA: return (prolepticYear >= 1 ? 1 : 0);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
示例14: with
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public CopticDate with(TemporalField field, long newValue) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
f.checkValidValue(newValue); // TODO: validate value
int nvalue = (int) newValue;
switch (f) {
case DAY_OF_WEEK: return plusDays(newValue - get(ChronoField.DAY_OF_WEEK));
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
case DAY_OF_MONTH: return resolvePreviousValid(prolepticYear, month, nvalue);
case DAY_OF_YEAR: return resolvePreviousValid(prolepticYear, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1);
case EPOCH_DAY: return ofEpochDay(nvalue);
case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, day);
case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, month, day);
case YEAR: return resolvePreviousValid(nvalue, month, day);
case ERA: return resolvePreviousValid(1 - prolepticYear, month, day);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.adjustInto(this, newValue);
}
示例15: plus
import java.time.temporal.UnsupportedTemporalTypeException; //导入依赖的package包/类
@Override
public CopticDate plus(long amountToAdd, TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
ChronoUnit f = (ChronoUnit) unit;
switch (f) {
case DAYS: return plusDays(amountToAdd);
case WEEKS: return plusDays(Math.multiplyExact(amountToAdd, 7));
case MONTHS: return plusMonths(amountToAdd);
case YEARS: return plusYears(amountToAdd);
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
}
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.addTo(this, amountToAdd);
}