Interface DateProvider
- All Known Subinterfaces:
DateTimeProvider
- All Known Implementing Classes:
CopticDate
,HistoricDate
,LocalDate
,LocalDateTime
,OffsetDate
,OffsetDateTime
,ZonedDateTime
DateProvider is a simple interface that provides uniform access to any object that can provide access to a date in the ISO-8601 calendar system.
The implementation of DateProvider
may be mutable.
For example, GregorianCalendar
is a
mutable implementation of this interface.
The result of toLocalDate()
, however, is immutable.
When implementing an API that accepts a DateProvider as a parameter, it is
important to convert the input to a LocalDate
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 toLocalDate()
.
The recommended way to convert a DateProvider to a LocalDate is using
LocalDate.of(DateProvider)
as this method provides additional null checking.
The implementation of DateProvider
may provide more
information than just a local date. For example, OffsetDate
,
implements this interface and also provides a zone offset.
DateProvider makes no guarantees about the thread-safety or immutability of implementations.
-
Method Summary
Modifier and TypeMethodDescriptionReturns an instance ofLocalDate
initialized from the state of this object.
-
Method Details
-
toLocalDate
LocalDate toLocalDate()Returns an instance ofLocalDate
initialized from the state of this object.This method will take the date represented by this object and return a
LocalDate
constructed using the year, month and day. If this object is already aLocalDate
then it is simply returned.The result of this method is a
LocalDate
which represents a date in the ISO calendar system. Implementors may perform conversion when implementing this method to convert from alternate calendar systems.- Returns:
- the
LocalDate
equivalent to this object, never null - Throws:
CalendricalException
- if the date cannot be converted
-