Interface TimeProvider
- All Known Implementing Classes:
TimeProviderImpl
public interface TimeProvider
TimeProvider is an interface that provides methods to obtain the current date and time,
the default
TimeUnit accuracy to use, the time zone and over configured values
that are used across the application when handling date and date-time data.-
Method Summary
Modifier and TypeMethodDescriptionaccuracy()Gets the accuracy of the TimeProvider as TimeUnitfromMillis(long milliseconds) Obtains an instance of LocalDateTime from provided milliseconds in the specified time-zoneGets the accuracy of the TimeProvider as ChronoUnitObtains the current date from the system clock in the specified time-zoneObtains the current date-time from the system clock in the specified time-zoneObtains the current instant from the system clock in the default time-zonelongObtains the current time in milliseconds from the system clock in the specified time-zone.Gets the default ZoneOffset of the TimeProvidergetEndOfDay(LocalDate date) Returns LocalDateTime with the time of the end of the day based on given LocalDate NOTE: Returned time will be 23:59 (where LocalTime.MAX is 23:59:59.999999999)getFirstDayOfQuarter(LocalDate dateInQuarter) Returns new instance of LocalDate with first day of quarter for given date.getFirstDayOfYear(LocalDate date) Return new instance of LocalDate with first day of the year.getLastDayOfQuarter(LocalDate dateInQuarter) Returns new instance of LocalDate with last day of quarter for given date.getLastDayOfYear(LocalDate date) Return new instance of LocalDate with last day of the year.getStartOfDay(LocalDate date) Returns the LocalDateTime with the start time of the day based on the given LocalDateinstantFromNowPlusSeconds(long seconds) Creates anInstantIntervalstarting from now plus the given seconds.maxDate()Gets the maximum date that can be used in the system.Gets the maximum date time that can be used in the system.minDate()Gets the minimum date that can be used in the system.Gets the minimum date time that can be used in the system.timeFromNowPlusSeconds(long seconds) Creates aTimeIntervalstarting from now plus the given seconds.longtoMillis(LocalDateTime ldt) Converts this LocalDateTime to the number of milliseconds from the epoch of 1970-01-01T00:00:00Z in the specified time-zonezoneId()Gets the time zone of the TimeProvider
-
Method Details
-
accuracy
TimeUnit accuracy()Gets the accuracy of the TimeProvider as TimeUnit- Returns:
- the accuracy as TimeUnit
-
getDefaultZone
ZoneOffset getDefaultZone()Gets the default ZoneOffset of the TimeProvider- Returns:
- the default ZoneOffset
-
getChronoAccuracy
ChronoUnit getChronoAccuracy()Gets the accuracy of the TimeProvider as ChronoUnit- Returns:
- the accuracy as ChronoUnit
-
getCurrentDateTime
LocalDateTime getCurrentDateTime()Obtains the current date-time from the system clock in the specified time-zone- Returns:
- the current date-time of specific time zone
-
getCurrentInstant
Instant getCurrentInstant()Obtains the current instant from the system clock in the default time-zone- Returns:
- the current instant of specific time zone
-
getCurrentDate
LocalDate getCurrentDate()Obtains the current date from the system clock in the specified time-zone- Returns:
- the current date of specific time zone
-
getCurrentTimeMillis
long getCurrentTimeMillis()Obtains the current time in milliseconds from the system clock in the specified time-zone.- Returns:
- the current time in milliseconds.
-
fromMillis
Obtains an instance of LocalDateTime from provided milliseconds in the specified time-zone- Parameters:
milliseconds- the milliseconds to convert- Returns:
- LocalDateTime object from milliseconds
-
toMillis
Converts this LocalDateTime to the number of milliseconds from the epoch of 1970-01-01T00:00:00Z in the specified time-zone- Parameters:
ldt- the LocalDateTime to convert- Returns:
- number of milliseconds from LocalDateTime object from epoch
-
getEndOfDay
Returns LocalDateTime with the time of the end of the day based on given LocalDate NOTE: Returned time will be 23:59 (where LocalTime.MAX is 23:59:59.999999999)- Parameters:
date- the given date- Returns:
- number of milliseconds from LocalDateTime object from epoch
-
getStartOfDay
Returns the LocalDateTime with the start time of the day based on the given LocalDate- Parameters:
date- the given date- Returns:
- number of milliseconds from LocalDateTime object from epoch
-
getFirstDayOfQuarter
Returns new instance of LocalDate with first day of quarter for given date.getFirstDayOfQuarter(LocalDate.of(2016, 2, 29)) == LocalDate.of(2016,1,1) getFirstDayOfQuarter(LocalDate.of(2017, 10, 16)) == LocalDate.of(2017,10,1)
- Parameters:
dateInQuarter- - any date in the quarter- Returns:
- First day of quarter
-
getLastDayOfQuarter
Returns new instance of LocalDate with last day of quarter for given date.getFirstDayOfQuarter(LocalDate.of(2016, 2, 29)) == LocalDate.of(2016, 3, 31) getFirstDayOfQuarter(LocalDate.of(2017, 10, 16)) == LocalDate.of(2017,12,31)
- Parameters:
dateInQuarter- - any date in the quarter- Returns:
- First day of quarter
-
getFirstDayOfYear
-
getLastDayOfYear
-
zoneId
-
maxDate
LocalDate maxDate()Gets the maximum date that can be used in the system.- Returns:
- the maximum date.
-
minDate
LocalDate minDate()Gets the minimum date that can be used in the system.- Returns:
- the minimum date.
-
maxDateTime
LocalDateTime maxDateTime()Gets the maximum date time that can be used in the system.- Returns:
- the maximum date time.
-
minDateTime
LocalDateTime minDateTime()Gets the minimum date time that can be used in the system.- Returns:
- the minimum date time.
-
instantFromNowPlusSeconds
Creates anInstantIntervalstarting from now plus the given seconds.- Parameters:
seconds- the number of seconds to add to the current instant.- Returns:
- an
InstantIntervalstarting from now plus the given seconds.
-
timeFromNowPlusSeconds
Creates aTimeIntervalstarting from now plus the given seconds.- Parameters:
seconds- the number of seconds to add to the current time.- Returns:
- a
TimeIntervalstarting from now plus the given seconds.
-