DateTime
class DateTime extends DateTime
Properties
protected Generator | $generator | from Base | |
protected UniqueGenerator | $unique | from Base | |
static protected | $century | from DateTime | |
static protected | $defaultTimezone | from DateTime |
Methods
Chainable method for making any formatter optional.
Chainable method for making any formatter unique.
Chainable method for forcing any formatter to return only valid values.
Returns a random integer with 0 to $nbDigits digits.
Return a random float number
Returns a random number between $int1 and $int2 (any order)
Returns a random ASCII character (excluding accents and special chars)
Returns randomly ordered subsequence of $count elements from a provided array
Returns a random element from a passed array
Returns a random key from a passed associative array
Returns a shuffled version of the argument.
Returns a shuffled version of the string.
Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a not null number
Replaces all question mark ('?') occurrences with a random letter
Replaces hash signs ('#') and question marks ('?') with random numbers and letters An asterisk ('*') is replaced with either a random number or a random letter
Replaces * signs with random numbers and letters and special characters
Transforms a basic regular expression into a random string satisfying the expression.
Get a datetime object for a date between January 1, 1970 and now
Get a datetime object for a date between January 1, 001 and now
Get a date string between January 1, 1970 and now
Get a time string (24h format by default)
Get a DateTime object based on a random date between two given dates.
Get a DateTime object based on a random date between one given date and an interval Accepts date string that can be recognized by strtotime().
Details
in
Base at line 45
mixed|null
optional(float|int $weight = 0.5, $default = null)
Chainable method for making any formatter optional.
in
Base at line 76
UniqueGenerator
unique(bool $reset = false, int $maxRetries = 10000)
Chainable method for making any formatter unique.
// will never return twice the same value
$faker->unique()->randomElement(array(1, 2, 3));
in
Base at line 108
ValidGenerator
valid(Closure $validator = null, int $maxRetries = 10000)
Chainable method for forcing any formatter to return only valid values.
The value validity is determined by a function passed as first argument.
$values = array();
$evenValidator = function ($digit) {
return $digit % 2 === 0;
};
for ($i=0; $i < 10; $i++) {
$values []= $faker->valid($evenValidator)->randomDigit;
}
print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]
in
Base at line 118
static int
randomDigit()
Returns a random number between 0 and 9
in
Base at line 128
static int
randomDigitNotNull()
Returns a random number between 1 and 9
in
Base at line 139
static int
randomDigitNot(int $except)
Generates a random digit, which cannot be $except
in
Base at line 159
static int
randomNumber(int $nbDigits = null, bool $strict = false)
Returns a random integer with 0 to $nbDigits digits.
The maximum value returned is mt_getrandmax()
in
Base at line 188
static float
randomFloat(int $nbMaxDecimals = null, int|float $min = 0, int|float $max = null)
Return a random float number
in
Base at line 219
static int
numberBetween(int $int1 = 0, int $int2 = 2147483647)
Returns a random number between $int1 and $int2 (any order)
in
Base at line 233
static mixed
passthrough(mixed $value)
Returns the passed value
in
Base at line 243
static string
randomLetter()
Returns a random letter from a to z
in
Base at line 251
static
randomAscii()
Returns a random ASCII character (excluding accents and special chars)
in
Base at line 266
static array
randomElements(array $array = ['a', 'b', 'c'], int $count = 1, bool $allowDuplicates = false)
Returns randomly ordered subsequence of $count elements from a provided array
in
Base at line 312
static mixed
randomElement(array|Countable $array = ['a', 'b', 'c'])
Returns a random element from a passed array
in
Base at line 328
static int|string|null
randomKey(array $array = [])
Returns a random key from a passed associative array
in
Base at line 353
static array|string
shuffle(array|string $arg = '')
Returns a shuffled version of the argument.
This function accepts either an array, or a string.
in
Base at line 379
static array
shuffleArray(array $array = [])
Returns a shuffled version of the array.
This function does not mutate the original array. It uses the Fisher–Yates algorithm, which is unbiased, together with a Mersenne twister random generator. This function is therefore more random than PHP's shuffle() function, and it is seedable.
in
Base at line 420
static string
shuffleString(string $string = '', string $encoding = 'UTF-8')
Returns a shuffled version of the string.
This function does not mutate the original string. It uses the Fisher–Yates algorithm, which is unbiased, together with a Mersenne twister random generator. This function is therefore more random than PHP's shuffle() function, and it is seedable. Additionally, it is UTF8 safe if the mb extension is available.
in
Base at line 443
static string
numerify(string $string = '###')
Replaces all hash sign ('#') occurrences with a random number Replaces all percentage sign ('%') occurrences with a not null number
in
Base at line 477
static string
lexify(string $string = '????')
Replaces all question mark ('?') occurrences with a random letter
in
Base at line 489
static string
bothify(string $string = '## ??')
Replaces hash signs ('#') and question marks ('?') with random numbers and letters An asterisk ('*') is replaced with either a random number or a random letter
in
Base at line 505
static string
asciify(string $string = '****')
Replaces * signs with random numbers and letters and special characters
in
Base at line 536
static string
regexify(string $regex = '')
Transforms a basic regular expression into a random string satisfying the expression.
in
Base at line 590
static string
toLower(string $string = '')
Converts string to lowercase.
Uses mb_string extension if available.
in
Base at line 602
static string
toUpper(string $string = '')
Converts string to uppercase.
Uses mb_string extension if available.
in
DateTime at line 19
static int
unixTime(DateTime|int|string $max = 'now')
Get a timestamp between January 1, 1970 and now
in
DateTime at line 34
static DateTime
dateTime(DateTime|int|string $max = 'now', string $timezone = null)
Get a datetime object for a date between January 1, 1970 and now
in
DateTime at line 52
static DateTime
dateTimeAD(DateTime|int|string $max = 'now', string|null $timezone = null)
Get a datetime object for a date between January 1, 001 and now
in
DateTime at line 68
static string
iso8601(DateTime|int|string $max = 'now')
get a date string formatted with ISO8601
in
DateTime at line 81
static string
date(string $format = 'Y-m-d', DateTime|int|string $max = 'now')
Get a date string between January 1, 1970 and now
in
DateTime at line 94
static string
time(string $format = 'H:i:s', DateTime|int|string $max = 'now')
Get a time string (24h format by default)
in
DateTime at line 111
static DateTime
dateTimeBetween(DateTime|string $startDate = '-30 years', DateTime|string $endDate = 'now', string|null $timezone = null)
Get a DateTime object based on a random date between two given dates.
Accepts date strings that can be recognized by strtotime().
in
DateTime at line 141
static DateTime
dateTimeInInterval(DateTime|string $date = '-30 years', string $interval = '+5 days', string|null $timezone = null)
Get a DateTime object based on a random date between one given date and an interval Accepts date string that can be recognized by strtotime().
in
DateTime at line 164
static DateTime
dateTimeThisCentury(DateTime|int|string $max = 'now', string|null $timezone = null)
No description
in
DateTime at line 175
static DateTime
dateTimeThisDecade(DateTime|int|string $max = 'now', string|null $timezone = null)
No description
in
DateTime at line 186
static DateTime
dateTimeThisYear(DateTime|int|string $max = 'now', string|null $timezone = null)
No description
in
DateTime at line 197
static DateTime
dateTimeThisMonth(DateTime|int|string $max = 'now', string|null $timezone = null)
No description
at line 7
static string
amPm(DateTime|int|string $max = 'now')
No description
at line 12
static string
dayOfWeek(DateTime|int|string $max = 'now')
No description
at line 27
static string
monthName(DateTime|int|string $max = 'now')
No description
in
DateTime at line 266
static string
century()
No description
in
DateTime at line 275
static string
timezone()
No description
in
DateTime at line 285
static string|null
getDefaultTimezone()
Gets default time zone.
in
DateTime at line 297
static void
setDefaultTimezone(string $timezone = null)
Sets default time zone.