Package net.datafaker
Class DateAndTime
java.lang.Object
net.datafaker.DateAndTime
A generator of random dates.
- Since:
- 0.8.0
- Author:
- pmiklos
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGenerates a random date between two dates.Generates a string representation of a random date between two dates.birthday()
Generates a random birthday between 65 and 18 years ago from now.birthday
(int minAge, int maxAge) Generates a random birthday between two ages from now.Generates and converts to string representation a random birthday between two ages from now.Generates a string representation of a random birthday between 65 and 18 years ago from now.Generates a random Duration between min and max.duration
(long min, long max, ChronoUnit unit) Generates a random Duration between min and max.Generates a random Duration lower than max.duration
(long max, ChronoUnit unit) Generates a random Duration lower than max.Generates a future date from now, with a minimum time.Generates and converts to string representation of a future date from now, with a minimum time.Generates a future date from now.Generates and converts to string representation a future date from now.Generates a future date relative to thereferenceDate
.Generates and converts to string representation a future date relative to thereferenceDate
.Generates a past date from now, with a minimum time.Generates and converts to string representation a past date from now, with a minimum time.Generates a past date from now.Generates a string representation of a past date from now.Generates a past date relative to thereferenceDate
.Generates a string representation of a past date relative to thereferenceDate
.Generates a random Period between min and max.
-
Constructor Details
-
DateAndTime
-
-
Method Details
-
future
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
Generates and converts to string representation 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.pattern
- date time pattern to convert to string.- Returns:
- a string representation of a future date from now.
-
future
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
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
Generates a future date relative to thereferenceDate
.- Parameters:
atMost
- at most this amount of time ahead to thereferenceDate
exclusive.unit
- the time unit.referenceDate
- the future date relative to this date.- Returns:
- a future date relative to
referenceDate
.
-
future
Generates and converts to string representation a future date relative to thereferenceDate
.- Parameters:
atMost
- at most this amount of time ahead to thereferenceDate
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
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
Generates a string representation of 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.pattern
- date time pattern to convert to string.- Returns:
- a string representation of a past date from now.
-
past
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
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
Generates a past date relative to thereferenceDate
.- Parameters:
atMost
- at most this amount of time past to thereferenceDate
exclusive.unit
- the time unit.referenceDate
- the past date relative to this date.- Returns:
- a past date relative to
referenceDate
.
-
past
Generates a string representation of a past date relative to thereferenceDate
.- Parameters:
atMost
- at most this amount of time past to thereferenceDate
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
Generates a random date between two dates.- Parameters:
from
- the lower bound inclusiveto
- the upper bound exclusive- Returns:
- a random date between
from
andto
. - Throws:
IllegalArgumentException
- if theto
date represents an earlier date thanfrom
date.
-
between
Generates a string representation of a random date between two dates.- Parameters:
from
- the lower bound inclusiveto
- the upper bound exclusivepattern
- date time pattern to convert to string.- Returns:
- a string representation of a random date between
from
andto
. - Throws:
IllegalArgumentException
- if theto
date represents an earlier date thanfrom
date.
-
birthday
Generates a random birthday between 65 and 18 years ago from now.- Returns:
- a random birthday between 65 and 18 years ago from now.
-
birthday
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
Generates a random birthday between two ages from now.- Parameters:
minAge
- the minimal agemaxAge
- the maximal age- Returns:
- a random birthday between
minAge
andmaxAge
years ago from now. - Throws:
IllegalArgumentException
- if themaxAge
is lower thanminAge
.
-
birthday
Generates and converts to string representation a random birthday between two ages from now.- Parameters:
minAge
- the minimal agemaxAge
- the maximal agepattern
- date time pattern to convert to string.- Returns:
- a string representation of a random birthday between
minAge
andmaxAge
years ago from now. - Throws:
IllegalArgumentException
- if themaxAge
is lower thanminAge
.
-
duration
Generates a random Duration lower than max.- Parameters:
max
- the maximum valueunit
- the temporal unit (day or shorter than a day)- Returns:
- a random Duration lower than
max
. - Throws:
IllegalArgumentException
- if theunit
is invalid.
-
duration
Generates a random Duration between min and max.- Parameters:
min
- the maximum valuemax
- the minimal valueunit
- the temporal unit (day or shorter than a day)- Returns:
- a random Duration between
min
inclusive andmax
exclusive ifmax
greatermin
. - Throws:
IllegalArgumentException
- if theunit
is invalid.
-
duration
Generates a random Duration lower than max.- Parameters:
max
- the maximum valueunit
- the temporal unit (day or shorter than a day)- Returns:
- a random Duration lower than
max
. - Throws:
IllegalArgumentException
- if theunit
is invalid.
-
duration
Generates a random Duration between min and max.- Parameters:
min
- the minimal valuemax
- the maximum valueunit
- the temporal unit (day or shorter than a day)- Returns:
- a random Duration between
min
inclusive andmax
exclusive ifmax
greatermin
. - Throws:
IllegalArgumentException
- if theunit
is invalid.
-
period
Generates a random Period between min and max.- Parameters:
min
- the minimal valuemax
- the maximum value- Returns:
- a random Period between
min
inclusive andmax
inclusive ifmax
greatermin
. - Throws:
IllegalArgumentException
- if themin
is greater thanmax
.
-