Package org.kiwiproject.time
Class KiwiDates
java.lang.Object
org.kiwiproject.time.KiwiDates
The original JDK 1.0
Date class leaves, ahem, much to be desired, but there are still (unfortunately)
many classes, interfaces, and libraries that use it and probably won't be changed soon or ever. KiwiDate contains
some utilities to convert Instant objects to Date objects shifted by some amount of time, for
example if you need a Date that is 30 minutes from a given Instant.
If you have a choice, you should always prefer the Java 8 date/time APIs (e.g. Instant,
LocalDateTime, ZonedDateTime) in the java.time package
over using the legacy Date. But if you need to convert instants to dates, then this will help.
Functionally this is just a Date wrapper for KiwiInstants.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DateReturn theDateconverted frominstant.static DatedateFromInstantMinusDays(Instant instant, long days) static DatedateFromInstantMinusHours(Instant instant, long hours) static DatedateFromInstantMinusMinutes(Instant instant, long minutes) static DatedateFromInstantMinusMonths(Instant instant, long months) static DatedateFromInstantMinusYears(Instant instant, long years) static @Nullable DatedateFromInstantOrNull(@Nullable Instant instant) static DatedateFromInstantPlusDays(Instant instant, long days) static DatedateFromInstantPlusHours(Instant instant, long hours) static DatedateFromInstantPlusMinutes(Instant instant, long minutes) static DatedateFromInstantPlusMonths(Instant instant, long months) static DatedateFromInstantPlusYears(Instant instant, long years)
-
Method Details
-
dateFrom
Return theDateconverted frominstant.- Parameters:
instant- theInstantto convert- Returns:
- the converted
Date - API Note:
- This is just a simple wrapper around
Date.from(Instant)and is mainly here for consistency with the other utilities provided here
-
dateFromInstantOrNull
Return theDateconverted frominstant, ornullifinstantisnull.This is a null-safe wrapper around
Date.from(Instant), and is useful in situations when you might have anullinstant.- Parameters:
instant- theInstantto convert, may be null- Returns:
- the converted
Dateornull - API Note:
- This method only exists because
Date.from(Instant)throwsNullPointerExceptionif its arguments isnull.
-
dateFromInstantMinusMinutes
-
dateFromInstantMinusHours
-
dateFromInstantMinusDays
-
dateFromInstantMinusMonths
-
dateFromInstantMinusYears
-
dateFromInstantPlusMinutes
-
dateFromInstantPlusHours
-
dateFromInstantPlusDays
-
dateFromInstantPlusMonths
-
dateFromInstantPlusYears
-