Interface DateProvider
-
- All Known Subinterfaces:
DateTimeProvider
- All Known Implementing Classes:
CopticDate,HistoricDate,LocalDate,LocalDateTime,OffsetDate,OffsetDateTime,ZonedDateTime
public interface DateProviderProvides access to a date in the ISO-8601 calendar system.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
DateProvidermay be mutable. For example,GregorianCalendaris a mutable implementation of this interface. The result oftoLocalDate(), however, is immutable.When implementing an API that accepts a DateProvider as a parameter, it is important to convert the input to a
LocalDateonce 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 totoLocalDate().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
DateProvidermay 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description LocalDatetoLocalDate()Returns an instance ofLocalDateinitialized from the state of this object.
-
-
-
Method Detail
-
toLocalDate
LocalDate toLocalDate()
Returns an instance ofLocalDateinitialized from the state of this object.This method will take the date represented by this object and return a
LocalDateconstructed using the year, month and day. If this object is already aLocalDatethen it is simply returned.The result of this method is a
LocalDatewhich represents a date in the ISO calendar system. Implementors may perform conversion when implementing this method to convert from alternate calendar systems.- Returns:
- the
LocalDateequivalent to this object, never null - Throws:
CalendricalException- if the date cannot be converted
-
-