Package net.datafaker.providers.base
Class TimeAndDate
java.lang.Object
net.datafaker.providers.base.AbstractProvider<BaseProviders>
net.datafaker.providers.base.TimeAndDate
A generator of random times and dates.
This class is similar to DateAndTime, but migrated to the newer Java 8+ Time API.
- Since:
- 2.3.0
-
Field Summary
Fields inherited from class net.datafaker.providers.base.AbstractProvider
faker -
Constructor Summary
Constructors -
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.duration(long min, long max, ChronoUnit unit) Generates a random Duration between min and max.duration(long max, ChronoUnit unit) Generates a random Duration lower than max.future()Generates a future date from now.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.past()Generates a past date from now.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.Methods inherited from class net.datafaker.providers.base.AbstractProvider
equals, getFaker, hashCode, loadGenerators, resolve, resolve, toString
-
Constructor Details
-
TimeAndDate
-
-
Method Details
-
future
Generates a future date from now. -
future
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
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
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 thereferenceDateexclusive.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 thereferenceDateexclusive.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. -
past
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
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
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 thereferenceDateexclusive.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 thereferenceDateexclusive.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
fromandto. - Throws:
IllegalArgumentException- if thetodate represents an earlier date thanfromdate.
-
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
fromandto. - Throws:
IllegalArgumentException- if thetodate represents an earlier date thanfromdate.
-
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
minAgeandmaxAgeyears ago from now. NegativeminAgeandmaxAgeare supported.
-
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
minAgeandmaxAgeyears ago from now. - Throws:
IllegalArgumentException- if themaxAgeis 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 theunitis invalid.
-
duration
Generates a random Duration between min and max.- Parameters:
min- the minimum valuemax- the maximum valueunit- the temporal unit (day or shorter than a day)- Returns:
- a random Duration between
mininclusive andmaxexclusive ifmaxgreatermin. - Throws:
IllegalArgumentException- if theunitis invalid.
-
period
Generates a random Period between min and max.- Parameters:
min- the minimal valuemax- the maximum value- Returns:
- a random Period between
mininclusive andmaxinclusive ifmaxgreatermin. - Throws:
IllegalArgumentException- if theminis greater thanmax.
-