Java Code Examples for java.time.temporal.TemporalAccessor#getClass()

The following examples show how to use java.time.temporal.TemporalAccessor#getClass() . 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: Chronology.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 2
Source File: Chronology.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 3
Source File: Chronology.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 4
Source File: Chronology.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 5
Source File: Chronology.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtains a {@code ChronoZonedDateTime} in this chronology from another temporal object.
 * <p>
 * This obtains a zoned date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion will first obtain a {@code ZoneId} from the temporal object,
 * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
 * an {@code Instant}, falling back to a {@code ChronoLocalDateTime} if necessary.
 * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
 * with {@code Instant} or {@code ChronoLocalDateTime}.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::zonedDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoZonedDateTime#from(TemporalAccessor)
 */
default ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
    try {
        ZoneId zone = ZoneId.from(temporal);
        try {
            Instant instant = Instant.from(temporal);
            return zonedDateTime(instant, zone);

        } catch (DateTimeException ex1) {
            ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
            return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
        }
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 6
Source File: ChronoZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoZonedDateTime} from a temporal object.
 * <p>
 * This creates a zoned date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion extracts and combines the chronology, date, time and zone
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#zonedDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoZonedDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoZonedDateTime}
 * @see Chronology#zonedDateTime(TemporalAccessor)
 */
static ChronoZonedDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoZonedDateTime) {
        return (ChronoZonedDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.zonedDateTime(temporal);
}
 
Example 7
Source File: ChronoLocalDate.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoLocalDate} from a temporal object.
 * <p>
 * This obtains a local date based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDate}.
 * <p>
 * The conversion extracts and combines the chronology and the date
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#date(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDate::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDate}
 * @see Chronology#date(TemporalAccessor)
 */
static ChronoLocalDate from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDate) {
        return (ChronoLocalDate) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDate from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.date(temporal);
}
 
Example 8
Source File: ChronoZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoZonedDateTime} from a temporal object.
 * <p>
 * This creates a zoned date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion extracts and combines the chronology, date, time and zone
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#zonedDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoZonedDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoZonedDateTime}
 * @see Chronology#zonedDateTime(TemporalAccessor)
 */
static ChronoZonedDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoZonedDateTime) {
        return (ChronoZonedDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.zonedDateTime(temporal);
}
 
Example 9
Source File: ChronoLocalDate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoLocalDate} from a temporal object.
 * <p>
 * This obtains a local date based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDate}.
 * <p>
 * The conversion extracts and combines the chronology and the date
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#date(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDate::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDate}
 * @see Chronology#date(TemporalAccessor)
 */
static ChronoLocalDate from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDate) {
        return (ChronoLocalDate) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDate from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.date(temporal);
}
 
Example 10
Source File: ChronoZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoZonedDateTime} from a temporal object.
 * <p>
 * This creates a zoned date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion extracts and combines the chronology, date, time and zone
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#zonedDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoZonedDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoZonedDateTime}
 * @see Chronology#zonedDateTime(TemporalAccessor)
 */
static ChronoZonedDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoZonedDateTime) {
        return (ChronoZonedDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.zonedDateTime(temporal);
}
 
Example 11
Source File: ChronoLocalDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoLocalDateTime} from a temporal object.
 * <p>
 * This obtains a local date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the chronology and the date-time
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#localDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDateTime}
 * @see Chronology#localDateTime(TemporalAccessor)
 */
static ChronoLocalDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDateTime) {
        return (ChronoLocalDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.localDateTime(temporal);
}
 
Example 12
Source File: Chronology.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains a local date-time in this chronology from another temporal object.
 * <p>
 * This obtains a date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the {@code ChronoLocalDate} and the
 * {@code LocalTime} from the temporal object.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::localDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoLocalDateTime#from(TemporalAccessor)
 */
default ChronoLocalDateTime<? extends ChronoLocalDate> localDateTime(TemporalAccessor temporal) {
    try {
        return date(temporal).atTime(LocalTime.from(temporal));
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 13
Source File: ChronoLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoLocalDateTime} from a temporal object.
 * <p>
 * This obtains a local date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the chronology and the date-time
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#localDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDateTime}
 * @see Chronology#localDateTime(TemporalAccessor)
 */
static ChronoLocalDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDateTime) {
        return (ChronoLocalDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.localDateTime(temporal);
}
 
Example 14
Source File: ChronoZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoZonedDateTime} from a temporal object.
 * <p>
 * This creates a zoned date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion extracts and combines the chronology, date, time and zone
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#zonedDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoZonedDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoZonedDateTime}
 * @see Chronology#zonedDateTime(TemporalAccessor)
 */
static ChronoZonedDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoZonedDateTime) {
        return (ChronoZonedDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.zonedDateTime(temporal);
}
 
Example 15
Source File: Chronology.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains a local date-time in this chronology from another temporal object.
 * <p>
 * This obtains a date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the {@code ChronoLocalDate} and the
 * {@code LocalTime} from the temporal object.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::localDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoLocalDateTime#from(TemporalAccessor)
 */
default ChronoLocalDateTime<? extends ChronoLocalDate> localDateTime(TemporalAccessor temporal) {
    try {
        return date(temporal).atTime(LocalTime.from(temporal));
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 16
Source File: ChronoLocalDateTime.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoLocalDateTime} from a temporal object.
 * <p>
 * This obtains a local date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the chronology and the date-time
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#localDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDateTime}
 * @see Chronology#localDateTime(TemporalAccessor)
 */
static ChronoLocalDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDateTime) {
        return (ChronoLocalDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.localDateTime(temporal);
}
 
Example 17
Source File: ChronoLocalDate.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoLocalDate} from a temporal object.
 * <p>
 * This obtains a local date based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDate}.
 * <p>
 * The conversion extracts and combines the chronology and the date
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#date(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDate::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDate}
 * @see Chronology#date(TemporalAccessor)
 */
static ChronoLocalDate from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDate) {
        return (ChronoLocalDate) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDate from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.date(temporal);
}
 
Example 18
Source File: Chronology.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Obtains a local date-time in this chronology from another temporal object.
 * <p>
 * This obtains a date-time in this chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the {@code ChronoLocalDate} and the
 * {@code LocalTime} from the temporal object.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * The result uses this chronology.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code aChronology::localDateTime}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the local date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 * @see ChronoLocalDateTime#from(TemporalAccessor)
 */
default ChronoLocalDateTime<? extends ChronoLocalDate> localDateTime(TemporalAccessor temporal) {
    try {
        return date(temporal).atTime(LocalTime.from(temporal));
    } catch (DateTimeException ex) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass(), ex);
    }
}
 
Example 19
Source File: ChronoZonedDateTime.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoZonedDateTime} from a temporal object.
 * <p>
 * This creates a zoned date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoZonedDateTime}.
 * <p>
 * The conversion extracts and combines the chronology, date, time and zone
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#zonedDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoZonedDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoZonedDateTime}
 * @see Chronology#zonedDateTime(TemporalAccessor)
 */
static ChronoZonedDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoZonedDateTime) {
        return (ChronoZonedDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.zonedDateTime(temporal);
}
 
Example 20
Source File: ChronoLocalDateTime.java    From desugar_jdk_libs with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code ChronoLocalDateTime} from a temporal object.
 * <p>
 * This obtains a local date-time based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code ChronoLocalDateTime}.
 * <p>
 * The conversion extracts and combines the chronology and the date-time
 * from the temporal object. The behavior is equivalent to using
 * {@link Chronology#localDateTime(TemporalAccessor)} with the extracted chronology.
 * Implementations are permitted to perform optimizations such as accessing
 * those fields that are equivalent to the relevant objects.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code ChronoLocalDateTime::from}.
 *
 * @param temporal  the temporal object to convert, not null
 * @return the date-time, not null
 * @throws DateTimeException if unable to convert to a {@code ChronoLocalDateTime}
 * @see Chronology#localDateTime(TemporalAccessor)
 */
static ChronoLocalDateTime<?> from(TemporalAccessor temporal) {
    if (temporal instanceof ChronoLocalDateTime) {
        return (ChronoLocalDateTime<?>) temporal;
    }
    Objects.requireNonNull(temporal, "temporal");
    Chronology chrono = temporal.query(TemporalQueries.chronology());
    if (chrono == null) {
        throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass());
    }
    return chrono.localDateTime(temporal);
}