random-test-date
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

random-test-date

Tiny util to create random date objects in tests.

import {
  addMilliseconds,
  nextDate,
  previousDate,
  randomDate
} from "random-test-date";
 
// Returns a new date with a random time between `0000-01-01T00:00:00.000Z` and `9999-12-31T23:59:59.999Z`.
const date_1 = randomDate();
 
// date_2 is a new date 10 milliseconds after date_1
const date_2 = addMilliseconds(date_1, 10);
 
// date_3 is a new date 10 milliseconds before date_1
const date_3 = addMilliseconds(date_1, -10);
 
// date_4 is a new date 1 millisecond after date_1
// nextDate is just an alias for addMilliseconds(date, 1)
const date_4 = nextDate(date_1);
 
// date_5 is a new date 1 millisecond before date_1
// previousDate is just an alias for addMilliseconds(date, -1)
const date_5 = previousDate(date_1);

Readme

Keywords

none

Package Sidebar

Install

npm i random-test-date

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

5.35 kB

Total Files

5

Last publish

Collaborators

  • dbrockman