Skip to content

Generate DateTime objects? #31

Description

@letharion

I quickly hacked up this to support testing my class that uses DateTime's extensively.
Could it be of interest to others? The function can of course just be copy-pasted straight into the argument generation, but I figured this might help someone else. If only as an issue that be found through searching.

class GeneratorWithDates extends Gen
{
    /**
     * Generate DateTime objects
     *
     * @return Generator
     */
    public static function dates($from = 1000, $to = 3000)
    {
        return self::choose($from, to)->map(
            function ($i) {
                return new DateTime($i);
            }
        );
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions