Package com.github.javafaker
Class DateAndTime
- java.lang.Object
-
- com.github.javafaker.DateAndTime
-
public class DateAndTime extends java.lang.ObjectA generator of random dates.- Author:
- pmiklos
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDateAndTime(Faker faker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Datebetween(java.util.Date from, java.util.Date to)Generates a random date between two dates.java.util.Datebirthday()Generates a random birthday between 65 and 18 years ago.java.util.Datebirthday(int minAge, int maxAge)Generates a random birthday between two ages.java.util.Datefuture(int atMost, int minimum, java.util.concurrent.TimeUnit unit)Generates a future date from now, with a minimum time.java.util.Datefuture(int atMost, java.util.concurrent.TimeUnit unit)Generates a future date from now.java.util.Datefuture(int atMost, java.util.concurrent.TimeUnit unit, java.util.Date referenceDate)Generates a future date relative to thereferenceDate.java.util.Datepast(int atMost, int minimum, java.util.concurrent.TimeUnit unit)Generates a past date from now, with a minimum time.java.util.Datepast(int atMost, java.util.concurrent.TimeUnit unit)Generates a past date from now.java.util.Datepast(int atMost, java.util.concurrent.TimeUnit unit, java.util.Date referenceDate)Generates a past date relative to thereferenceDate.
-
-
-
Constructor Detail
-
DateAndTime
protected DateAndTime(Faker faker)
-
-
Method Detail
-
future
public java.util.Date future(int atMost, java.util.concurrent.TimeUnit unit)Generates a future date from now. Note that there is a 1 second slack to avoid generating a past date.- Parameters:
atMost- at most this amount of time ahead from now exclusive.unit- the time unit.- Returns:
- a future date from now.
-
future
public java.util.Date future(int atMost, int minimum, java.util.concurrent.TimeUnit unit)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.
-
future
public java.util.Date future(int atMost, java.util.concurrent.TimeUnit unit, java.util.Date referenceDate)Generates a future date relative to thereferenceDate.- Parameters:
atMost- at most this amount of time ahead to thereferenceDateexclusive.unit- the time unit.referenceDate- the future date relative to this date.- Returns:
- a future date relative to
referenceDate.
-
past
public java.util.Date past(int atMost, java.util.concurrent.TimeUnit unit)Generates a past date from now. Note that there is a 1 second slack added.- Parameters:
atMost- at most this amount of time earlier from now exclusive.unit- the time unit.- Returns:
- a past date from now.
-
past
public java.util.Date past(int atMost, int minimum, java.util.concurrent.TimeUnit unit)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 java.util.Date past(int atMost, java.util.concurrent.TimeUnit unit, java.util.Date referenceDate)Generates a past date relative to thereferenceDate.- Parameters:
atMost- at most this amount of time past to thereferenceDateexclusive.unit- the time unit.referenceDate- the past date relative to this date.- Returns:
- a past date relative to
referenceDate.
-
between
public java.util.Date between(java.util.Date from, java.util.Date to) throws java.lang.IllegalArgumentExceptionGenerates a random date between two dates.- Parameters:
from- the lower bound inclusiveto- the upper bound exclusive- Returns:
- a random date between
fromandto. - Throws:
java.lang.IllegalArgumentException- if thetodate represents an earlier date thanfromdate.
-
birthday
public java.util.Date birthday()
Generates a random birthday between 65 and 18 years ago.- Returns:
- a random birthday between 65 and 18 years ago.
-
birthday
public java.util.Date birthday(int minAge, int maxAge)Generates a random birthday between two ages.- Parameters:
minAge- the minimal agemaxAge- the maximal age- Returns:
- a random birthday between
minAgeandmaxAgeyears ago. - Throws:
java.lang.IllegalArgumentException- if themaxAgeis lower thanminAge.
-
-