1 |
|
2 |
|
3 |
|
4 | var IterResult = (function () {
|
5 | function IterResult(method, args) {
|
6 | this.minDate = null;
|
7 | this.maxDate = null;
|
8 | this._result = [];
|
9 | this.total = 0;
|
10 | this.method = method;
|
11 | this.args = args;
|
12 | if (method === 'between') {
|
13 | this.maxDate = args.inc
|
14 | ? args.before
|
15 | : new Date(args.before.getTime() - 1);
|
16 | this.minDate = args.inc ? args.after : new Date(args.after.getTime() + 1);
|
17 | }
|
18 | else if (method === 'before') {
|
19 | this.maxDate = args.inc ? args.dt : new Date(args.dt.getTime() - 1);
|
20 | }
|
21 | else if (method === 'after') {
|
22 | this.minDate = args.inc ? args.dt : new Date(args.dt.getTime() + 1);
|
23 | }
|
24 | }
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | IterResult.prototype.accept = function (date) {
|
34 | ++this.total;
|
35 | var tooEarly = this.minDate && date < this.minDate;
|
36 | var tooLate = this.maxDate && date > this.maxDate;
|
37 | if (this.method === 'between') {
|
38 | if (tooEarly)
|
39 | return true;
|
40 | if (tooLate)
|
41 | return false;
|
42 | }
|
43 | else if (this.method === 'before') {
|
44 | if (tooLate)
|
45 | return false;
|
46 | }
|
47 | else if (this.method === 'after') {
|
48 | if (tooEarly)
|
49 | return true;
|
50 | this.add(date);
|
51 | return false;
|
52 | }
|
53 | return this.add(date);
|
54 | };
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 | IterResult.prototype.add = function (date) {
|
61 | this._result.push(date);
|
62 | return true;
|
63 | };
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 | IterResult.prototype.getValue = function () {
|
70 | var res = this._result;
|
71 | switch (this.method) {
|
72 | case 'all':
|
73 | case 'between':
|
74 | return res;
|
75 | case 'before':
|
76 | case 'after':
|
77 | default:
|
78 | return (res.length ? res[res.length - 1] : null);
|
79 | }
|
80 | };
|
81 | IterResult.prototype.clone = function () {
|
82 | return new IterResult(this.method, this.args);
|
83 | };
|
84 | return IterResult;
|
85 | }());
|
86 | export default IterResult;
|
87 |
|
\ | No newline at end of file |