Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use faker.date.between faker.js

I want to generate some dates between two fixed values, but I don't know how to

use faker.date.between to achieve that.

the example in faker js demo is just giving a null value.

like image 209
Hamza Avatar asked Feb 05 '16 23:02

Hamza


People also ask

How do you use date in faker?

between = function (from, to) { var fromMilli = Date. parse(from); var dateOffset = faker. random. number(Date.

Can you still use Faker JS?

FAQ - What happened to the original faker. js? This project was originally created and hosted at https://github.com/marak/Faker.js/ - however around 4th Jan, 2022 - the author decided to delete the repository (for unknown reasons).

What can I use instead of Faker in JavaScript?

Falso is a modern alternative to Faker. js. Fake data can be useful when building and testing applications. Falso can generate fake data in various areas, including address, commerce, company, date, finance, image, random, and more.

Is Faker JS gone?

The epic of one of the most beloved open source JS libraries took a quick turn to the dark side. On the 5th of January 2022, a new version of Faker was released by Marak, versioned intentionally 6.6. 6. This marked the unforeseen extinction of the library which was essentially completely deleted from NPM and Github.


2 Answers

Not sure when did they update wiki, but they do have a working sample for date.between now

faker.date.between('2015-01-01', '2015-01-05');
like image 54
palaniraja Avatar answered Oct 30 '22 11:10

palaniraja


Their code from Github shows:

self.between = function (from, to) {
  var fromMilli = Date.parse(from);
  var dateOffset = faker.random.number(Date.parse(to) - fromMilli);

  var newDate = new Date(fromMilli + dateOffset);

  return newDate;
};

And I don't know how you're using it, or why it's not working on their example.... But this should give you some direction, at least.

If this does not help you, or is still producing an undesired result, I would open an issue up on their github.

like image 25
SirUncleCid Avatar answered Oct 30 '22 10:10

SirUncleCid