How to use the date function from chance

Find comprehensive JavaScript chance.date code examples handpicked from public code repositorys.

212
213
214
215
216
217
218
219
220
221
if (opts.min || opts.max) {
  d = new Date(faker.Date.between(
    opts.min ? new Date(opts.min) : new Date(),
    opts.max ? new Date(opts.max) : new Date()));
} else {
  d = chance.date({
    year: Number(opts.year),
    month: opts.month ? Number(opts.month)+1 : undefined,
    day: Number(opts.day)
  });
fork icon12
star icon33
watch icon3

+ 23 other calls in file

95
96
97
98
99
100
101
102
103
104
        american: false,
        year: year
    }).toCsv(CSV.delimiter);
    break;
case '3':
    t = chance.date({
        year: year
    });
    t = t.getFullYear() + '/' + ("0" + (t.getMonth() + 1)).slice(-2) + '/' + ("0" + t.getDate()).slice(-2);
    s += t;
fork icon2
star icon8
watch icon0

+ 3 other calls in file

54
55
56
57
58
59
60
61
62
63
movies.push({
  PK: "MOVIE#" + title.replace(/\W/g, "-"),
  SK: "MOVIE#" + title.replace(/\W/g, "-"),
  __typename: "MOVIE",
  title: title,
  releaseDate: chance.date({ max: new Date() }).toISOString(),
  updatedAt: new Date().toISOString(),
  director: chance.name(),
  listsCount: chance.integer({ min: 0, max: listsCount - 1 }),
  reviewsCount: chance.integer({ min: 0, max: reviewsCount - 1 }),
fork icon0
star icon2
watch icon0

12
13
14
15
16
17
18
19
20
21
let ticketAttributes;

beforeEach(() => {
    ticketAttributes = {
        TicketNumber:  String(chance.integer({min: 0})),
        Ship_by_Date: chance.date({string: true}),
        OrderDate: chance.date({string: true}),
        CustPONum: chance.string(),
        Priority: chance.pickone(getAllPriorities()),
        BillZip: chance.string(),
fork icon0
star icon0
watch icon0

+ 15 other calls in file

5
6
7
8
9
10
11
12
13
14
15
  name: chance.sentence({ words: 3 }),
  downloadurl: chance.url(),
  sha256: chance.string({ length: 64, pool: "abcdef0123456789" }),
  description: chance.sentence({ word: 10 }),
  created_at: chance.date().toJSON(),
  updated_at: chance.date().toJSON()
});


var fakeData = [];
for (i = 1; i <= 1000; i++) {
fork icon0
star icon0
watch icon0

157
158
159
160
161
162
163
164
165
166
previous_attendance: chance.bool(),
application_started: true, // TODO When would this ever be false?
application_complete: false, // TODO
application_submitted: false, // TODO
// TODO why do we have both a 'dob' and a 'bd' ?
dob: chance.date(),
bd: {
   month: 'January',
   day: 2,
   year: 1930,
fork icon0
star icon0
watch icon4

+ 7 other calls in file