Class DateAndTime


@Deprecated(since="2.3.0", forRemoval=true) public class DateAndTime extends AbstractProvider<BaseProviders>
Deprecated, for removal: This API element is subject to removal in a future version.
Use TimeAndDate instead.
A generator of random dates.
Since:
0.8.0
Author:
pmiklos
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Deprecated, for removal: This API element is subject to removal in a future version.
     

    Fields inherited from class net.datafaker.providers.base.AbstractProvider

    faker
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends Date>
    T
    between(T from, T to)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random date between two dates.
    <T extends Date>
    String
    between(T from, T to, String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a string representation of a random date between two dates.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random birthday between 65 and 18 years ago from now.
    birthday(int minAge, int maxAge)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random birthday between two ages from now.
    birthday(int minAge, int maxAge, String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates and converts to string representation a random birthday between two ages from now.
    birthday(String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a string representation of a random birthday between 65 and 18 years ago from now.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random birthday between 65 and 18 years ago from now as LocalDate.
    birthdayLocalDate(int minAge, int maxAge)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random birthday between two ages from now as LocalDate.
    duration(long min, long max, String unit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random Duration between min and max.
    duration(long min, long max, ChronoUnit unit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random Duration between min and max.
    duration(long max, String unit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random Duration lower than max.
    duration(long max, ChronoUnit unit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random Duration lower than max.
    future(int atMost, int minimum, TimeUnit unit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a future date from now, with a minimum time.
    future(int atMost, int minimum, TimeUnit unit, String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates and converts to string representation of a future date from now, with a minimum time.
    future(int atMost, TimeUnit unit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a future date from now.
    future(int atMost, TimeUnit unit, String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates and converts to string representation a future date from now.
    <T extends Date>
    T
    future(int atMost, TimeUnit unit, T referenceDate)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a future date relative to the referenceDate.
    <T extends Date>
    String
    future(int atMost, TimeUnit unit, T referenceDate, String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates and converts to string representation a future date relative to the referenceDate.
    past(int atMost, int minimum, TimeUnit unit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a past date from now, with a minimum time.
    past(int atMost, int minimum, TimeUnit unit, String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates and converts to string representation a past date from now, with a minimum time.
    past(int atMost, TimeUnit unit)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a past date from now.
    past(int atMost, TimeUnit unit, String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a string representation of a past date from now.
    past(int atMost, TimeUnit unit, Date referenceDate, String pattern)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a string representation of a past date relative to the referenceDate.
    <T extends Date>
    T
    past(int atMost, TimeUnit unit, T referenceDate)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a past date relative to the referenceDate.
    period(Period min, Period max)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generates a random Period between min and max.

    Methods inherited from class net.datafaker.providers.base.AbstractProvider

    equals, getFaker, hashCode, loadGenerators, resolve, resolve, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • DAYS_NANOS

      public static final long DAYS_NANOS
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Constructor Details

    • DateAndTime

      protected DateAndTime(BaseProviders faker)
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Details

    • future

      public Timestamp future(int atMost, TimeUnit unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a future date from now.
      Parameters:
      atMost - at most this amount of time ahead from now exclusive.
      unit - the time unit.
      Returns:
      a future date from now.
    • future

      public String future(int atMost, TimeUnit unit, String pattern)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates and converts to string representation a future date from now.
      Parameters:
      atMost - at most this amount of time ahead from now exclusive.
      unit - the time unit.
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a future date from now.
    • future

      public Timestamp future(int atMost, int minimum, TimeUnit unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a future date from now, with a minimum time.
      Parameters:
      atMost - at most this amount of time ahead from now exclusive.
      minimum - the minimum amount of time in the future from now.
      unit - the time unit.
      Returns:
      a future date from now, with a minimum time.
    • future

      public String future(int atMost, int minimum, TimeUnit unit, String pattern)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates and converts to string representation of a future date from now, with a minimum time.
      Parameters:
      atMost - at most this amount of time ahead from now exclusive.
      minimum - the minimum amount of time in the future from now.
      unit - the time unit.
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a future date from now, with a minimum time.
    • future

      public <T extends Date> T future(int atMost, TimeUnit unit, T referenceDate)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a future date relative to the referenceDate.
      Parameters:
      atMost - at most this amount of time ahead to the referenceDate exclusive.
      unit - the time unit.
      referenceDate - the future date relative to this date.
      Returns:
      a future date relative to referenceDate.
    • future

      public <T extends Date> String future(int atMost, TimeUnit unit, T referenceDate, String pattern)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates and converts to string representation a future date relative to the referenceDate.
      Parameters:
      atMost - at most this amount of time ahead to the referenceDate exclusive.
      unit - the time unit.
      referenceDate - the future date relative to this date.
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a future date relative to referenceDate.
    • past

      public Timestamp past(int atMost, TimeUnit unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a past date from now.
      Parameters:
      atMost - at most this amount of time earlier from now exclusive.
      unit - the time unit.
      Returns:
      a past date from now.
    • past

      public String past(int atMost, TimeUnit unit, String pattern)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a string representation of a past date from now.
      Parameters:
      atMost - at most this amount of time earlier from now exclusive.
      unit - the time unit.
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a past date from now.
    • past

      public Timestamp past(int atMost, int minimum, TimeUnit unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a past date from now, with a minimum time.
      Parameters:
      atMost - at most this amount of time earlier from now exclusive.
      minimum - the minimum amount of time in the past from now.
      unit - the time unit.
      Returns:
      a past date from now.
    • past

      public String past(int atMost, int minimum, TimeUnit unit, String pattern)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates and converts to string representation a past date from now, with a minimum time.
      Parameters:
      atMost - at most this amount of time earlier from now exclusive.
      minimum - the minimum amount of time in the past from now.
      unit - the time unit.
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a past date from now, with a minimum time.
    • past

      public <T extends Date> T past(int atMost, TimeUnit unit, T referenceDate)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a past date relative to the referenceDate.
      Parameters:
      atMost - at most this amount of time past to the referenceDate exclusive.
      unit - the time unit.
      referenceDate - the past date relative to this date.
      Returns:
      a past date relative to referenceDate.
    • past

      public String past(int atMost, TimeUnit unit, Date referenceDate, String pattern)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a string representation of a past date relative to the referenceDate.
      Parameters:
      atMost - at most this amount of time past to the referenceDate exclusive.
      unit - the time unit.
      referenceDate - the past date relative to this date.
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a past date relative to referenceDate.
    • between

      public <T extends Date> T between(T from, T to) throws IllegalArgumentException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random date between two dates.
      Parameters:
      from - the lower bound inclusive
      to - the upper bound exclusive
      Returns:
      a random date between from and to.
      Throws:
      IllegalArgumentException - if the to date represents an earlier date than from date.
    • between

      public <T extends Date> String between(T from, T to, String pattern) throws IllegalArgumentException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a string representation of a random date between two dates.
      Parameters:
      from - the lower bound inclusive
      to - the upper bound exclusive
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a random date between from and to.
      Throws:
      IllegalArgumentException - if the to date represents an earlier date than from date.
    • birthday

      public Timestamp birthday()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random birthday between 65 and 18 years ago from now.
      Returns:
      a random birthday between 65 and 18 years ago from now.
    • birthdayLocalDate

      public LocalDate birthdayLocalDate()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random birthday between 65 and 18 years ago from now as LocalDate.
      Returns:
      a random birthday between 65 and 18 years ago from now.
    • birthday

      public String birthday(String pattern)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a string representation of a random birthday between 65 and 18 years ago from now.
      Parameters:
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a random birthday between 65 and 18 years ago from now.
    • birthday

      public Timestamp birthday(int minAge, int maxAge)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random birthday between two ages from now.
      Parameters:
      minAge - the minimal age
      maxAge - the maximal age
      Returns:
      a random birthday between minAge and maxAge years ago from now. Negative minAge and maxAge are supported.
    • birthdayLocalDate

      public LocalDate birthdayLocalDate(int minAge, int maxAge)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random birthday between two ages from now as LocalDate.
      Parameters:
      minAge - the minimal age
      maxAge - the maximal age
      Returns:
      a random birthday between minAge and maxAge years ago from now. Negative minAge and maxAge are supported.
    • birthday

      public String birthday(int minAge, int maxAge, String pattern)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates and converts to string representation a random birthday between two ages from now.
      Parameters:
      minAge - the minimal age
      maxAge - the maximal age
      pattern - date time pattern to convert to string.
      Returns:
      a string representation of a random birthday between minAge and maxAge years ago from now.
      Throws:
      IllegalArgumentException - if the maxAge is lower than minAge.
    • duration

      public Duration duration(long max, ChronoUnit unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random Duration lower than max.
      Parameters:
      max - the maximum value (exclusive in most cases)
      unit - the temporal unit (day or shorter than a day)
      Returns:
      a random Duration lower than max.
      Throws:
      IllegalArgumentException - if the unit is invalid.
    • duration

      public Duration duration(long min, long max, ChronoUnit unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random Duration between min and max.
      Parameters:
      min - the minimum value (inclusive)
      max - the maximum value (exclusive in most cases)
      unit - the temporal unit (day or shorter than a day)
      Returns:
      a random Duration between min inclusive and max exclusive if max greater min.
      Throws:
      IllegalArgumentException - if the unit is invalid.
    • duration

      public Duration duration(long max, String unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random Duration lower than max.
      Parameters:
      max - the maximum value
      unit - the temporal unit (day or shorter than a day)
      Returns:
      a random Duration lower than max.
      Throws:
      IllegalArgumentException - if the unit is invalid.
    • duration

      public Duration duration(long min, long max, String unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random Duration between min and max.
      Parameters:
      min - the minimal value
      max - the maximum value
      unit - the temporal unit (day or shorter than a day)
      Returns:
      a random Duration between min inclusive and max exclusive if max greater min.
      Throws:
      IllegalArgumentException - if the unit is invalid.
    • period

      public Period period(Period min, Period max)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generates a random Period between min and max.
      Parameters:
      min - the minimal value
      max - the maximum value
      Returns:
      a random Period between min inclusive and max inclusive if max greater min.
      Throws:
      IllegalArgumentException - if the min is greater than max.