java.time.temporal.UnsupportedTemporalTypeException Java Examples
The following examples show how to use
java.time.temporal.UnsupportedTemporalTypeException.
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: LocalDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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); }
Example #2
Source File: ChronoLocalDateImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@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); }
Example #3
Source File: CopticDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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); }
Example #4
Source File: CopticDate.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@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); }
Example #5
Source File: CopticDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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); }
Example #6
Source File: LocalDate.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
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); }
Example #7
Source File: HijrahDate.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@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); }
Example #8
Source File: Parsed.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
@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); }
Example #9
Source File: ChronoLocalDateImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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); }
Example #10
Source File: LocalDate.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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); }
Example #11
Source File: HijrahDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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); }
Example #12
Source File: HijrahDate.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
@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); }
Example #13
Source File: HijrahDate.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
@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); }
Example #14
Source File: ChronoLocalDateImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
@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); }
Example #15
Source File: CopticDate.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@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); }
Example #16
Source File: JapaneseDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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); }
Example #17
Source File: Parsed.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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); }
Example #18
Source File: ChronoPeriodImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public long get(TemporalUnit unit) { if (unit == ChronoUnit.YEARS) { return years; } else if (unit == ChronoUnit.MONTHS) { return months; } else if (unit == ChronoUnit.DAYS) { return days; } else { throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } }
Example #19
Source File: ChronoLocalDate.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override default ChronoLocalDate plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return ChronoLocalDateImpl.ensureValid(getChronology(), unit.addTo(this, amountToAdd)); }
Example #20
Source File: JapaneseDate.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { // same as ISO: // DAY_OF_WEEK, DAY_OF_MONTH, EPOCH_DAY, MONTH_OF_YEAR, PROLEPTIC_MONTH, YEAR // // calendar specific fields // DAY_OF_YEAR, YEAR_OF_ERA, ERA switch ((ChronoField) field) { case ALIGNED_DAY_OF_WEEK_IN_MONTH: case ALIGNED_DAY_OF_WEEK_IN_YEAR: case ALIGNED_WEEK_OF_MONTH: case ALIGNED_WEEK_OF_YEAR: throw new UnsupportedTemporalTypeException("Unsupported field: " + field); case YEAR_OF_ERA: return yearOfEra; case ERA: return era.getValue(); case DAY_OF_YEAR: Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE); jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET); jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth()); return jcal.get(Calendar.DAY_OF_YEAR); } return isoDate.getLong(field); } return field.getFrom(this); }
Example #21
Source File: ChronoPeriodImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
@Override public long get(TemporalUnit unit) { if (unit == ChronoUnit.YEARS) { return years; } else if (unit == ChronoUnit.MONTHS) { return months; } else if (unit == ChronoUnit.DAYS) { return days; } else { throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } }
Example #22
Source File: MockFieldValue.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public long getLong(TemporalField field) { if (this.field.equals(field)) { return value; } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); }
Example #23
Source File: ChronoZonedDateTime.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
@Override default int get(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case INSTANT_SECONDS: throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead"); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } return toLocalDateTime().get(field); } return Temporal.super.get(field); }
Example #24
Source File: MockFieldValue.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public ValueRange range(TemporalField field) { if (field instanceof ChronoField) { if (isSupported(field)) { return field.range(); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.rangeRefinedBy(this); }
Example #25
Source File: MockFieldValue.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public ValueRange range(TemporalField field) { if (field instanceof ChronoField) { if (isSupported(field)) { return field.range(); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.rangeRefinedBy(this); }
Example #26
Source File: MockFieldValue.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public long getLong(TemporalField field) { if (this.field.equals(field)) { return value; } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); }
Example #27
Source File: ChronoLocalDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} * @throws DateTimeException {@inheritDoc} * @throws ArithmeticException {@inheritDoc} */ @Override default ChronoLocalDate plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return ChronoLocalDateImpl.ensureValid(getChronology(), unit.addTo(this, amountToAdd)); }
Example #28
Source File: ChronoPeriodImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public long get(TemporalUnit unit) { if (unit == ChronoUnit.YEARS) { return years; } else if (unit == ChronoUnit.MONTHS) { return months; } else if (unit == ChronoUnit.DAYS) { return days; } else { throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } }
Example #29
Source File: LocalDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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); }
Example #30
Source File: LocalTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns a copy of this {@code LocalTime} with the time truncated. * <p> * Truncation returns a copy of the original time with fields * smaller than the specified unit set to zero. * For example, truncating with the {@link ChronoUnit#MINUTES minutes} unit * will set the second-of-minute and nano-of-second field to zero. * <p> * The unit must have a {@linkplain TemporalUnit#getDuration() duration} * that divides into the length of a standard day without remainder. * This includes all supplied time units on {@link ChronoUnit} and * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception. * <p> * This instance is immutable and unaffected by this method call. * * @param unit the unit to truncate to, not null * @return a {@code LocalTime} based on this time with the time truncated, not null * @throws DateTimeException if unable to truncate * @throws UnsupportedTemporalTypeException if the unit is not supported */ public LocalTime truncatedTo(TemporalUnit unit) { if (unit == ChronoUnit.NANOS) { return this; } Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > SECONDS_PER_DAY) { throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation"); } long dur = unitDur.toNanos(); if ((NANOS_PER_DAY % dur) != 0) { throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder"); } long nod = toNanoOfDay(); return ofNanoOfDay((nod / dur) * dur); }