@nocobase/plugin-field-sequence 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/SequenceFieldProvider.d.ts +2 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +19 -0
- package/dist/client/locale/index.d.ts +3 -0
- package/dist/client/sequence.d.ts +259 -0
- package/dist/externalVersion.js +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +24 -0
- package/dist/locale/es-ES.json +24 -0
- package/dist/locale/fr-FR.json +24 -0
- package/dist/locale/ko_KR.json +24 -0
- package/dist/locale/pt-BR.json +24 -0
- package/dist/locale/zh-CN.json +25 -0
- package/dist/node_modules/cron-parser/.eslintrc.json +15 -0
- package/dist/node_modules/cron-parser/.travis.yml +7 -0
- package/dist/node_modules/cron-parser/LICENSE +21 -0
- package/dist/node_modules/cron-parser/component.json +11 -0
- package/dist/node_modules/cron-parser/index.d.ts +1 -0
- package/dist/node_modules/cron-parser/lib/date.js +252 -0
- package/dist/node_modules/cron-parser/lib/expression.js +983 -0
- package/dist/node_modules/cron-parser/lib/field_compactor.js +70 -0
- package/dist/node_modules/cron-parser/lib/field_stringify.js +38 -0
- package/dist/node_modules/cron-parser/lib/parser.js +1 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/build/amd/luxon.js +8489 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/build/cjs-browser/luxon.js +8487 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/build/global/luxon.js +8490 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/build/global/luxon.min.js +1 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/build/node/luxon.js +7522 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/package.json +96 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/datetime.js +2169 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/duration.js +880 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/errors.js +61 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/conversions.js +157 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/diff.js +80 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/digits.js +76 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/english.js +233 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/formats.js +191 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/formatter.js +386 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/invalid.js +14 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/locale.js +482 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/regexParser.js +335 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/tokenParser.js +424 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/util.js +292 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/impl/zoneUtil.js +36 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/info.js +193 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/interval.js +602 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/luxon.js +26 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/luxonFilled.js +13 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/settings.js +137 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/zone.js +88 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/IANAZone.js +191 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/fixedOffsetZone.js +94 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/invalidZone.js +53 -0
- package/dist/node_modules/cron-parser/node_modules/luxon/src/zones/localZone.js +63 -0
- package/dist/node_modules/cron-parser/package.json +1 -0
- package/dist/node_modules/cron-parser/test/31_of_month.js +17 -0
- package/dist/node_modules/cron-parser/test/bug.js +29 -0
- package/dist/node_modules/cron-parser/test/crondate.js +16 -0
- package/dist/node_modules/cron-parser/test/crontab.example +7 -0
- package/dist/node_modules/cron-parser/test/empty_around_comma.js +22 -0
- package/dist/node_modules/cron-parser/test/expression.js +1489 -0
- package/dist/node_modules/cron-parser/test/field_compactor.js +250 -0
- package/dist/node_modules/cron-parser/test/field_stringify.js +84 -0
- package/dist/node_modules/cron-parser/test/fields.js +32 -0
- package/dist/node_modules/cron-parser/test/increment_on_first_iteration.js +22 -0
- package/dist/node_modules/cron-parser/test/index-ts3.test-d.ts +133 -0
- package/dist/node_modules/cron-parser/test/index.test-d.ts +138 -0
- package/dist/node_modules/cron-parser/test/leap_year.js +17 -0
- package/dist/node_modules/cron-parser/test/parser.js +46 -0
- package/dist/node_modules/cron-parser/test/parser_crondate_formats.js +145 -0
- package/dist/node_modules/cron-parser/test/parser_day_of_month.js +169 -0
- package/dist/node_modules/cron-parser/test/prev_date.js +32 -0
- package/dist/node_modules/cron-parser/test/stringify.js +402 -0
- package/dist/node_modules/cron-parser/test/timezone.js +422 -0
- package/dist/node_modules/cron-parser/types/common.d.ts +131 -0
- package/dist/node_modules/cron-parser/types/index.d.ts +45 -0
- package/dist/node_modules/cron-parser/types/ts3/index.d.ts +28 -0
- package/dist/server/Plugin.d.ts +8 -0
- package/dist/server/Plugin.js +124 -0
- package/dist/server/collections/sequences.d.ts +2 -0
- package/dist/server/collections/sequences.js +88 -0
- package/dist/server/fields/sequence-field.d.ts +38 -0
- package/dist/server/fields/sequence-field.js +386 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +39 -0
- package/dist/server/migrations/20221207022250-sequence-field-key.d.ts +6 -0
- package/dist/server/migrations/20221207022250-sequence-field-key.js +85 -0
- package/dist/server/migrations/20240425225438-change-locale-module.d.ts +6 -0
- package/dist/server/migrations/20240425225438-change-locale-module.js +42 -0
- package/package.json +36 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
var test = require('tap').test;
|
|
2
|
+
var CronExpression = require('../lib/expression');
|
|
3
|
+
|
|
4
|
+
test('It works on DST start', function(t) {
|
|
5
|
+
try {
|
|
6
|
+
var options = {
|
|
7
|
+
currentDate: '2016-03-27 02:00:01',
|
|
8
|
+
tz: 'Europe/Athens'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var interval, date;
|
|
12
|
+
|
|
13
|
+
interval = CronExpression.parse('0 * * * *', options);
|
|
14
|
+
t.ok(interval, 'Interval parsed');
|
|
15
|
+
|
|
16
|
+
date = interval.next();
|
|
17
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
18
|
+
t.equal(date.getHours(), 4, 'Due to DST start in Athens, 3 is skipped');
|
|
19
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
20
|
+
|
|
21
|
+
date = interval.next();
|
|
22
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
23
|
+
t.equal(date.getHours(), 5, '5 AM');
|
|
24
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
25
|
+
|
|
26
|
+
interval = CronExpression.parse('30 2 * * *', options);
|
|
27
|
+
t.ok(interval, 'Interval parsed');
|
|
28
|
+
|
|
29
|
+
date = interval.next();
|
|
30
|
+
t.equal(date.getMinutes(), 30, '30 Minutes');
|
|
31
|
+
t.equal(date.getHours(), 2, '2 AM');
|
|
32
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
33
|
+
|
|
34
|
+
date = interval.next();
|
|
35
|
+
t.equal(date.getMinutes(), 30, '30 Minutes');
|
|
36
|
+
t.equal(date.getHours(), 2, '2 AM');
|
|
37
|
+
t.equal(date.getDate(), 28, 'on the 28th');
|
|
38
|
+
|
|
39
|
+
interval = CronExpression.parse('0 3 * * *', options);
|
|
40
|
+
t.ok(interval, 'Interval parsed');
|
|
41
|
+
|
|
42
|
+
date = interval.next();
|
|
43
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
44
|
+
t.equal(date.getHours(), 4, 'Due to DST start in Athens, 3 is skipped');
|
|
45
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
46
|
+
|
|
47
|
+
date = interval.next();
|
|
48
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
49
|
+
t.equal(date.getHours(), 3, '3 on the 28th');
|
|
50
|
+
t.equal(date.getDate(), 28, 'on the 28th');
|
|
51
|
+
|
|
52
|
+
interval = CronExpression.parse('*/20 3 * * *', options);
|
|
53
|
+
t.ok(interval, 'Interval parsed');
|
|
54
|
+
|
|
55
|
+
date = interval.next();
|
|
56
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
57
|
+
t.equal(date.getHours(), 4, 'Due to DST start in Athens, 3 is skipped');
|
|
58
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
59
|
+
|
|
60
|
+
date = interval.next();
|
|
61
|
+
t.equal(date.getMinutes(), 20, '20 Minutes');
|
|
62
|
+
t.equal(date.getHours(), 4, 'Due to DST start in Athens, 3 is skipped');
|
|
63
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
64
|
+
|
|
65
|
+
date = interval.next();
|
|
66
|
+
t.equal(date.getMinutes(), 40, '20 Minutes');
|
|
67
|
+
t.equal(date.getHours(), 4, 'Due to DST start in Athens, 3 is skipped');
|
|
68
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
69
|
+
|
|
70
|
+
date = interval.next();
|
|
71
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
72
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
73
|
+
t.equal(date.getDate(), 28, 'on the 28th');
|
|
74
|
+
|
|
75
|
+
options.currentDate = '2016-03-27 00:00:01';
|
|
76
|
+
|
|
77
|
+
interval = CronExpression.parse('0 * 27 * *', options);
|
|
78
|
+
t.ok(interval, 'Interval parsed');
|
|
79
|
+
|
|
80
|
+
date = interval.next();
|
|
81
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
82
|
+
t.equal(date.getHours(), 1, '1 AM');
|
|
83
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
84
|
+
|
|
85
|
+
date = interval.next();
|
|
86
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
87
|
+
t.equal(date.getHours(), 2, '2 AM');
|
|
88
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
89
|
+
|
|
90
|
+
date = interval.next();
|
|
91
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
92
|
+
t.equal(date.getHours(), 4, '4 AM');
|
|
93
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
94
|
+
|
|
95
|
+
date = interval.next();
|
|
96
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
97
|
+
t.equal(date.getHours(), 5, '5 AM');
|
|
98
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
99
|
+
|
|
100
|
+
options.currentDate = '2016-03-27 00:00:01';
|
|
101
|
+
options.endDate = '2016-03-27 03:00:01';
|
|
102
|
+
|
|
103
|
+
interval = CronExpression.parse('0 * * * *', options);
|
|
104
|
+
t.ok(interval, 'Interval parsed');
|
|
105
|
+
|
|
106
|
+
date = interval.next();
|
|
107
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
108
|
+
t.equal(date.getHours(), 1, '1 AM');
|
|
109
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
110
|
+
|
|
111
|
+
date = interval.next();
|
|
112
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
113
|
+
t.equal(date.getHours(), 2, '2 AM');
|
|
114
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
115
|
+
|
|
116
|
+
date = interval.next();
|
|
117
|
+
t.equal(date.getMinutes(), 0, '0 Minutes');
|
|
118
|
+
t.equal(date.getHours(), 4, '4 AM');
|
|
119
|
+
t.equal(date.getDate(), 27, 'on the 27th');
|
|
120
|
+
|
|
121
|
+
// Out of the timespan range
|
|
122
|
+
t.throws(function() {
|
|
123
|
+
date = interval.next();
|
|
124
|
+
});
|
|
125
|
+
} catch (err) {
|
|
126
|
+
t.error(err, 'Interval parse error');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
t.end();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('It works on DST end', function(t) {
|
|
133
|
+
try {
|
|
134
|
+
var options = {
|
|
135
|
+
currentDate: '2016-10-30 02:00:01',
|
|
136
|
+
tz: 'Europe/Athens'
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
var interval, date;
|
|
140
|
+
|
|
141
|
+
interval = CronExpression.parse('0 * * * *', options);
|
|
142
|
+
t.ok(interval, 'Interval parsed');
|
|
143
|
+
|
|
144
|
+
date = interval.next();
|
|
145
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
146
|
+
t.equal(date.getDate(), 30, '30th');
|
|
147
|
+
|
|
148
|
+
date = interval.next();
|
|
149
|
+
t.equal(date.getHours(), 3, 'Due to DST end in Athens (4-->3)');
|
|
150
|
+
t.equal(date.getDate(), 30, '30th');
|
|
151
|
+
|
|
152
|
+
date = interval.next();
|
|
153
|
+
t.equal(date.getHours(), 4, '4 AM');
|
|
154
|
+
t.equal(date.getDate(), 30, '30th');
|
|
155
|
+
|
|
156
|
+
interval = CronExpression.parse('0 3 * * *', options);
|
|
157
|
+
t.ok(interval, 'Interval parsed');
|
|
158
|
+
|
|
159
|
+
date = interval.next();
|
|
160
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
161
|
+
t.equal(date.getDate(), 30, '30th');
|
|
162
|
+
|
|
163
|
+
date = interval.next();
|
|
164
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
165
|
+
t.equal(date.getDate(), 31, '31st');
|
|
166
|
+
|
|
167
|
+
interval = CronExpression.parse('*/20 3 * * *', options);
|
|
168
|
+
t.ok(interval, 'Interval parsed');
|
|
169
|
+
|
|
170
|
+
date = interval.next();
|
|
171
|
+
t.equal(date.getMinutes(), 0, '0');
|
|
172
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
173
|
+
t.equal(date.getDate(), 30, '30th');
|
|
174
|
+
|
|
175
|
+
date = interval.next();
|
|
176
|
+
t.equal(date.getMinutes(), 20, '20');
|
|
177
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
178
|
+
t.equal(date.getDate(), 30, '30th');
|
|
179
|
+
|
|
180
|
+
date = interval.next();
|
|
181
|
+
t.equal(date.getMinutes(), 40, '40');
|
|
182
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
183
|
+
t.equal(date.getDate(), 30, '30th');
|
|
184
|
+
|
|
185
|
+
date = interval.next();
|
|
186
|
+
t.equal(date.getMinutes(), 0, '0');
|
|
187
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
188
|
+
t.equal(date.getDate(), 31, '31st');
|
|
189
|
+
|
|
190
|
+
options.currentDate = '2016-10-30 00:00:01';
|
|
191
|
+
|
|
192
|
+
interval = CronExpression.parse('0 * 30 * *', options);
|
|
193
|
+
t.ok(interval, 'Interval parsed');
|
|
194
|
+
|
|
195
|
+
date = interval.next();
|
|
196
|
+
t.equal(date.getHours(), 1, '1 AM');
|
|
197
|
+
t.equal(date.getDate(), 30, '30th');
|
|
198
|
+
|
|
199
|
+
date = interval.next();
|
|
200
|
+
t.equal(date.getHours(), 2, '2 AM');
|
|
201
|
+
t.equal(date.getDate(), 30, '30th');
|
|
202
|
+
|
|
203
|
+
date = interval.next();
|
|
204
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
205
|
+
t.equal(date.getDate(), 30, '30th');
|
|
206
|
+
|
|
207
|
+
date = interval.next();
|
|
208
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
209
|
+
t.equal(date.getDate(), 30, '30th');
|
|
210
|
+
|
|
211
|
+
date = interval.next();
|
|
212
|
+
t.equal(date.getHours(), 4, '4 AM');
|
|
213
|
+
t.equal(date.getDate(), 30, '30th');
|
|
214
|
+
|
|
215
|
+
options.currentDate = '2016-10-30 00:00:01';
|
|
216
|
+
// specify the DST offset via ISO 8601 format, as 3am is repeated
|
|
217
|
+
options.endDate = '2016-10-30T03:00:01+03';
|
|
218
|
+
|
|
219
|
+
interval = CronExpression.parse('0 * * * *', options);
|
|
220
|
+
t.ok(interval, 'Interval parsed');
|
|
221
|
+
|
|
222
|
+
date = interval.next();
|
|
223
|
+
t.equal(date.getHours(), 1, '1 AM');
|
|
224
|
+
t.equal(date.getDate(), 30, '30th');
|
|
225
|
+
|
|
226
|
+
date = interval.next();
|
|
227
|
+
t.equal(date.getHours(), 2, '2 AM');
|
|
228
|
+
t.equal(date.getDate(), 30, '30th');
|
|
229
|
+
|
|
230
|
+
date = interval.next();
|
|
231
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
232
|
+
t.equal(date.getDate(), 30, '30th');
|
|
233
|
+
|
|
234
|
+
// Out of the timespan range
|
|
235
|
+
t.throws(function() {
|
|
236
|
+
date = interval.next();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
options.endDate = '2016-10-30 04:00:01';
|
|
240
|
+
|
|
241
|
+
interval = CronExpression.parse('0 * * * *', options);
|
|
242
|
+
t.ok(interval, 'Interval parsed');
|
|
243
|
+
|
|
244
|
+
date = interval.next();
|
|
245
|
+
t.equal(date.getHours(), 1, '1 AM');
|
|
246
|
+
t.equal(date.getDate(), 30, '30th');
|
|
247
|
+
|
|
248
|
+
date = interval.next();
|
|
249
|
+
t.equal(date.getHours(), 2, '2 AM');
|
|
250
|
+
t.equal(date.getDate(), 30, '30th');
|
|
251
|
+
|
|
252
|
+
date = interval.next();
|
|
253
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
254
|
+
t.equal(date.getDate(), 30, '30th');
|
|
255
|
+
|
|
256
|
+
date = interval.next();
|
|
257
|
+
t.equal(date.getHours(), 3, '3 AM');
|
|
258
|
+
t.equal(date.getDate(), 30, '30th');
|
|
259
|
+
|
|
260
|
+
date = interval.next();
|
|
261
|
+
t.equal(date.getHours(), 4, '4 AM');
|
|
262
|
+
t.equal(date.getDate(), 30, '30th');
|
|
263
|
+
|
|
264
|
+
// Out of the timespan range
|
|
265
|
+
t.throws(function() {
|
|
266
|
+
date = interval.next();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
options = {
|
|
270
|
+
currentDate : new Date('Sun Oct 29 2016 01:00:00 GMT+0200')
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
interval = CronExpression.parse('0 12 * * *', options);
|
|
274
|
+
t.ok(interval, 'Interval parsed');
|
|
275
|
+
|
|
276
|
+
date = interval.next();
|
|
277
|
+
t.equal(date.getHours(), 12, '12');
|
|
278
|
+
t.equal(date.getDate(), 29, '29th');
|
|
279
|
+
date = interval.next();
|
|
280
|
+
t.equal(date.getHours(), 12, '12');
|
|
281
|
+
t.equal(date.getDate(), 30, '30th');
|
|
282
|
+
date = interval.next();
|
|
283
|
+
t.equal(date.getHours(), 12, '12');
|
|
284
|
+
t.equal(date.getDate(), 31, '31st');
|
|
285
|
+
|
|
286
|
+
options = {
|
|
287
|
+
currentDate : new Date('Sun Oct 29 2016 02:59:00 GMT+0200')
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
interval = CronExpression.parse('0 12 * * *', options);
|
|
291
|
+
t.ok(interval, 'Interval parsed');
|
|
292
|
+
|
|
293
|
+
date = interval.next();
|
|
294
|
+
t.equal(date.getHours(), 12, '12');
|
|
295
|
+
t.equal(date.getDate(), 29, '29th');
|
|
296
|
+
date = interval.next();
|
|
297
|
+
t.equal(date.getHours(), 12, '12');
|
|
298
|
+
t.equal(date.getDate(), 30, '30th');
|
|
299
|
+
date = interval.next();
|
|
300
|
+
t.equal(date.getHours(), 12, '12');
|
|
301
|
+
t.equal(date.getDate(), 31, '31st');
|
|
302
|
+
|
|
303
|
+
options = {
|
|
304
|
+
currentDate : new Date('Sun Oct 29 2016 02:59:59 GMT+0200')
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
interval = CronExpression.parse('0 12 * * *', options);
|
|
308
|
+
t.ok(interval, 'Interval parsed');
|
|
309
|
+
|
|
310
|
+
date = interval.next();
|
|
311
|
+
t.equal(date.getHours(), 12, '12');
|
|
312
|
+
t.equal(date.getDate(), 29, '29th');
|
|
313
|
+
date = interval.next();
|
|
314
|
+
t.equal(date.getHours(), 12, '12');
|
|
315
|
+
t.equal(date.getDate(), 30, '30th');
|
|
316
|
+
date = interval.next();
|
|
317
|
+
t.equal(date.getHours(), 12, '12');
|
|
318
|
+
t.equal(date.getDate(), 31, '31st');
|
|
319
|
+
|
|
320
|
+
options = {
|
|
321
|
+
currentDate : new Date('Sun Oct 30 2016 01:00:00 GMT+0200')
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
interval = CronExpression.parse('0 12 * * *', options);
|
|
325
|
+
t.ok(interval, 'Interval parsed');
|
|
326
|
+
|
|
327
|
+
date = interval.next();
|
|
328
|
+
t.equal(date.getHours(), 12, '12');
|
|
329
|
+
t.equal(date.getDate(), 30, '30th');
|
|
330
|
+
date = interval.next();
|
|
331
|
+
t.equal(date.getHours(), 12, '12');
|
|
332
|
+
t.equal(date.getDate(), 31, '31st');
|
|
333
|
+
|
|
334
|
+
options = {
|
|
335
|
+
currentDate : new Date('Sun Oct 30 2016 01:59:00 GMT+0200')
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
interval = CronExpression.parse('0 12 * * *', options);
|
|
339
|
+
t.ok(interval, 'Interval parsed');
|
|
340
|
+
|
|
341
|
+
date = interval.next();
|
|
342
|
+
t.equal(date.getHours(), 12, '12');
|
|
343
|
+
t.equal(date.getDate(), 30, '30th');
|
|
344
|
+
date = interval.next();
|
|
345
|
+
t.equal(date.getHours(), 12, '12');
|
|
346
|
+
t.equal(date.getDate(), 31, '31st');
|
|
347
|
+
|
|
348
|
+
options = {
|
|
349
|
+
currentDate : new Date('Sun Oct 30 2016 01:59:59 GMT+0200')
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
interval = CronExpression.parse('0 12 * * *', options);
|
|
353
|
+
t.ok(interval, 'Interval parsed');
|
|
354
|
+
|
|
355
|
+
date = interval.next();
|
|
356
|
+
t.equal(date.getHours(), 12, '12');
|
|
357
|
+
t.equal(date.getDate(), 30, '30th');
|
|
358
|
+
date = interval.next();
|
|
359
|
+
t.equal(date.getHours(), 12, '12');
|
|
360
|
+
t.equal(date.getDate(), 31, '31st');
|
|
361
|
+
|
|
362
|
+
options = {
|
|
363
|
+
currentDate : new Date('Sun Oct 30 2016 02:59:00 GMT+0200')
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
interval = CronExpression.parse('0 12 * * *', options);
|
|
367
|
+
t.ok(interval, 'Interval parsed');
|
|
368
|
+
|
|
369
|
+
date = interval.next();
|
|
370
|
+
t.equal(date.getHours(), 12, '12');
|
|
371
|
+
t.equal(date.getDate(), 30, '30th');
|
|
372
|
+
date = interval.next();
|
|
373
|
+
t.equal(date.getHours(), 12, '12');
|
|
374
|
+
t.equal(date.getDate(), 31, '31st');
|
|
375
|
+
} catch (err) {
|
|
376
|
+
t.error(err, 'Interval parse error');
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
t.end();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
test('it will work with #131 issue case', function(t) {
|
|
383
|
+
var options = {
|
|
384
|
+
tz: 'America/Sao_Paulo',
|
|
385
|
+
currentDate : new Date('Sun Oct 30 2018 02:59:00 GMT+0200')
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
var interval = CronExpression.parse('0 9 1 1 *', options);
|
|
389
|
+
var date = interval.next();
|
|
390
|
+
|
|
391
|
+
t.equal(date.getFullYear(), 2019);
|
|
392
|
+
t.equal(date.getDate(), 1);
|
|
393
|
+
t.equal(date.getMonth(), 0);
|
|
394
|
+
|
|
395
|
+
date = interval.prev();
|
|
396
|
+
t.equal(date.getFullYear(), 2018);
|
|
397
|
+
t.equal(date.getDate(), 1);
|
|
398
|
+
t.equal(date.getMonth(), 0);
|
|
399
|
+
|
|
400
|
+
date = interval.prev();
|
|
401
|
+
t.equal(date.getFullYear(), 2017);
|
|
402
|
+
t.equal(date.getDate(), 1);
|
|
403
|
+
t.equal(date.getMonth(), 0);
|
|
404
|
+
|
|
405
|
+
t.end();
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test('it will work with #137 issue case', function(t) {
|
|
409
|
+
var options = {
|
|
410
|
+
tz: 'America/New_York',
|
|
411
|
+
currentDate : new Date('10/28/2018')
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
var interval = CronExpression.parse('0 12 * * 3', options);
|
|
415
|
+
var date = interval.next();
|
|
416
|
+
|
|
417
|
+
t.equal(date.getFullYear(), 2018);
|
|
418
|
+
t.equal(date.getDate(), 31);
|
|
419
|
+
t.equal(date.getMonth(), 9);
|
|
420
|
+
|
|
421
|
+
t.end();
|
|
422
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
export type DateType = Date | number | string
|
|
2
|
+
|
|
3
|
+
export interface CronDate {
|
|
4
|
+
addYear(): void
|
|
5
|
+
|
|
6
|
+
addMonth(): void
|
|
7
|
+
|
|
8
|
+
addDay(): void
|
|
9
|
+
|
|
10
|
+
addHour(): void
|
|
11
|
+
|
|
12
|
+
addMinute(): void
|
|
13
|
+
|
|
14
|
+
addSecond(): void
|
|
15
|
+
|
|
16
|
+
subtractYear(): void
|
|
17
|
+
|
|
18
|
+
subtractMonth(): void
|
|
19
|
+
|
|
20
|
+
subtractDay(): void
|
|
21
|
+
|
|
22
|
+
subtractHour(): void
|
|
23
|
+
|
|
24
|
+
subtractMinute(): void
|
|
25
|
+
|
|
26
|
+
subtractSecond(): void
|
|
27
|
+
|
|
28
|
+
getDate(): number
|
|
29
|
+
|
|
30
|
+
getFullYear(): number
|
|
31
|
+
|
|
32
|
+
getDay(): number
|
|
33
|
+
|
|
34
|
+
getMonth(): number
|
|
35
|
+
|
|
36
|
+
getHours(): number
|
|
37
|
+
|
|
38
|
+
getMinutes(): number
|
|
39
|
+
|
|
40
|
+
getSeconds(): number
|
|
41
|
+
|
|
42
|
+
getMilliseconds(): number
|
|
43
|
+
|
|
44
|
+
getTime(): number
|
|
45
|
+
|
|
46
|
+
getUTCDate(): number
|
|
47
|
+
|
|
48
|
+
getUTCFullYear(): number
|
|
49
|
+
|
|
50
|
+
getUTCDay(): number
|
|
51
|
+
|
|
52
|
+
getUTCMonth(): number
|
|
53
|
+
|
|
54
|
+
getUTCHours(): number
|
|
55
|
+
|
|
56
|
+
getUTCMinutes(): number
|
|
57
|
+
|
|
58
|
+
getUTCSeconds(): number
|
|
59
|
+
|
|
60
|
+
toISOString(): string
|
|
61
|
+
|
|
62
|
+
toJSON(): string
|
|
63
|
+
|
|
64
|
+
setDate(d: number): void
|
|
65
|
+
|
|
66
|
+
setFullYear(y: number): void
|
|
67
|
+
|
|
68
|
+
setDay(d: number): void
|
|
69
|
+
|
|
70
|
+
setMonth(m: number): void
|
|
71
|
+
|
|
72
|
+
setHours(h: number): void
|
|
73
|
+
|
|
74
|
+
setMinutes(m: number): void
|
|
75
|
+
|
|
76
|
+
setSeconds(s: number): void
|
|
77
|
+
|
|
78
|
+
setMilliseconds(s: number): void
|
|
79
|
+
|
|
80
|
+
getTime(): number
|
|
81
|
+
|
|
82
|
+
toString(): string
|
|
83
|
+
|
|
84
|
+
toDate(): Date
|
|
85
|
+
|
|
86
|
+
isLastDayOfMonth(): boolean
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ParserOptions<IsIterable extends boolean = false> {
|
|
90
|
+
currentDate?: DateType
|
|
91
|
+
startDate?: DateType
|
|
92
|
+
endDate?: DateType
|
|
93
|
+
utc?: boolean
|
|
94
|
+
tz?: string
|
|
95
|
+
nthDayOfWeek?: number
|
|
96
|
+
iterator?: IsIterable
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
type IteratorResultOrCronDate<IsIterable extends boolean> = IsIterable extends true
|
|
100
|
+
? IteratorResult<CronDate, CronDate>
|
|
101
|
+
: CronDate;
|
|
102
|
+
|
|
103
|
+
export interface ICronExpression<CronFields, IsIterable extends boolean> {
|
|
104
|
+
readonly fields: CronFields;
|
|
105
|
+
|
|
106
|
+
/** Find next suitable date */
|
|
107
|
+
next(): IteratorResultOrCronDate<IsIterable>
|
|
108
|
+
|
|
109
|
+
/** Find previous suitable date */
|
|
110
|
+
prev(): IteratorResultOrCronDate<IsIterable>
|
|
111
|
+
|
|
112
|
+
/** Check if next suitable date exists */
|
|
113
|
+
hasNext(): boolean
|
|
114
|
+
|
|
115
|
+
/** Check if previous suitable date exists */
|
|
116
|
+
hasPrev(): boolean
|
|
117
|
+
|
|
118
|
+
/** Iterate over expression iterator */
|
|
119
|
+
iterate(steps: number, callback?: (item: IteratorResultOrCronDate<IsIterable>, i: number) => void): IteratorResultOrCronDate<IsIterable>[]
|
|
120
|
+
|
|
121
|
+
/** Reset expression iterator state */
|
|
122
|
+
reset(resetDate?: string | number | Date): void
|
|
123
|
+
|
|
124
|
+
stringify(includeSeconds?: boolean): string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface IStringResult<CronFields> {
|
|
128
|
+
variables: Record<string, string>,
|
|
129
|
+
expressions: ICronExpression<CronFields, false>[],
|
|
130
|
+
errors: Record<string, any>,
|
|
131
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CronDate,
|
|
3
|
+
DateType,
|
|
4
|
+
ICronExpression,
|
|
5
|
+
IStringResult,
|
|
6
|
+
ParserOptions,
|
|
7
|
+
} from './common';
|
|
8
|
+
|
|
9
|
+
type BuildRangeTuple<Current extends [...number[]], Count extends number> =
|
|
10
|
+
Current["length"] extends Count
|
|
11
|
+
? Current
|
|
12
|
+
: BuildRangeTuple<[number, ...Current], Count>
|
|
13
|
+
type RangeTuple<Count extends number> = BuildRangeTuple<[], Count>
|
|
14
|
+
type BuildRange<Current extends number, End extends number, Accu extends [...number[]]> =
|
|
15
|
+
Accu["length"] extends End
|
|
16
|
+
? Current
|
|
17
|
+
: BuildRange<Current | Accu["length"], End, [number, ...Accu]>
|
|
18
|
+
type Range<StartInclusive extends number, EndExclusive extends number> = BuildRange<StartInclusive, EndExclusive, RangeTuple<StartInclusive>>
|
|
19
|
+
|
|
20
|
+
export type SixtyRange = Range<0, 30> | Range<30, 60>; // Typescript restriction on recursion depth
|
|
21
|
+
export type HourRange = Range<0, 24>;
|
|
22
|
+
export type DayOfTheMonthRange = Range<1, 32> | 'L';
|
|
23
|
+
export type MonthRange = Range<1, 13>;
|
|
24
|
+
export type DayOfTheWeekRange = Range<0, 8>;
|
|
25
|
+
|
|
26
|
+
export type CronFields = {
|
|
27
|
+
readonly second: readonly SixtyRange[];
|
|
28
|
+
readonly minute: readonly SixtyRange[];
|
|
29
|
+
readonly hour: readonly HourRange[];
|
|
30
|
+
readonly dayOfMonth: readonly DayOfTheMonthRange[];
|
|
31
|
+
readonly month: readonly MonthRange[];
|
|
32
|
+
readonly dayOfWeek: readonly DayOfTheWeekRange[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {ParserOptions, CronDate, DateType}
|
|
36
|
+
export type CronExpression<IsIterable extends boolean = false> = ICronExpression<CronFields, IsIterable>
|
|
37
|
+
export type StringResult = IStringResult<CronFields>
|
|
38
|
+
|
|
39
|
+
export function parseExpression<IsIterable extends boolean = false>(expression: string, options?: ParserOptions<IsIterable>): CronExpression<IsIterable>;
|
|
40
|
+
|
|
41
|
+
export function fieldsToExpression<IsIterable extends boolean = false>(fields: CronFields, options?: ParserOptions<IsIterable>): CronExpression<IsIterable>;
|
|
42
|
+
|
|
43
|
+
export function parseFile(filePath: string, callback: (err: any, data: StringResult) => any): void;
|
|
44
|
+
|
|
45
|
+
export function parseString(data: string): StringResult;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CronDate,
|
|
3
|
+
DateType,
|
|
4
|
+
ICronExpression,
|
|
5
|
+
IStringResult,
|
|
6
|
+
ParserOptions,
|
|
7
|
+
} from '../common';
|
|
8
|
+
|
|
9
|
+
export type CronFields = {
|
|
10
|
+
readonly second: readonly number[];
|
|
11
|
+
readonly minute: readonly number[];
|
|
12
|
+
readonly hour: readonly number[];
|
|
13
|
+
readonly dayOfMonth: readonly (number | 'L')[];
|
|
14
|
+
readonly month: readonly number[];
|
|
15
|
+
readonly dayOfWeek: readonly number[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {ParserOptions, CronDate, DateType}
|
|
19
|
+
export type CronExpression<IsIterable extends boolean = false> = ICronExpression<CronFields, IsIterable>
|
|
20
|
+
export type StringResult = IStringResult<CronFields>
|
|
21
|
+
|
|
22
|
+
export function parseExpression<IsIterable extends boolean = false>(expression: string, options?: ParserOptions<IsIterable>): CronExpression<IsIterable>;
|
|
23
|
+
|
|
24
|
+
export function fieldsToExpression<IsIterable extends boolean = false>(fields: CronFields, options?: ParserOptions<IsIterable>): CronExpression<IsIterable>;
|
|
25
|
+
|
|
26
|
+
export function parseFile(filePath: string, callback: (err: any, data: StringResult) => any): void;
|
|
27
|
+
|
|
28
|
+
export function parseString(data: string): StringResult;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin } from '@nocobase/server';
|
|
2
|
+
import { Registry } from '@nocobase/utils';
|
|
3
|
+
import { Pattern } from './fields/sequence-field';
|
|
4
|
+
export default class PluginFieldSequenceServer extends Plugin {
|
|
5
|
+
patternTypes: Registry<Pattern>;
|
|
6
|
+
load(): Promise<void>;
|
|
7
|
+
install(): Promise<void>;
|
|
8
|
+
}
|