UNPKG

6.63 kBJavaScriptView Raw
1import dateutil from '../dateutil';
2import { notEmpty, repeat, range, isPresent } from '../helpers';
3import { Frequency } from '../types';
4import { rebuildYear } from './yearinfo';
5import { rebuildMonth } from './monthinfo';
6import { easter } from './easter';
7import { Time } from '../datetime';
8// =============================================================================
9// Iterinfo
10// =============================================================================
11var Iterinfo = /** @class */ (function () {
12 // eslint-disable-next-line no-empty-function
13 function Iterinfo(options) {
14 this.options = options;
15 }
16 Iterinfo.prototype.rebuild = function (year, month) {
17 var options = this.options;
18 if (year !== this.lastyear) {
19 this.yearinfo = rebuildYear(year, options);
20 }
21 if (notEmpty(options.bynweekday) &&
22 (month !== this.lastmonth || year !== this.lastyear)) {
23 var _a = this.yearinfo, yearlen = _a.yearlen, mrange = _a.mrange, wdaymask = _a.wdaymask;
24 this.monthinfo = rebuildMonth(year, month, yearlen, mrange, wdaymask, options);
25 }
26 if (isPresent(options.byeaster)) {
27 this.eastermask = easter(year, options.byeaster);
28 }
29 };
30 Object.defineProperty(Iterinfo.prototype, "lastyear", {
31 get: function () {
32 return this.monthinfo ? this.monthinfo.lastyear : null;
33 },
34 enumerable: false,
35 configurable: true
36 });
37 Object.defineProperty(Iterinfo.prototype, "lastmonth", {
38 get: function () {
39 return this.monthinfo ? this.monthinfo.lastmonth : null;
40 },
41 enumerable: false,
42 configurable: true
43 });
44 Object.defineProperty(Iterinfo.prototype, "yearlen", {
45 get: function () {
46 return this.yearinfo.yearlen;
47 },
48 enumerable: false,
49 configurable: true
50 });
51 Object.defineProperty(Iterinfo.prototype, "yearordinal", {
52 get: function () {
53 return this.yearinfo.yearordinal;
54 },
55 enumerable: false,
56 configurable: true
57 });
58 Object.defineProperty(Iterinfo.prototype, "mrange", {
59 get: function () {
60 return this.yearinfo.mrange;
61 },
62 enumerable: false,
63 configurable: true
64 });
65 Object.defineProperty(Iterinfo.prototype, "wdaymask", {
66 get: function () {
67 return this.yearinfo.wdaymask;
68 },
69 enumerable: false,
70 configurable: true
71 });
72 Object.defineProperty(Iterinfo.prototype, "mmask", {
73 get: function () {
74 return this.yearinfo.mmask;
75 },
76 enumerable: false,
77 configurable: true
78 });
79 Object.defineProperty(Iterinfo.prototype, "wnomask", {
80 get: function () {
81 return this.yearinfo.wnomask;
82 },
83 enumerable: false,
84 configurable: true
85 });
86 Object.defineProperty(Iterinfo.prototype, "nwdaymask", {
87 get: function () {
88 return this.monthinfo ? this.monthinfo.nwdaymask : [];
89 },
90 enumerable: false,
91 configurable: true
92 });
93 Object.defineProperty(Iterinfo.prototype, "nextyearlen", {
94 get: function () {
95 return this.yearinfo.nextyearlen;
96 },
97 enumerable: false,
98 configurable: true
99 });
100 Object.defineProperty(Iterinfo.prototype, "mdaymask", {
101 get: function () {
102 return this.yearinfo.mdaymask;
103 },
104 enumerable: false,
105 configurable: true
106 });
107 Object.defineProperty(Iterinfo.prototype, "nmdaymask", {
108 get: function () {
109 return this.yearinfo.nmdaymask;
110 },
111 enumerable: false,
112 configurable: true
113 });
114 Iterinfo.prototype.ydayset = function () {
115 return [range(this.yearlen), 0, this.yearlen];
116 };
117 Iterinfo.prototype.mdayset = function (_, month) {
118 var start = this.mrange[month - 1];
119 var end = this.mrange[month];
120 var set = repeat(null, this.yearlen);
121 for (var i = start; i < end; i++)
122 set[i] = i;
123 return [set, start, end];
124 };
125 Iterinfo.prototype.wdayset = function (year, month, day) {
126 // We need to handle cross-year weeks here.
127 var set = repeat(null, this.yearlen + 7);
128 var i = dateutil.toOrdinal(new Date(Date.UTC(year, month - 1, day))) -
129 this.yearordinal;
130 var start = i;
131 for (var j = 0; j < 7; j++) {
132 set[i] = i;
133 ++i;
134 if (this.wdaymask[i] === this.options.wkst)
135 break;
136 }
137 return [set, start, i];
138 };
139 Iterinfo.prototype.ddayset = function (year, month, day) {
140 var set = repeat(null, this.yearlen);
141 var i = dateutil.toOrdinal(new Date(Date.UTC(year, month - 1, day))) -
142 this.yearordinal;
143 set[i] = i;
144 return [set, i, i + 1];
145 };
146 Iterinfo.prototype.htimeset = function (hour, _, second, millisecond) {
147 var _this = this;
148 var set = [];
149 this.options.byminute.forEach(function (minute) {
150 set = set.concat(_this.mtimeset(hour, minute, second, millisecond));
151 });
152 dateutil.sort(set);
153 return set;
154 };
155 Iterinfo.prototype.mtimeset = function (hour, minute, _, millisecond) {
156 var set = this.options.bysecond.map(function (second) { return new Time(hour, minute, second, millisecond); });
157 dateutil.sort(set);
158 return set;
159 };
160 Iterinfo.prototype.stimeset = function (hour, minute, second, millisecond) {
161 return [new Time(hour, minute, second, millisecond)];
162 };
163 Iterinfo.prototype.getdayset = function (freq) {
164 switch (freq) {
165 case Frequency.YEARLY:
166 return this.ydayset.bind(this);
167 case Frequency.MONTHLY:
168 return this.mdayset.bind(this);
169 case Frequency.WEEKLY:
170 return this.wdayset.bind(this);
171 case Frequency.DAILY:
172 return this.ddayset.bind(this);
173 default:
174 return this.ddayset.bind(this);
175 }
176 };
177 Iterinfo.prototype.gettimeset = function (freq) {
178 switch (freq) {
179 case Frequency.HOURLY:
180 return this.htimeset.bind(this);
181 case Frequency.MINUTELY:
182 return this.mtimeset.bind(this);
183 case Frequency.SECONDLY:
184 return this.stimeset.bind(this);
185 }
186 };
187 return Iterinfo;
188}());
189export default Iterinfo;
190//# sourceMappingURL=index.js.map
\No newline at end of file