boo1ean / casual

Fake data generator for javascript
3.03k stars 152 forks source link

Feature request: Date in range #69

Open Billy- opened 7 years ago

Billy- commented 7 years ago

I would like to be able to generate a casual.unix_time that is between a certain range of dates.

Many thanks for a great module.

mattgabor commented 7 years ago

Does anyone have a workaround solution for this?

Billy- commented 7 years ago

Not sure why I didn't think of this before, but just had a look at the source code, and it just uses casual.integer: https://github.com/boo1ean/casual/blob/4f05a130c0f10bf7a3f0b7555985fec6d7d070d3/src/providers/date.js#L9 so you can use that with your desired range

mattgabor commented 7 years ago

I see, thanks for finding that! I was actually referring to casual.date but I see that just calls moment so I can call it directly. Still would be nice to have a convenience method for readability.

jasonlimantoro commented 5 years ago

Are there any updates? I need to generate random dates at a given range.

A very common use case would be to generate random createdAt and endedAt dates which adhere to the following condition: createdAt < endedAt.

It would be nice to have an API for date generator with custom range since I believe this is a very common use case.