Record Class TimeProviderImpl
java.lang.Object
java.lang.Record
com.thanlinardos.spring_enterprise_library.time.TimeProviderImpl
- Record Components:
zoneId- the time zone to use for date and time operations.accuracy- the default accuracy to use for date and time operations.maxDate- the maximum date that can be used in the system.minDate- the minimum date that can be used in the system.maxDateTime- the maximum date time that can be used in the system.minDateTime- the minimum date time that can be used in the system.
- All Implemented Interfaces:
TimeProvider
public record TimeProviderImpl(ZoneId zoneId, TimeUnit accuracy, LocalDate maxDate, LocalDate minDate, LocalDateTime maxDateTime, LocalDateTime minDateTime)
extends Record
implements TimeProvider
Default implementation of
TimeProvider interface.-
Constructor Summary
ConstructorsConstructorDescriptionTimeProviderImpl(ZoneId zoneId, TimeUnit accuracy, LocalDate maxDate, LocalDate minDate, LocalDateTime maxDateTime, LocalDateTime minDateTime) Creates an instance of aTimeProviderImplrecord class. -
Method Summary
Modifier and TypeMethodDescriptionaccuracy()Returns the value of theaccuracyrecord component.final booleanIndicates whether some other object is "equal to" this one.fromMillis(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 LocalDatefinal inthashCode()Returns a hash code value for this object.instantFromNowPlusSeconds(long seconds) Creates anInstantIntervalstarting from now plus the given seconds.maxDate()Returns the value of themaxDaterecord component.Returns the value of themaxDateTimerecord component.minDate()Returns the value of theminDaterecord component.Returns the value of theminDateTimerecord component.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-zonefinal StringtoString()Returns a string representation of this record class.zoneId()Returns the value of thezoneIdrecord component.
-
Constructor Details
-
TimeProviderImpl
public TimeProviderImpl(ZoneId zoneId, TimeUnit accuracy, LocalDate maxDate, LocalDate minDate, LocalDateTime maxDateTime, LocalDateTime minDateTime) Creates an instance of aTimeProviderImplrecord class.- Parameters:
zoneId- the value for thezoneIdrecord componentaccuracy- the value for theaccuracyrecord componentmaxDate- the value for themaxDaterecord componentminDate- the value for theminDaterecord componentmaxDateTime- the value for themaxDateTimerecord componentminDateTime- the value for theminDateTimerecord component
-
-
Method Details
-
getDefaultZone
Description copied from interface:TimeProviderGets the default ZoneOffset of the TimeProvider- Specified by:
getDefaultZonein interfaceTimeProvider- Returns:
- the default ZoneOffset
-
getChronoAccuracy
Description copied from interface:TimeProviderGets the accuracy of the TimeProvider as ChronoUnit- Specified by:
getChronoAccuracyin interfaceTimeProvider- Returns:
- the accuracy as ChronoUnit
-
getCurrentDateTime
Description copied from interface:TimeProviderObtains the current date-time from the system clock in the specified time-zone- Specified by:
getCurrentDateTimein interfaceTimeProvider- Returns:
- the current date-time of specific time zone
-
getCurrentInstant
Description copied from interface:TimeProviderObtains the current instant from the system clock in the default time-zone- Specified by:
getCurrentInstantin interfaceTimeProvider- Returns:
- the current instant of specific time zone
-
getCurrentDate
Description copied from interface:TimeProviderObtains the current date from the system clock in the specified time-zone- Specified by:
getCurrentDatein interfaceTimeProvider- Returns:
- the current date of specific time zone
-
getCurrentTimeMillis
public long getCurrentTimeMillis()Description copied from interface:TimeProviderObtains the current time in milliseconds from the system clock in the specified time-zone.- Specified by:
getCurrentTimeMillisin interfaceTimeProvider- Returns:
- the current time in milliseconds.
-
fromMillis
Description copied from interface:TimeProviderObtains an instance of LocalDateTime from provided milliseconds in the specified time-zone- Specified by:
fromMillisin interfaceTimeProvider- Parameters:
milliseconds- the milliseconds to convert- Returns:
- LocalDateTime object from milliseconds
-
toMillis
Description copied from interface:TimeProviderConverts this LocalDateTime to the number of milliseconds from the epoch of 1970-01-01T00:00:00Z in the specified time-zone- Specified by:
toMillisin interfaceTimeProvider- Parameters:
ldt- the LocalDateTime to convert- Returns:
- number of milliseconds from LocalDateTime object from epoch
-
getEndOfDay
Description copied from interface:TimeProviderReturns 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)- Specified by:
getEndOfDayin interfaceTimeProvider- Parameters:
date- the given date- Returns:
- number of milliseconds from LocalDateTime object from epoch
-
getStartOfDay
Description copied from interface:TimeProviderReturns the LocalDateTime with the start time of the day based on the given LocalDate- Specified by:
getStartOfDayin interfaceTimeProvider- Parameters:
date- the given date- Returns:
- number of milliseconds from LocalDateTime object from epoch
-
getFirstDayOfQuarter
Description copied from interface:TimeProviderReturns 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)
- Specified by:
getFirstDayOfQuarterin interfaceTimeProvider- Parameters:
dateInQuarter- - any date in the quarter- Returns:
- First day of quarter
-
getLastDayOfQuarter
Description copied from interface:TimeProviderReturns 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)
- Specified by:
getLastDayOfQuarterin interfaceTimeProvider- Parameters:
dateInQuarter- - any date in the quarter- Returns:
- First day of quarter
-
getFirstDayOfYear
Description copied from interface:TimeProviderReturn new instance of LocalDate with first day of the year.- Specified by:
getFirstDayOfYearin interfaceTimeProvider- Parameters:
date- - any date in the year- Returns:
- First day of year
-
getLastDayOfYear
Description copied from interface:TimeProviderReturn new instance of LocalDate with last day of the year.- Specified by:
getLastDayOfYearin interfaceTimeProvider- Parameters:
date- - any date in the year- Returns:
- First day of year
-
instantFromNowPlusSeconds
Description copied from interface:TimeProviderCreates anInstantIntervalstarting from now plus the given seconds.- Specified by:
instantFromNowPlusSecondsin interfaceTimeProvider- Parameters:
seconds- the number of seconds to add to the current instant.- Returns:
- an
InstantIntervalstarting from now plus the given seconds.
-
timeFromNowPlusSeconds
Description copied from interface:TimeProviderCreates aTimeIntervalstarting from now plus the given seconds.- Specified by:
timeFromNowPlusSecondsin interfaceTimeProvider- Parameters:
seconds- the number of seconds to add to the current time.- Returns:
- a
TimeIntervalstarting from now plus the given seconds.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
zoneId
Returns the value of thezoneIdrecord component.- Specified by:
zoneIdin interfaceTimeProvider- Returns:
- the value of the
zoneIdrecord component
-
accuracy
Returns the value of theaccuracyrecord component.- Specified by:
accuracyin interfaceTimeProvider- Returns:
- the value of the
accuracyrecord component
-
maxDate
Returns the value of themaxDaterecord component.- Specified by:
maxDatein interfaceTimeProvider- Returns:
- the value of the
maxDaterecord component
-
minDate
Returns the value of theminDaterecord component.- Specified by:
minDatein interfaceTimeProvider- Returns:
- the value of the
minDaterecord component
-
maxDateTime
Returns the value of themaxDateTimerecord component.- Specified by:
maxDateTimein interfaceTimeProvider- Returns:
- the value of the
maxDateTimerecord component
-
minDateTime
Returns the value of theminDateTimerecord component.- Specified by:
minDateTimein interfaceTimeProvider- Returns:
- the value of the
minDateTimerecord component
-