parser_day_of_month.js
1.65 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var util = require('util');
var test = require('tap').test;
var CronParser = require('../lib/parser');
test('parse cron with last day in a month', function(t) {
var options = {
currentDate: new Date(2014, 0, 1),
endDate: new Date(2014, 10, 1)
};
try {
var interval = CronParser.parseExpression('0 0 L * *', options);
t.equal(interval.hasNext(), true);
for (i = 0; i < 10; ++i) {
var next = interval.next();
t.ok(next, 'has a date');
}
} catch (err) {
t.ifError(err, 'Parse read error');
}
t.end();
});
test('parse cron with last day in feb', function(t) {
var options = {
currentDate: new Date(2016, 0, 1),
endDate: new Date(2016, 10, 1)
};
try {
var interval = CronParser.parseExpression('0 0 6-20/2,L 2 *', options);
t.equal(interval.hasNext(), true);
var next = null;
var items = 9;
var i = 0;
while(interval.hasNext()) {
next = interval.next();
i += 1;
t.ok(next, 'has a date');
}
//leap year
t.equal(next.getDate(), 29);
t.equal(i, items);
} catch (err) {
t.ifError(err, 'Parse read error');
}
t.end();
});
test('parse cron with last day in feb', function(t) {
var options = {
currentDate: new Date(2014, 0, 1),
endDate: new Date(2014, 10, 1)
};
try {
var interval = CronParser.parseExpression('0 0 1,3,6-10,L 2 *', options);
t.equal(interval.hasNext(), true);
var next = null;
while(interval.hasNext()) {
next = interval.next();
t.ok(next, 'has a date');
}
//common year
t.equal(next.getDate(), 28);
} catch (err) {
t.ifError(err, 'Parse read error');
}
t.end();
});