public interface DateProvider
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.
Modifier and Type | Method and Description |
---|---|
LocalDate |
toLocalDate()
Returns an instance of
LocalDate initialized from the
state of this object. |
LocalDate toLocalDate()
LocalDate
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 a LocalDate
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.
LocalDate
equivalent to this object, never nullCalendricalException
- if the date cannot be convertedCopyright © 2014. All rights reserved.