casual icon indicating copy to clipboard operation
casual copied to clipboard

Feature request: Date in range

Open Billy- opened this issue 8 years ago • 4 comments

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.

Billy- avatar Jun 12 '17 10:06 Billy-

Does anyone have a workaround solution for this?

mattgabor avatar Sep 12 '17 20:09 mattgabor

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

Billy- avatar Sep 12 '17 21:09 Billy-

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.

mattgabor avatar Sep 14 '17 17:09 mattgabor

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.

jasonlimantoro avatar Jun 30 '19 09:06 jasonlimantoro