Interface DateTimeProvider
- All Superinterfaces:
DateProvider, TimeProvider
- All Known Implementing Classes:
LocalDateTime, OffsetDateTime, ZonedDateTime
DateTimeProvider is a simple interface that provides uniform access to any object that can provide access to a date-time in the ISO-8601 calendar system.
The implementation of DateTimeProvider may be mutable.
For example, GregorianCalendar is a
mutable implementation of this interface.
The result of toLocalDateTime(), however, is immutable.
When implementing an API that accepts a DateTimeProvider as a parameter, it is
important to convert the input to a LocalDateTime once and once only.
It is recommended that this is done at the top of the method before other processing.
This is necessary to handle the case where the implementation of the provider is
mutable and changes in value between two calls to toLocalDateTime().
The recommended way to convert a DateTimeProvider to a LocalDateTime is using
LocalDateTime.of(DateTimeProvider) as this method provides additional null checking.
It is recommended that this interface should only be implemented by classes that provide time information to at least minute precision.
The implementation of DateTimeProvider may provide more
information than just a local date-time. For example, ZonedDateTime,
implements this interface and also provides a time-zone.
DateTimeProvider makes no guarantees about the thread-safety or immutability of implementations.
-
Method Summary
Modifier and TypeMethodDescriptionReturns an instance ofLocalDateTimeinitialized from the state of this object.Methods inherited from interface DateProvider
toLocalDateMethods inherited from interface TimeProvider
toLocalTime
-
Method Details
-
toLocalDateTime
LocalDateTime toLocalDateTime()Returns an instance ofLocalDateTimeinitialized from the state of this object.This method will take the date-time represented by this object and return a
LocalDateTimeconstructed using the year, month, day, hour, minute, second and nanosecond. If this object is already aLocalDateTimethen it is simply returned.If this object does not support nanosecond precision, then all fields below the precision it does support must be set to zero. For example, if this instance only stores hours, minutes and seconds, then the nanoseconds part will be set to zero.
The result of this method is a
LocalDateTimewhich represents a date in the ISO calendar system. Implementors may perform conversion when implementing this method to convert from alternate calendar systems.- Returns:
- the
LocalDateTimeequivalent to this object, never null - Throws:
CalendricalException- if the date-time cannot be converted
-