Class DateUtils
java.lang.Object
com.thanlinardos.spring_enterprise_library.time.utils.DateUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalDateAdds one day to the given date.static LocalDateAdds the specified number of days to the given date.static ZonedDateTimeepochMilliToZonedDateTime(Long epochMilli) Converts epoch milliseconds toZonedDateTimein the system default time zoneTimeFactory.getDefaultZoneId().static longgetEpochMilliFromLocalDateTime(LocalDateTime localDateTime) ConvertsLocalDateTimeto epoch milliseconds in the system default time zoneTimeFactory.getDefaultZoneId().static LocalDategetLastDayOfYear(Year year) Gets the first day of the given year.static LocalDategetLocalDateFromEpochMilli(Long epochMilli) Converts epoch milliseconds toLocalDatein the system default time zoneTimeFactory.getDefaultZoneId().static LocalDateTimegetLocalDateTimeFromEpochMilli(Long epochMilli) Converts epoch milliseconds toLocalDateTimein the system default time zoneTimeFactory.getDefaultZoneId().static booleanisAfterNullAsMax(LocalDate date1, LocalDate date2) Checks if date1 is after date2, treating null asTimeFactory.getMaxDate().static booleanisAfterOrEqual(LocalDate date1, LocalDate date2) Checks if date1 is after or equal to date2, treating null asTimeFactory.getMaxDate().static booleanisBeforeNullAsMin(LocalDate date1, LocalDate date2) Checks if date1 is before date2, treating null asTimeFactory.getMinDate().static booleanisBeforeOrEqual(LocalDate date1, LocalDate date2) Checks if date1 is before or equal to date2, treating null asTimeFactory.getMinDate().static LocalDatemaxNullAsMax(LocalDate date1, LocalDate date2) Returns the maximum of two LocalDate values, treating null as the maximum possible date.static LocalDatemaxNullAsMin(LocalDate date1, LocalDate date2) Returns the maximum of two LocalDate values, treating null as the minimum possible date.static LocalDateminNullAsMax(LocalDate date1, LocalDate date2) Returns the minimum of two LocalDate values, treating null as the maximum possible date.static LocalDateminNullAsMin(LocalDate date1, LocalDate date2) Returns the minimum of two LocalDate values, treating null as the minimum possible date.static LocalDateParses a date string using the provided parser function.static LocalDateparseLocalDate(String startDate) Parses a date string into a LocalDate using the default parser fromLocalDate.parse(CharSequence).static LocalDatesubtractDay(LocalDate date) Subtracts one day from the given date.
-
Constructor Details
-
DateUtils
public DateUtils()
-
-
Method Details
-
getLastDayOfYear
-
getLocalDateTimeFromEpochMilli
Converts epoch milliseconds toLocalDateTimein the system default time zoneTimeFactory.getDefaultZoneId().- Parameters:
epochMilli- the epoch milliseconds to convert.- Returns:
- the corresponding
LocalDateTime.
-
getLocalDateFromEpochMilli
Converts epoch milliseconds toLocalDatein the system default time zoneTimeFactory.getDefaultZoneId().- Parameters:
epochMilli- the epoch milliseconds to convert.- Returns:
- the corresponding
LocalDate.
-
epochMilliToZonedDateTime
Converts epoch milliseconds toZonedDateTimein the system default time zoneTimeFactory.getDefaultZoneId().- Parameters:
epochMilli- the epoch milliseconds to convert.- Returns:
- the corresponding
ZonedDateTime.
-
getEpochMilliFromLocalDateTime
ConvertsLocalDateTimeto epoch milliseconds in the system default time zoneTimeFactory.getDefaultZoneId().- Parameters:
localDateTime- theLocalDateTimeto convert.- Returns:
- the corresponding epoch milliseconds.
-
isBeforeNullAsMin
Checks if date1 is before date2, treating null asTimeFactory.getMinDate().- Parameters:
date1- The first date to compare.date2- The second date to compare.- Returns:
- true if date1 is before date2, false otherwise.
-
isAfterNullAsMax
Checks if date1 is after date2, treating null asTimeFactory.getMaxDate().- Parameters:
date1- The first date to compare.date2- The second date to compare.- Returns:
- true if date1 is after date2, false otherwise.
-
isBeforeOrEqual
Checks if date1 is before or equal to date2, treating null asTimeFactory.getMinDate().- Parameters:
date1- The first date to compare.date2- The second date to compare.- Returns:
- true if date1 is before or equal to date2, false otherwise.
-
isAfterOrEqual
Checks if date1 is after or equal to date2, treating null asTimeFactory.getMaxDate().- Parameters:
date1- The first date to compare.date2- The second date to compare.- Returns:
- true if date1 is after or equal to date2, false otherwise.
-
maxNullAsMax
Returns the maximum of two LocalDate values, treating null as the maximum possible date.- Parameters:
date1- The first LocalDate value, which may be null.date2- The second LocalDate value, which may be null.- Returns:
- The maximum of the two LocalDate values, or null if both are null.
-
minNullAsMin
Returns the minimum of two LocalDate values, treating null as the minimum possible date.- Parameters:
date1- The first LocalDate value, which may be null.date2- The second LocalDate value, which may be null.- Returns:
- The minimum of the two LocalDate values, or null if both are null.
-
maxNullAsMin
Returns the maximum of two LocalDate values, treating null as the minimum possible date.- Parameters:
date1- The first LocalDate value, which may be null.date2- The second LocalDate value, which may be null.- Returns:
- The maximum of the two LocalDate values, or null if both are null.
-
minNullAsMax
Returns the minimum of two LocalDate values, treating null as the maximum possible date.- Parameters:
date1- The first LocalDate value, which may be null.date2- The second LocalDate value, which may be null.- Returns:
- The minimum of the two LocalDate values, or null if both are null.
-
addDays
Adds the specified number of days to the given date.- Parameters:
date- the date to add days to, may be null.days- the number of days to add, may be negative to subtract days.- Returns:
- the new date with the added days, or null if the input date was null.
-
addDay
-
subtractDay
-
parseLocalDate
Parses a date string into a LocalDate using the default parser fromLocalDate.parse(CharSequence).- Parameters:
startDate- the date string to parse.- Returns:
- the parsed LocalDate, or null if the input string is empty.
-
parseDate
Parses a date string using the provided parser function.- Parameters:
date- the date string to parse.parser- the function to parse the date.- Returns:
- the parsed LocalDate, or null if the input string is empty.
-