Class KiwiDates


  • public class KiwiDates
    extends Object
    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.

    • Constructor Detail

      • KiwiDates

        public KiwiDates()
    • Method Detail

      • dateFrom

        public static Date dateFrom​(Instant instant)
        Return the Date converted from instant.
        Parameters:
        instant - the Instant to 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
      • dateFromInstantMinusMinutes

        public static Date dateFromInstantMinusMinutes​(Instant instant,
                                                       long minutes)
        Return the Date that is the given number of minutes before the given instant.
        Parameters:
        instant - the Instant to convert
        minutes - number of minutes to subtract from instant
        Returns:
        the converted Date
      • dateFromInstantMinusHours

        public static Date dateFromInstantMinusHours​(Instant instant,
                                                     long hours)
        Return the Date that is the given number of hours before the given instant.
        Parameters:
        instant - the Instant to convert
        hours - number of hours to subtract from instant
        Returns:
        the converted Date
      • dateFromInstantMinusDays

        public static Date dateFromInstantMinusDays​(Instant instant,
                                                    long days)
        Return the Date that is the given number of days before the given instant.
        Parameters:
        instant - the Instant to convert
        days - number of days to subtract from instant
        Returns:
        the converted Date
      • dateFromInstantMinusMonths

        public static Date dateFromInstantMinusMonths​(Instant instant,
                                                      long months)
        Return the Date that is the given number of months before the given instant.
        Parameters:
        instant - the Instant to convert
        months - number of months to subtract from instant
        Returns:
        the converted Date
      • dateFromInstantMinusYears

        public static Date dateFromInstantMinusYears​(Instant instant,
                                                     long years)
        Return the Date that is the given number of years before the given instant.
        Parameters:
        instant - the Instant to convert
        years - number of years to subtract from instant
        Returns:
        the converted Date
      • dateFromInstantPlusMinutes

        public static Date dateFromInstantPlusMinutes​(Instant instant,
                                                      long minutes)
        Return the Date that is the given number of minutes after the given instant.
        Parameters:
        instant - the Instant to convert
        minutes - number of minutes to add to instant
        Returns:
        the converted Date
      • dateFromInstantPlusHours

        public static Date dateFromInstantPlusHours​(Instant instant,
                                                    long hours)
        Return the Date that is the given number of hours after the given instant.
        Parameters:
        instant - the Instant to convert
        hours - number of hours to add to instant
        Returns:
        the converted Date
      • dateFromInstantPlusDays

        public static Date dateFromInstantPlusDays​(Instant instant,
                                                   long days)
        Return the Date that is the given number of days after the given instant.
        Parameters:
        instant - the Instant to convert
        days - number of days to add to instant
        Returns:
        the converted Date
      • dateFromInstantPlusMonths

        public static Date dateFromInstantPlusMonths​(Instant instant,
                                                     long months)
        Return the Date that is the given number of months after the given instant.
        Parameters:
        instant - the Instant to convert
        months - number of months to add to instant
        Returns:
        the converted Date
      • dateFromInstantPlusYears

        public static Date dateFromInstantPlusYears​(Instant instant,
                                                    long years)
        Return the Date that is the given number of years after the given instant.
        Parameters:
        instant - the Instant to convert
        years - number of years to add to instant
        Returns:
        the converted Date