Class InstantUtils
java.lang.Object
com.thanlinardos.spring_enterprise_library.time.utils.InstantUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InstantaddDefault(Instant instant, long amount) Adds the given amount of the default accuracy to the given instant.static InstantAdds a single unit of the default accuracy to the given instant.static InstantfromEndOfLocalDate(LocalDate date) Converts a LocalDate to an Instant at the end of the given date's day in the default time zone and represented with the default accuracy.static InstantfromEndOfLocalDate(LocalDate date, TimeUnit accuracy, ZoneOffset zoneOffset) Converts a LocalDate to an Instant at the end of the day in the specified ZoneOffset and accuracy.static InstantfromLocalDate(LocalDate date) Converts a LocalDate to an Instant at the start of the day in the default time zone.static InstantfromLocalDate(LocalDate date, ZoneOffset zoneOffset) Converts a LocalDate to an Instant at the start of the day in the specified ZoneOffset.static booleanisAfterNullAsMax(Instant instant1, Instant instant2) Checks if instant1 is after instant2, treating null asTimeFactory.getMaxInstant().static booleanisAfterOrEqual(Instant instant1, Instant instant2) Checks if instant1 is after or equal to instant2, treating null asTimeFactory.getMinInstant().static booleanisBeforeNullAsMin(Instant instant1, Instant instant2) Checks if instant1 is before instant2, treating null asTimeFactory.getMinInstant().static booleanisBeforeOrEqual(Instant instant1, Instant instant2) Checks if instant1 is before or equal to instant2, treating null asTimeFactory.getMaxInstant().static InstantmaxNullAsMax(Instant instant1, Instant instant2) Returns the maximum of two Instants, treating null asTimeFactory.getMaxInstant().static InstantmaxNullAsMin(Instant instant1, Instant instant2) Returns the maximum of two Instants, treating null asTimeFactory.getMaxInstant().static InstantminNullAsMax(Instant instant1, Instant instant2) Returns the minimum of two Instants, treating null asTimeFactory.getMaxInstant().static InstantminNullAsMin(Instant instant1, Instant instant2) Returns the minimum of two Instants, treating null asTimeFactory.getMinInstant().static InstantparseInstant(String start) Parses an Instant string using the default parser inInstant.parse(CharSequence).static InstantparseInstant(String date, Function<String, Instant> parser) Parses an Instant string using the provided parser function.static InstantsubtractDefault(Instant instant, long amount) Adds the given amount of the default accuracy to the given instant.static InstantsubtractDefault(Instant temporal, long amount, TimeUnit accuracy) Subtracts the given amount of the specified accuracy from the given instant.static InstantsubtractSingle(Instant instant) Subtracts a single unit of the default accuracy from the given instant.static InstantsubtractSingle(Instant temporal, TimeUnit accuracy) Subtracts a single unit of the specified accuracy from the given instant.static LocalDatetoLocalDate(Instant instant) Converts an Instant to a LocalDate in the default time zone.
-
Constructor Details
-
InstantUtils
public InstantUtils()
-
-
Method Details
-
parseInstant
Parses an Instant string using the default parser inInstant.parse(CharSequence).- Parameters:
start- the Instant string to parse.- Returns:
- the parsed Instant, or null if the input string is empty.
-
parseInstant
Parses an Instant string using the provided parser function.- Parameters:
date- the Instant string to parse.parser- the function to parse the Instant.- Returns:
- the parsed Instant, or null if the input string is empty.
-
fromLocalDate
-
fromLocalDate
Converts a LocalDate to an Instant at the start of the day in the specified ZoneOffset.- Parameters:
date- the LocalDate to convert.zoneOffset- the ZoneOffset to use for conversion.- Returns:
- the corresponding Instant, or null if the input date is null.
-
fromEndOfLocalDate
Converts a LocalDate to an Instant at the end of the given date's day in the default time zone and represented with the default accuracy.For example, if the default accuracy is MILLISECONDS, then result will be: '
dateT23:59:59.999'.- Parameters:
date- the LocalDate to convert.- Returns:
- the corresponding Instant, or null if the input date is null.
-
fromEndOfLocalDate
@Nullable public static Instant fromEndOfLocalDate(@Nullable LocalDate date, TimeUnit accuracy, ZoneOffset zoneOffset) Converts a LocalDate to an Instant at the end of the day in the specified ZoneOffset and accuracy. SeefromEndOfLocalDate(LocalDate)for details.- Parameters:
date- the LocalDate to convert.accuracy- the TimeUnit accuracy to use to represent the resulting Instant.zoneOffset- the ZoneOffset to use for conversion.- Returns:
- the corresponding Instant, or null if the input date is null.
-
toLocalDate
-
isBeforeNullAsMin
Checks if instant1 is before instant2, treating null asTimeFactory.getMinInstant().- Parameters:
instant1- The first date to compare.instant2- The second date to compare.- Returns:
- true if instant1 is before instant2, false otherwise.
-
isAfterNullAsMax
Checks if instant1 is after instant2, treating null asTimeFactory.getMaxInstant().- Parameters:
instant1- The first date to compare.instant2- The second date to compare.- Returns:
- true if instant1 is after instant2, false otherwise.
-
isBeforeOrEqual
Checks if instant1 is before or equal to instant2, treating null asTimeFactory.getMaxInstant().- Parameters:
instant1- The first date to compare.instant2- The second date to compare.- Returns:
- true if instant1 is before or equal to instant2, false otherwise.
-
isAfterOrEqual
Checks if instant1 is after or equal to instant2, treating null asTimeFactory.getMinInstant().- Parameters:
instant1- The first date to compare.instant2- The second date to compare.- Returns:
- true if instant1 is after or equal to instant2, false otherwise.
-
maxNullAsMax
Returns the maximum of two Instants, treating null asTimeFactory.getMaxInstant().- Parameters:
instant1- the first instant.instant2- the second instant.- Returns:
- the maximum of the two instants.
-
minNullAsMin
Returns the minimum of two Instants, treating null asTimeFactory.getMinInstant().- Parameters:
instant1- the first instant.instant2- the second instant.- Returns:
- the minimum of the two instants.
-
maxNullAsMin
Returns the maximum of two Instants, treating null asTimeFactory.getMaxInstant().- Parameters:
instant1- the first instant.instant2- the second instant.- Returns:
- the maximum of the two instants.
-
minNullAsMax
Returns the minimum of two Instants, treating null asTimeFactory.getMaxInstant().- Parameters:
instant1- the first instant.instant2- the second instant.- Returns:
- the minimum of the two instants.
-
addDefault
-
addSingle
-
subtractDefault
-
subtractSingle
-
subtractDefault
@Nullable public static Instant subtractDefault(@Nullable Instant temporal, long amount, TimeUnit accuracy) Subtracts the given amount of the specified accuracy from the given instant.- Parameters:
temporal- the instant to subtract from.amount- the amount to subtract.accuracy- the TimeUnit accuracy to use for the subtraction.- Returns:
- the resulting instant, or null if the input instant is null.
-
subtractSingle
Subtracts a single unit of the specified accuracy from the given instant.- Parameters:
temporal- the instant to subtract from.accuracy- the TimeUnit accuracy to use for the subtraction.- Returns:
- the resulting instant, or null if the input instant is null.
-