1 | import dateutil from './dateutil';
|
2 | import IterResult from './iterresult';
|
3 | import CallbackIterResult from './callbackiterresult';
|
4 | import { fromText, parseText, toText, isFullyConvertible } from './nlp/index';
|
5 | import { Frequency } from './types';
|
6 | import { parseOptions, initializeOptions } from './parseoptions';
|
7 | import { parseString } from './parsestring';
|
8 | import { optionsToString } from './optionstostring';
|
9 | import { Cache } from './cache';
|
10 | import { Weekday } from './weekday';
|
11 | import { iter } from './iter/index';
|
12 |
|
13 |
|
14 |
|
15 | export var Days = {
|
16 | MO: new Weekday(0),
|
17 | TU: new Weekday(1),
|
18 | WE: new Weekday(2),
|
19 | TH: new Weekday(3),
|
20 | FR: new Weekday(4),
|
21 | SA: new Weekday(5),
|
22 | SU: new Weekday(6)
|
23 | };
|
24 | export var DEFAULT_OPTIONS = {
|
25 | freq: Frequency.YEARLY,
|
26 | dtstart: null,
|
27 | interval: 1,
|
28 | wkst: Days.MO,
|
29 | count: null,
|
30 | until: null,
|
31 | tzid: null,
|
32 | bysetpos: null,
|
33 | bymonth: null,
|
34 | bymonthday: null,
|
35 | bynmonthday: null,
|
36 | byyearday: null,
|
37 | byweekno: null,
|
38 | byweekday: null,
|
39 | bynweekday: null,
|
40 | byhour: null,
|
41 | byminute: null,
|
42 | bysecond: null,
|
43 | byeaster: null
|
44 | };
|
45 | export var defaultKeys = Object.keys(DEFAULT_OPTIONS);
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | var RRule = (function () {
|
53 | function RRule(options, noCache) {
|
54 | if (options === void 0) { options = {}; }
|
55 | if (noCache === void 0) { noCache = false; }
|
56 |
|
57 | this._cache = noCache ? null : new Cache();
|
58 |
|
59 | this.origOptions = initializeOptions(options);
|
60 | var parsedOptions = parseOptions(options).parsedOptions;
|
61 | this.options = parsedOptions;
|
62 | }
|
63 | RRule.parseText = function (text, language) {
|
64 | return parseText(text, language);
|
65 | };
|
66 | RRule.fromText = function (text, language) {
|
67 | return fromText(text, language);
|
68 | };
|
69 | RRule.fromString = function (str) {
|
70 | return new RRule(RRule.parseString(str) || undefined);
|
71 | };
|
72 | RRule.prototype._iter = function (iterResult) {
|
73 | return iter(iterResult, this.options);
|
74 | };
|
75 | RRule.prototype._cacheGet = function (what, args) {
|
76 | if (!this._cache)
|
77 | return false;
|
78 | return this._cache._cacheGet(what, args);
|
79 | };
|
80 | RRule.prototype._cacheAdd = function (what, value, args) {
|
81 | if (!this._cache)
|
82 | return;
|
83 | return this._cache._cacheAdd(what, value, args);
|
84 | };
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | RRule.prototype.all = function (iterator) {
|
92 | if (iterator) {
|
93 | return this._iter(new CallbackIterResult('all', {}, iterator));
|
94 | }
|
95 | var result = this._cacheGet('all');
|
96 | if (result === false) {
|
97 | result = this._iter(new IterResult('all', {}));
|
98 | this._cacheAdd('all', result);
|
99 | }
|
100 | return result;
|
101 | };
|
102 | |
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | RRule.prototype.between = function (after, before, inc, iterator) {
|
110 | if (inc === void 0) { inc = false; }
|
111 | if (!dateutil.isValidDate(after) || !dateutil.isValidDate(before))
|
112 | throw new Error('Invalid date passed in to RRule.between');
|
113 | var args = {
|
114 | before: before,
|
115 | after: after,
|
116 | inc: inc
|
117 | };
|
118 | if (iterator) {
|
119 | return this._iter(new CallbackIterResult('between', args, iterator));
|
120 | }
|
121 | var result = this._cacheGet('between', args);
|
122 | if (result === false) {
|
123 | result = this._iter(new IterResult('between', args));
|
124 | this._cacheAdd('between', result, args);
|
125 | }
|
126 | return result;
|
127 | };
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | RRule.prototype.before = function (dt, inc) {
|
135 | if (inc === void 0) { inc = false; }
|
136 | if (!dateutil.isValidDate(dt))
|
137 | throw new Error('Invalid date passed in to RRule.before');
|
138 | var args = { dt: dt, inc: inc };
|
139 | var result = this._cacheGet('before', args);
|
140 | if (result === false) {
|
141 | result = this._iter(new IterResult('before', args));
|
142 | this._cacheAdd('before', result, args);
|
143 | }
|
144 | return result;
|
145 | };
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | RRule.prototype.after = function (dt, inc) {
|
153 | if (inc === void 0) { inc = false; }
|
154 | if (!dateutil.isValidDate(dt))
|
155 | throw new Error('Invalid date passed in to RRule.after');
|
156 | var args = { dt: dt, inc: inc };
|
157 | var result = this._cacheGet('after', args);
|
158 | if (result === false) {
|
159 | result = this._iter(new IterResult('after', args));
|
160 | this._cacheAdd('after', result, args);
|
161 | }
|
162 | return result;
|
163 | };
|
164 | |
165 |
|
166 |
|
167 |
|
168 | RRule.prototype.count = function () {
|
169 | return this.all().length;
|
170 | };
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 | RRule.prototype.toString = function () {
|
177 | return optionsToString(this.origOptions);
|
178 | };
|
179 | |
180 |
|
181 |
|
182 |
|
183 | RRule.prototype.toText = function (gettext, language, dateFormatter) {
|
184 | return toText(this, gettext, language, dateFormatter);
|
185 | };
|
186 | RRule.prototype.isFullyConvertibleToText = function () {
|
187 | return isFullyConvertible(this);
|
188 | };
|
189 | |
190 |
|
191 |
|
192 |
|
193 | RRule.prototype.clone = function () {
|
194 | return new RRule(this.origOptions);
|
195 | };
|
196 |
|
197 | RRule.FREQUENCIES = [
|
198 | 'YEARLY',
|
199 | 'MONTHLY',
|
200 | 'WEEKLY',
|
201 | 'DAILY',
|
202 | 'HOURLY',
|
203 | 'MINUTELY',
|
204 | 'SECONDLY'
|
205 | ];
|
206 | RRule.YEARLY = Frequency.YEARLY;
|
207 | RRule.MONTHLY = Frequency.MONTHLY;
|
208 | RRule.WEEKLY = Frequency.WEEKLY;
|
209 | RRule.DAILY = Frequency.DAILY;
|
210 | RRule.HOURLY = Frequency.HOURLY;
|
211 | RRule.MINUTELY = Frequency.MINUTELY;
|
212 | RRule.SECONDLY = Frequency.SECONDLY;
|
213 | RRule.MO = Days.MO;
|
214 | RRule.TU = Days.TU;
|
215 | RRule.WE = Days.WE;
|
216 | RRule.TH = Days.TH;
|
217 | RRule.FR = Days.FR;
|
218 | RRule.SA = Days.SA;
|
219 | RRule.SU = Days.SU;
|
220 | RRule.parseString = parseString;
|
221 | RRule.optionsToString = optionsToString;
|
222 | return RRule;
|
223 | }());
|
224 | export default RRule;
|
225 |
|
\ | No newline at end of file |