public class DateAndTime extends AbstractProvider<BaseProviders>
faker
Modifier | Constructor and Description |
---|---|
protected |
DateAndTime(BaseProviders faker) |
Modifier and Type | Method and Description |
---|---|
<T extends java.util.Date> |
between(T from,
T to)
Generates a random date between two dates.
|
<T extends java.util.Date> |
between(T from,
T to,
java.lang.String pattern)
Generates a string representation of a random date between two dates.
|
java.sql.Timestamp |
birthday()
Generates a random birthday between 65 and 18 years ago from now.
|
java.sql.Timestamp |
birthday(int minAge,
int maxAge)
Generates a random birthday between two ages from now.
|
java.lang.String |
birthday(int minAge,
int maxAge,
java.lang.String pattern)
Generates and converts to string representation a random birthday between two ages from now.
|
java.lang.String |
birthday(java.lang.String pattern)
Generates a string representation of a random birthday between 65 and 18 years ago from now.
|
java.time.Duration |
duration(long max,
java.time.temporal.ChronoUnit unit)
Generates a random Duration lower than max.
|
java.time.Duration |
duration(long min,
long max,
java.time.temporal.ChronoUnit unit)
Generates a random Duration between min and max.
|
java.time.Duration |
duration(long min,
long max,
java.lang.String unit)
Generates a random Duration between min and max.
|
java.time.Duration |
duration(long max,
java.lang.String unit)
Generates a random Duration lower than max.
|
java.sql.Timestamp |
future(int atMost,
int minimum,
java.util.concurrent.TimeUnit unit)
Generates a future date from now, with a minimum time.
|
java.lang.String |
future(int atMost,
int minimum,
java.util.concurrent.TimeUnit unit,
java.lang.String pattern)
Generates and converts to string representation
of a future date from now, with a minimum time.
|
java.sql.Timestamp |
future(int atMost,
java.util.concurrent.TimeUnit unit)
Generates a future date from now.
|
java.lang.String |
future(int atMost,
java.util.concurrent.TimeUnit unit,
java.lang.String pattern)
Generates and converts to string representation a future date from now.
|
<T extends java.util.Date> |
future(int atMost,
java.util.concurrent.TimeUnit unit,
T referenceDate)
Generates a future date relative to the
referenceDate . |
<T extends java.util.Date> |
future(int atMost,
java.util.concurrent.TimeUnit unit,
T referenceDate,
java.lang.String pattern)
Generates and converts to string representation
a future date relative to the
referenceDate . |
java.sql.Timestamp |
past(int atMost,
int minimum,
java.util.concurrent.TimeUnit unit)
Generates a past date from now, with a minimum time.
|
java.lang.String |
past(int atMost,
int minimum,
java.util.concurrent.TimeUnit unit,
java.lang.String pattern)
Generates and converts to string representation a past date from now, with a minimum time.
|
java.sql.Timestamp |
past(int atMost,
java.util.concurrent.TimeUnit unit)
Generates a past date from now.
|
java.lang.String |
past(int atMost,
java.util.concurrent.TimeUnit unit,
java.util.Date referenceDate,
java.lang.String pattern)
Generates a string representation of a past date relative to the
referenceDate . |
java.lang.String |
past(int atMost,
java.util.concurrent.TimeUnit unit,
java.lang.String pattern)
Generates a string representation of a past date from now.
|
<T extends java.util.Date> |
past(int atMost,
java.util.concurrent.TimeUnit unit,
T referenceDate)
Generates a past date relative to the
referenceDate . |
java.time.Period |
period(java.time.Period min,
java.time.Period max)
Generates a random Period between min and max.
|
getFaker, resolve, resolve
protected DateAndTime(BaseProviders faker)
public java.sql.Timestamp future(int atMost, java.util.concurrent.TimeUnit unit)
atMost
- at most this amount of time ahead from now exclusive.unit
- the time unit.public java.lang.String future(int atMost, java.util.concurrent.TimeUnit unit, java.lang.String pattern)
atMost
- at most this amount of time ahead from now exclusive.unit
- the time unit.pattern
- date time pattern to convert to string.public java.sql.Timestamp future(int atMost, int minimum, java.util.concurrent.TimeUnit unit)
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.public java.lang.String future(int atMost, int minimum, java.util.concurrent.TimeUnit unit, java.lang.String pattern)
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.public <T extends java.util.Date> T future(int atMost, java.util.concurrent.TimeUnit unit, T referenceDate)
referenceDate
.atMost
- at most this amount of time ahead to the referenceDate
exclusive.unit
- the time unit.referenceDate
- the future date relative to this date.referenceDate
.public <T extends java.util.Date> java.lang.String future(int atMost, java.util.concurrent.TimeUnit unit, T referenceDate, java.lang.String pattern)
referenceDate
.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.referenceDate
.public java.sql.Timestamp past(int atMost, java.util.concurrent.TimeUnit unit)
atMost
- at most this amount of time earlier from now exclusive.unit
- the time unit.public java.lang.String past(int atMost, java.util.concurrent.TimeUnit unit, java.lang.String pattern)
atMost
- at most this amount of time earlier from now exclusive.unit
- the time unit.pattern
- date time pattern to convert to string.public java.sql.Timestamp past(int atMost, int minimum, java.util.concurrent.TimeUnit unit)
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.public java.lang.String past(int atMost, int minimum, java.util.concurrent.TimeUnit unit, java.lang.String pattern)
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.public <T extends java.util.Date> T past(int atMost, java.util.concurrent.TimeUnit unit, T referenceDate)
referenceDate
.atMost
- at most this amount of time past to the referenceDate
exclusive.unit
- the time unit.referenceDate
- the past date relative to this date.referenceDate
.public java.lang.String past(int atMost, java.util.concurrent.TimeUnit unit, java.util.Date referenceDate, java.lang.String pattern)
referenceDate
.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.referenceDate
.public <T extends java.util.Date> T between(T from, T to) throws java.lang.IllegalArgumentException
from
- the lower bound inclusiveto
- the upper bound exclusivefrom
and to
.java.lang.IllegalArgumentException
- if the to
date represents an earlier date than from
date.public <T extends java.util.Date> java.lang.String between(T from, T to, java.lang.String pattern) throws java.lang.IllegalArgumentException
from
- the lower bound inclusiveto
- the upper bound exclusivepattern
- date time pattern to convert to string.from
and to
.java.lang.IllegalArgumentException
- if the to
date represents an earlier date than from
date.public java.sql.Timestamp birthday()
public java.lang.String birthday(java.lang.String pattern)
pattern
- date time pattern to convert to string.public java.sql.Timestamp birthday(int minAge, int maxAge)
minAge
- the minimal agemaxAge
- the maximal ageminAge
and maxAge
years ago from now.java.lang.IllegalArgumentException
- if the maxAge
is lower than minAge
.public java.lang.String birthday(int minAge, int maxAge, java.lang.String pattern)
minAge
- the minimal agemaxAge
- the maximal agepattern
- date time pattern to convert to string.minAge
and maxAge
years ago from now.java.lang.IllegalArgumentException
- if the maxAge
is lower than minAge
.public java.time.Duration duration(long max, java.time.temporal.ChronoUnit unit)
max
- the maximum valueunit
- the temporal unit (day or shorter than a day)max
.java.lang.IllegalArgumentException
- if the unit
is invalid.public java.time.Duration duration(long min, long max, java.time.temporal.ChronoUnit unit)
min
- the maximum valuemax
- the minimal valueunit
- the temporal unit (day or shorter than a day)min
inclusive and max
exclusive if max
greater min
.java.lang.IllegalArgumentException
- if the unit
is invalid.public java.time.Duration duration(long max, java.lang.String unit)
max
- the maximum valueunit
- the temporal unit (day or shorter than a day)max
.java.lang.IllegalArgumentException
- if the unit
is invalid.public java.time.Duration duration(long min, long max, java.lang.String unit)
min
- the minimal valuemax
- the maximum valueunit
- the temporal unit (day or shorter than a day)min
inclusive and max
exclusive if max
greater min
.java.lang.IllegalArgumentException
- if the unit
is invalid.public java.time.Period period(java.time.Period min, java.time.Period max)
min
- the minimal valuemax
- the maximum valuemin
inclusive and max
inclusive if max
greater min
.java.lang.IllegalArgumentException
- if the min
is greater than max
.Copyright © 2023. All rights reserved.