-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerateDates.js
More file actions
47 lines (30 loc) · 1 KB
/
generateDates.js
File metadata and controls
47 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var moment = require('moment');
var fs = require('fs');
var since = '2015-04-01';
var until = '2015-05-15';
var sinceDate = moment(since, 'YYYY-MM-DD');
var untilDate = moment(until, 'YYYY-MM-DD');
var dates = [];
var days = parseInt(moment.duration(untilDate.diff(sinceDate)).asDays());
var prevDate = sinceDate;
for (var i = 0; i < days; i++) {
if (i === 0) {
var nextDate = moment(since, 'YYYY-MM-DD').add(1, 'd');
var interval = {
since: sinceDate.format('YYYY-MM-DD'),
until: nextDate.format('YYYY-MM-DD')
};
dates.push(interval);
} else {
var previous = dates[i - 1];
var prevDate = moment(previous.since, 'YYYY-MM-DD').add(1, 'd');
var nextDate = moment(previous.until, 'YYYY-MM-DD').add(1, 'd');
var interval = {
since: prevDate.format('YYYY-MM-DD'),
until: nextDate.format('YYYY-MM-DD')
};
dates.push(interval);
}
}
console.log(JSON.stringify(dates, true, '\t'));
fs.writeFileSync('dates3.json', JSON.stringify(dates, true, '\t'));