Java Code Examples for org.threeten.bp.temporal.TemporalField#getFrom()
The following examples show how to use
org.threeten.bp.temporal.TemporalField#getFrom() .
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: HijrahDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case DAY_OF_WEEK: return dayOfWeek.getValue(); case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfMonth - 1) % 7) + 1; case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((dayOfYear - 1) % 7) + 1; case DAY_OF_MONTH: return this.dayOfMonth; case DAY_OF_YEAR: return this.dayOfYear; case EPOCH_DAY: return toEpochDay(); case ALIGNED_WEEK_OF_MONTH: return ((dayOfMonth - 1) / 7) + 1; case ALIGNED_WEEK_OF_YEAR: return ((dayOfYear - 1) / 7) + 1; case MONTH_OF_YEAR: return monthOfYear; case YEAR_OF_ERA: return yearOfEra; case YEAR: return yearOfEra; case ERA: return era.getValue(); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }
Example 2
Source File: JapaneseDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { 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: return getDayOfYear(); } return isoDate.getLong(field); } return field.getFrom(this); }
Example 3
Source File: ThaiBuddhistDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case PROLEPTIC_MONTH: return getProlepticMonth(); case YEAR_OF_ERA: { int prolepticYear = getProlepticYear(); return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear); } case YEAR: return getProlepticYear(); case ERA: return (getProlepticYear() >= 1 ? 1 : 0); } return isoDate.getLong(field); } return field.getFrom(this); }
Example 4
Source File: MinguoDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case PROLEPTIC_MONTH: return getProlepticMonth(); case YEAR_OF_ERA: { int prolepticYear = getProlepticYear(); return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear); } case YEAR: return getProlepticYear(); case ERA: return (getProlepticYear() >= 1 ? 1 : 0); } return isoDate.getLong(field); } return field.getFrom(this); }
Example 5
Source File: ChronoLocalDateTimeImpl.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { return (field.isTimeBased() ? time.getLong(field) : date.getLong(field)); } return field.getFrom(this); }
Example 6
Source File: DefaultInterfaceEra.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public long getLong(TemporalField field) { if (field == ERA) { return getValue(); } else if (field instanceof ChronoField) { throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }
Example 7
Source File: ChronoZonedDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case INSTANT_SECONDS: return toEpochSecond(); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } return toLocalDateTime().getLong(field); } return field.getFrom(this); }
Example 8
Source File: ZonedDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this date-time as a {@code long}. * <p> * This queries this date-time for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this date-time. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case INSTANT_SECONDS: return toEpochSecond(); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } return dateTime.getLong(field); } return field.getFrom(this); }
Example 9
Source File: ZoneOffset.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this offset as a {@code long}. * <p> * This queries this offset for the value for the specified field. * If it is not possible to return the value, 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 {@code OFFSET_SECONDS} field returns the value of the offset. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field == OFFSET_SECONDS) { return totalSeconds; } else if (field instanceof ChronoField) { throw new DateTimeException("Unsupported field: " + field); } return field.getFrom(this); }
Example 10
Source File: Year.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this year as a {@code long}. * <p> * This queries this year for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this year. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case YEAR_OF_ERA: return (year < 1 ? 1 - year : year); case YEAR: return year; case ERA: return (year < 1 ? 0 : 1); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }
Example 11
Source File: OffsetTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this time as a {@code long}. * <p> * This queries this time for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this time. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { if (field == OFFSET_SECONDS) { return getOffset().getTotalSeconds(); } return time.getLong(field); } return field.getFrom(this); }
Example 12
Source File: LocalDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this date-time as a {@code long}. * <p> * This queries this date-time for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this date-time. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { return (field.isTimeBased() ? time.getLong(field) : date.getLong(field)); } return field.getFrom(this); }
Example 13
Source File: LocalDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this date as a {@code long}. * <p> * This queries this date for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this date. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { if (field == EPOCH_DAY) { return toEpochDay(); } if (field == PROLEPTIC_MONTH) { return getProlepticMonth(); } return get0(field); } return field.getFrom(this); }
Example 14
Source File: LocalTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this time as a {@code long}. * <p> * This queries this time for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this time. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { if (field == NANO_OF_DAY) { return toNanoOfDay(); } if (field == MICRO_OF_DAY) { return toNanoOfDay() / 1000; } return get0(field); } return field.getFrom(this); }
Example 15
Source File: OffsetDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this date-time as a {@code long}. * <p> * This queries this date-time for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this date-time. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case INSTANT_SECONDS: return toEpochSecond(); case OFFSET_SECONDS: return getOffset().getTotalSeconds(); } return dateTime.getLong(field); } return field.getFrom(this); }
Example 16
Source File: MonthDay.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this month-day as a {@code long}. * <p> * This queries this month-day for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this month-day. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { // alignedDOW and alignedWOM not supported because they cannot be set in with() case DAY_OF_MONTH: return day; case MONTH_OF_YEAR: return month; } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }
Example 17
Source File: Instant.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this instant as a {@code long}. * <p> * This queries this instant for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this date-time. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case NANO_OF_SECOND: return nanos; case MICRO_OF_SECOND: return nanos / 1000; case MILLI_OF_SECOND: return nanos / NANOS_PER_MILLI; case INSTANT_SECONDS: return seconds; } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }
Example 18
Source File: YearMonth.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Gets the value of the specified field from this year-month as a {@code long}. * <p> * This queries this year-month for the value for the specified field. * If it is not possible to return the value, 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 valid * values based on this year-month. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case MONTH_OF_YEAR: return month; case PROLEPTIC_MONTH: return getProlepticMonth(); case YEAR_OF_ERA: return (year < 1 ? 1 - year : year); case YEAR: return year; case ERA: return (year < 1 ? 0 : 1); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }