Class RandomDateExtensions


  • public final class RandomDateExtensions
    extends java.lang.Object
    The class RandomDateExtensions is a utility class for creating random random dates.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Date dateAfter​(java.util.Date date)
      Creates a random Date that is after from the given Date.
      static java.util.Date dateAfter​(java.util.Date date, int range)
      Creates a random Date that is after from the given Date.
      static java.util.Date dateBefore​(java.util.Date date)
      Creates a random date that is before from the given date.
      static java.util.Date dateBefore​(java.util.Date date, int range)
      Creates a random date that is before from the given date.
      static java.util.Date randomBirthday()
      Creates a random birthday-date between 9 and 55 years.
      static java.util.Date randomBirthday​(java.util.Date from, java.util.Date till)
      Creates a random birthday-date between the two given date-objects.
      static java.util.Date randomDate()
      Creates a random Date
      static java.util.Date randomDate​(java.util.Date from)
      Creates a random date.
      static java.util.Date randomDate​(java.util.Date from, java.security.SecureRandom secureRandom)
      Creates a random date.
      static java.lang.String randomDatebetween​(long startDate, long endDate)
      Creates a random Date between the range from startDays and endDays from the given Date and gives it back as a string to the default "dd.MM.yyyy HH:mm:ss" format.
      static java.lang.String randomDatebetween​(long startDate, long endDate, java.lang.String format)
      Creates a random Date between the range from startDays and endDays from the given Date and gives it back as a string to the given format.
      static java.util.Date randomDatebetween​(java.util.Date start, java.util.Date end)
      Creates a random Date between the range from start and end.
      static java.util.Date randomDateBetween​(java.util.Date from, int startDays, int endDays)
      Creates a random Date between the range from startDays and endDays from the given Date.
      static java.time.LocalDate randomLocalDate()
      Creates a random LocalDate object
      static java.time.LocalDateTime randomLocalDateTime()
      Creates a random LocalDateTime object
      static java.time.LocalTime randomLocalTime()
      Creates a random LocalTime object
      static java.time.ZoneId randomZoneId()
      Creates a random LocalDateTime object
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • dateAfter

        public static java.util.Date dateAfter​(java.util.Date date)
        Creates a random Date that is after from the given Date.
        Parameters:
        date - The Date from where to compute the future date.
        Returns:
        The random Date in the future.
      • dateAfter

        public static java.util.Date dateAfter​(java.util.Date date,
                                               int range)
        Creates a random Date that is after from the given Date.
        Parameters:
        date - The Date from where to compute the future date.
        range - The range.
        Returns:
        The random Date in the future.
      • dateBefore

        public static java.util.Date dateBefore​(java.util.Date date)
        Creates a random date that is before from the given date.
        Parameters:
        date - The date from where to compute the Past date.
        Returns:
        The random Date in the past.
      • dateBefore

        public static java.util.Date dateBefore​(java.util.Date date,
                                                int range)
        Creates a random date that is before from the given date.
        Parameters:
        date - The date from where to compute the past date.
        range - The range.
        Returns:
        The random Date in the past.
      • randomBirthday

        public static java.util.Date randomBirthday()
        Creates a random birthday-date between 9 and 55 years.
        Returns:
        's the random date.
      • randomBirthday

        public static java.util.Date randomBirthday​(java.util.Date from,
                                                    java.util.Date till)
        Creates a random birthday-date between the two given date-objects.
        Parameters:
        from - The date from where to start.
        till - The date from where to end.
        Returns:
        's the random date.
      • randomDate

        public static java.util.Date randomDate()
        Creates a random Date
        Returns:
        The random Date
      • randomDate

        public static java.util.Date randomDate​(java.util.Date from)
        Creates a random date.
        Parameters:
        from - The date from where to begin.
        Returns:
        The random date.
      • randomDate

        public static java.util.Date randomDate​(java.util.Date from,
                                                java.security.SecureRandom secureRandom)
        Creates a random date.
        Parameters:
        from - The date from where to begin.
        secureRandom - the secure random for date generation
        Returns:
        The random date.
      • randomDatebetween

        public static java.util.Date randomDatebetween​(java.util.Date start,
                                                       java.util.Date end)
        Creates a random Date between the range from start and end.
        Parameters:
        start - The Date from where the range starts.
        end - The Date from where the range ends.
        Returns:
        A random Date between the range from start and end.
      • randomDatebetween

        public static java.lang.String randomDatebetween​(long startDate,
                                                         long endDate)
        Creates a random Date between the range from startDays and endDays from the given Date and gives it back as a string to the default "dd.MM.yyyy HH:mm:ss" format.
        Parameters:
        startDate - The date from where to start as a long.
        endDate - The date from where to end as a long.
        Returns:
        The random date as a String.
      • randomDatebetween

        public static java.lang.String randomDatebetween​(long startDate,
                                                         long endDate,
                                                         java.lang.String format)
        Creates a random Date between the range from startDays and endDays from the given Date and gives it back as a string to the given format.
        Parameters:
        startDate - The date from where to start as a long.
        endDate - The date from where to end as a long.
        format - The format for the date.
        Returns:
        The random date as a String.
      • randomDateBetween

        public static java.util.Date randomDateBetween​(java.util.Date from,
                                                       int startDays,
                                                       int endDays)
        Creates a random Date between the range from startDays and endDays from the given Date.
        Parameters:
        from - The Date from where to the random Date to start.
        startDays - The int that represents the days from where the range starts.
        endDays - The int that represents the days from where the range ends.
        Returns:
        A random Date between the range from startDays and endDays from the given Date.
      • randomLocalDate

        public static java.time.LocalDate randomLocalDate()
        Creates a random LocalDate object
        Returns:
        the random LocalDate object
      • randomLocalDateTime

        public static java.time.LocalDateTime randomLocalDateTime()
        Creates a random LocalDateTime object
        Returns:
        the random LocalDateTime object
      • randomLocalTime

        public static java.time.LocalTime randomLocalTime()
        Creates a random LocalTime object
        Returns:
        the random LocalTime object
      • randomZoneId

        public static java.time.ZoneId randomZoneId()
        Creates a random LocalDateTime object
        Returns:
        the zone id