public interface TimeProvider
TimeProvider is a simple interface that provides uniform access to any object that can provide access to a time in the ISO-8601 calendar system.
The implementation of TimeProvider
may be mutable.
For example, GregorianCalendar
is a
mutable implementation of this interface.
The result of toLocalTime()
, however, is immutable.
When implementing an API that accepts a TimeProvider as a parameter, it is
important to convert the input to a LocalTime
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 toLocalTime()
.
The recommended way to convert a TimeProvider to a LocalTime is using
LocalTime.of(TimeProvider)
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 TimeProvider
may provide more
information than just a time. For example, OffsetTime
,
implements this interface and also provides a zone offset.
TimeProvider makes no guarantees about the thread-safety or immutability of implementations.
Modifier and Type | Method and Description |
---|---|
LocalTime |
toLocalTime()
Returns an instance of
LocalTime initialized from the
state of this object. |
LocalTime toLocalTime()
LocalTime
initialized from the
state of this object.
This method will take the time represented by this object and return
a LocalTime
constructed using the hour, minute, second and
nanosecond. If this object is already a LocalTime
then
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 LocalTime
which represents
a time in the ISO calendar system. Implementors may perform conversion
when implementing this method to convert from alternate calendar systems.
LocalTime
equivalent to this object, never nullCalendricalException
- if the time cannot be convertedCopyright © 2014. All rights reserved.