max13 / faker-dateinterval
Date and Time Interval faker provider
v1.2.0
2022-08-10 21:04 UTC
Requires
- php: ^7.0 || ^8.0
- fakerphp/faker: ^1.20
- illuminate/support: ^8.0 || ^9.0
Requires (Dev)
- orchestra/testbench: ^6.24
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-12-11 02:06:25 UTC
README
This is a DateInterval
FakerPHP Provider. It can generate a DateInterval
with only a date interval, only a time interval or both. It can return a DateInterval
or a duration in the ISO8601 format.
Installation
You can use composer: composer require max13/faker-dateinterval
Usage
Using the examples above:
$faker = new Faker\Generator; // Add this provider to Faker $faker->addProvider(new FakerDateInterval\FakerProvider($faker)); // Generate a date, time or date and time interval $date = $faker->dateInterval(/* $complex = */false, /* $asIso8601 = */ false); $time = $faker->timeInterval(/* $complex = */false, /* $asIso8601 = */ false); $datetime = $faker->dateTimeInterval(/* $complex = */false, /* $asIso8601 = */ false); // return DateInterval objects // You can generate a complex interval with more than 1 part generated $date = $faker->dateInterval(/* $complex = */true, /* $asIso8601 = */ false); // You can also retrieve the interval as an ISO8601 duration string $date = $faker->dateInterval(/* $complex = */true, /* $asIso8601 = */ true); // returns a string like: P1M3D for 1 month and 3 days
Bonus
A Laravel
service provider is included and will autoload the FakerProvider
to faker, if Laravel
's service provider discovery is enabled (default).
Need help?
Open an issue.
Now have fun.