Hi-Folks/rando-php

Model: create DateTime Model

roberto-butti opened this issue · 8 comments

Create a new model src/Models/DateTime.php in order to generate a random datetime.
Implement fluent interface (see src/Models/Integer.php) with:

  • min : minimum date (date from);
  • max : max date (date to).

The goal is to implement a functionality like this:

Randomize::datetime()->generate();
Randomize::datetime()->min($startDate)->max($endDate)->generate();

Would you mind if I give this a go?
What type of date are we expecting? or any datetime is valid?

Hi @rebelchris sure you can start with this.
I think that under the hood we could manage the datetime as timestamp.
So we need to generate randomly a number that is in the timestamp format.
When generate() is called a timestamp is returned (so the user needs to convert the timestamp with a "format").
So, my suggestion is:

  • use strtotime to obtain min date and max date
  • generate a random number with range min and max (int)
  • format the output with date() if user want to format (add format($format) method)

@roberto-butti Hello, I fixed it #27. Can you check for me? Thanks.

@roberto-butti Ah Oops, didn't say this above, created my version as well with documentation and variable min/max/format and range.

@roberto-butti Ah Oops, didn't say this above, created my version as well with documentation and variable min/max/format and range.

Hi, thank you. Could you resolve the conflict on Randomize.php?

@roberto-butti Updated my PR ;)

@roberto-butti Updated my PR ;)

To complete the PR, are you able to add tests? If not, i could open a new issue

@roberto-butti I've added some very basic tests, The testing is really new to me, so not sure how to incorporate other ones.