Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Add method to generate unique dates in a range #1878

Open
hackel opened this issue Dec 18, 2019 · 0 comments
Open

Add method to generate unique dates in a range #1878

hackel opened this issue Dec 18, 2019 · 0 comments

Comments

@hackel
Copy link

hackel commented Dec 18, 2019

Summary

There is currently no way to generate unique dates within a particular range. unique()->date() only allows a maximum and always uses 1970-01-01 as the minimum date. The dateTime* methods obviously return DateTimes, for which there could be up to 86,400 duplicate values for a single date rendering the unique modifier useless.

This limitation was already raised in #984, but it was closed even though the proposed solution cannot work with the unique modifier.

Proposed Solution

Add a simple dateBetween method to the DateTime provider:

public static function dateBetween($startDate = '-30 years', $endDate = 'now', $format = 'Y-m-d'): string
{
    return static::dateTimeBetween($startDate, $endDate)->format($format);
}

This is currently working well for me.

Versions

Version
PHP 7.4.0
fzaninotto/faker 1.9.1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants