cronli5 0.2.0 → 0.2.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/CHANGELOG.md +25 -0
- package/README.md +4 -4
- package/cronli5.min.js +2 -2
- package/dist/cronli5.cjs +123 -104
- package/dist/cronli5.js +123 -104
- package/dist/lang/de.cjs +65 -65
- package/dist/lang/de.js +65 -65
- package/dist/lang/en.cjs +122 -101
- package/dist/lang/en.js +122 -101
- package/dist/lang/es.cjs +71 -72
- package/dist/lang/es.js +71 -72
- package/dist/lang/fi.cjs +71 -66
- package/dist/lang/fi.js +71 -66
- package/dist/lang/zh.cjs +36 -36
- package/dist/lang/zh.js +36 -36
- package/package.json +1 -1
- package/src/core/analyze.ts +14 -13
- package/src/core/ir.ts +8 -8
- package/src/core/shapes.ts +8 -1
- package/src/core/util.ts +86 -3
- package/src/core/validate.ts +1 -1
- package/src/cronli5.ts +3 -3
- package/src/lang/de/index.ts +30 -99
- package/src/lang/en/index.ts +163 -188
- package/src/lang/es/index.ts +36 -120
- package/src/lang/fi/index.ts +33 -104
- package/src/lang/zh/index.ts +23 -48
- package/src/types.ts +2 -2
- package/types/core/analyze.d.ts +2 -2
- package/types/core/ir.d.ts +7 -7
- package/types/core/shapes.d.ts +2 -1
- package/types/core/util.d.ts +17 -2
- package/types/types.d.ts +1 -1
package/dist/lang/es.js
CHANGED
|
@@ -69,6 +69,48 @@ function orderWeekdaysForDisplay(segments) {
|
|
|
69
69
|
function toFieldNumber(token, numberMap) {
|
|
70
70
|
return isNonNegativeInteger(token) ? +token : numberMap[token.toUpperCase()];
|
|
71
71
|
}
|
|
72
|
+
function segmentsOf(ir, field) {
|
|
73
|
+
return ir.analyses.segments[field] ?? [];
|
|
74
|
+
}
|
|
75
|
+
function stepSegment(ir, field) {
|
|
76
|
+
return segmentsOf(ir, field)[0];
|
|
77
|
+
}
|
|
78
|
+
function singleValues(segments) {
|
|
79
|
+
const values = [];
|
|
80
|
+
for (const segment of segments) {
|
|
81
|
+
if (segment.kind !== "single") {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
values.push(+segment.value);
|
|
85
|
+
}
|
|
86
|
+
return values;
|
|
87
|
+
}
|
|
88
|
+
function offsetCleanStride(stride) {
|
|
89
|
+
return stride.start < stride.interval && 24 % stride.interval === 0;
|
|
90
|
+
}
|
|
91
|
+
function hourListStride(values) {
|
|
92
|
+
if (values.length < 2) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const interval = values[1] - values[0];
|
|
96
|
+
if (interval < 2) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
for (let i = 2; i < values.length; i += 1) {
|
|
100
|
+
if (values[i] - values[i - 1] !== interval) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (values[0] !== 0 && values.length < 5) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return { interval, last: values[values.length - 1], start: values[0] };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/core/shapes.ts
|
|
111
|
+
function isOpenStep(field) {
|
|
112
|
+
return field.indexOf("/") !== -1 && field.indexOf("-") === -1 && field.indexOf(",") === -1;
|
|
113
|
+
}
|
|
72
114
|
|
|
73
115
|
// src/lang/es/dialects.ts
|
|
74
116
|
var es = {
|
|
@@ -95,15 +137,6 @@ function resolveDialect(dialect) {
|
|
|
95
137
|
}
|
|
96
138
|
|
|
97
139
|
// src/lang/es/index.ts
|
|
98
|
-
function stepSegment(segments) {
|
|
99
|
-
return segments[0];
|
|
100
|
-
}
|
|
101
|
-
function hourSegments(ir) {
|
|
102
|
-
return ir.analyses.segments.hour;
|
|
103
|
-
}
|
|
104
|
-
function fieldSegments(ir, field) {
|
|
105
|
-
return ir.analyses.segments[field];
|
|
106
|
-
}
|
|
107
140
|
var numeros = [
|
|
108
141
|
"cero",
|
|
109
142
|
"uno",
|
|
@@ -189,8 +222,8 @@ function secondsListAtClock(ir, rest, opts) {
|
|
|
189
222
|
});
|
|
190
223
|
const grouped = groupClockTimesByArticle(clockPhrases);
|
|
191
224
|
const clockList = grouped.startsWith("a ") ? grouped.slice(2) : grouped;
|
|
192
|
-
const stride = strideFromSegments(
|
|
193
|
-
const secondsPhrase = stride ?? "en los segundos " + joinList(segmentWords(
|
|
225
|
+
const stride = strideFromSegments(segmentsOf(ir, "second"), "segundo", "", opts);
|
|
226
|
+
const secondsPhrase = stride ?? "en los segundos " + joinList(segmentWords(segmentsOf(ir, "second")));
|
|
194
227
|
const dayFrame = trailingQualifier(ir, opts);
|
|
195
228
|
return (dayFrame ? dayFrame.trimStart() + ", " : "") + secondsPhrase + " de " + clockList;
|
|
196
229
|
}
|
|
@@ -220,7 +253,7 @@ function renderComposeSeconds(ir, plan, opts) {
|
|
|
220
253
|
const restNode = plan.rest;
|
|
221
254
|
const window = hourWindow(boundedWindow(restNode), opts);
|
|
222
255
|
const dayFrame = weekdayQualifier(ir) + monthScope(ir);
|
|
223
|
-
const cadence = "cada " + numero(stepSegment(ir
|
|
256
|
+
const cadence = "cada " + numero(stepSegment(ir, "second").interval, opts) + " segundos del minuto " + ir.pattern.minute;
|
|
224
257
|
return dayFrame + ", " + window + ", " + cadence;
|
|
225
258
|
}
|
|
226
259
|
if (isEveryOtherMinuteSeconds(ir, plan)) {
|
|
@@ -234,7 +267,7 @@ function isEveryOtherMinuteSeconds(ir, plan) {
|
|
|
234
267
|
if (plan.rest.kind !== "minuteFrequency" || ir.shapes.second !== "wildcard" || ir.shapes.hour !== "wildcard") {
|
|
235
268
|
return false;
|
|
236
269
|
}
|
|
237
|
-
const minuteStep = stepSegment(ir
|
|
270
|
+
const minuteStep = stepSegment(ir, "minute");
|
|
238
271
|
return minuteStep.startToken === "*" && minuteStep.interval === 2;
|
|
239
272
|
}
|
|
240
273
|
function pinnedMinuteSeconds(ir, rest, opts) {
|
|
@@ -256,7 +289,7 @@ function secondsClause(ir, anchor, opts) {
|
|
|
256
289
|
}
|
|
257
290
|
if (shape === "step") {
|
|
258
291
|
return stepCycle60(
|
|
259
|
-
stepSegment(ir
|
|
292
|
+
stepSegment(ir, "second"),
|
|
260
293
|
"segundo",
|
|
261
294
|
anchor,
|
|
262
295
|
opts
|
|
@@ -270,11 +303,11 @@ function secondsClause(ir, anchor, opts) {
|
|
|
270
303
|
return "en el segundo " + secondField + " de cada " + anchor;
|
|
271
304
|
}
|
|
272
305
|
return strideFromSegments(
|
|
273
|
-
|
|
306
|
+
segmentsOf(ir, "second"),
|
|
274
307
|
"segundo",
|
|
275
308
|
anchor,
|
|
276
309
|
opts
|
|
277
|
-
) ?? "en los segundos " + joinList(segmentWords(
|
|
310
|
+
) ?? "en los segundos " + joinList(segmentWords(segmentsOf(ir, "second"))) + " de cada " + anchor;
|
|
278
311
|
}
|
|
279
312
|
function renderEveryMinute(ir, plan, opts) {
|
|
280
313
|
return "cada minuto" + trailingQualifier(ir, opts);
|
|
@@ -290,11 +323,11 @@ function renderMultipleMinutes(ir, plan, opts) {
|
|
|
290
323
|
}
|
|
291
324
|
function minutesList(ir, opts) {
|
|
292
325
|
return strideFromSegments(
|
|
293
|
-
|
|
326
|
+
segmentsOf(ir, "minute"),
|
|
294
327
|
"minuto",
|
|
295
328
|
"hora",
|
|
296
329
|
opts
|
|
297
|
-
) ?? "en los minutos " + joinList(segmentWords(
|
|
330
|
+
) ?? "en los minutos " + joinList(segmentWords(segmentsOf(ir, "minute"))) + " de cada hora";
|
|
298
331
|
}
|
|
299
332
|
function minuteRangeLead(minuteField) {
|
|
300
333
|
const bounds = minuteField.split("-");
|
|
@@ -351,7 +384,7 @@ function spanHours(hours) {
|
|
|
351
384
|
}
|
|
352
385
|
function renderMinuteFrequency(ir, plan, opts) {
|
|
353
386
|
let phrase = stepCycle60(
|
|
354
|
-
stepSegment(ir
|
|
387
|
+
stepSegment(ir, "minute"),
|
|
355
388
|
"minuto",
|
|
356
389
|
"hora",
|
|
357
390
|
opts
|
|
@@ -361,12 +394,12 @@ function renderMinuteFrequency(ir, plan, opts) {
|
|
|
361
394
|
if (cadence) {
|
|
362
395
|
phrase += ", " + cadence;
|
|
363
396
|
} else {
|
|
364
|
-
phrase += singleHourStep(ir.analyses.segments.hour) ? ", " + stepHourSpan(stepSegment(ir
|
|
397
|
+
phrase += singleHourStep(ir.analyses.segments.hour) ? ", " + stepHourSpan(stepSegment(ir, "hour"), opts) : " " + hourSpanFromTimes(ir, plan.hours.times, opts);
|
|
365
398
|
}
|
|
366
399
|
} else if (plan.hours.kind === "window") {
|
|
367
400
|
phrase += " " + hourWindow(plan.hours, opts);
|
|
368
401
|
} else if (plan.hours.kind === "step") {
|
|
369
|
-
phrase += ", " + stepHourSpan(stepSegment(ir
|
|
402
|
+
phrase += ", " + stepHourSpan(stepSegment(ir, "hour"), opts);
|
|
370
403
|
}
|
|
371
404
|
return phrase + trailingQualifier(ir, opts);
|
|
372
405
|
}
|
|
@@ -387,7 +420,7 @@ function renderMinutesAcrossHours(ir, plan, opts) {
|
|
|
387
420
|
return "cada minuto, " + cadence + trailingQualifier(ir, opts);
|
|
388
421
|
}
|
|
389
422
|
if (singleHourStep(ir.analyses.segments.hour)) {
|
|
390
|
-
return "cada minuto, " + stepHourSpan(stepSegment(ir
|
|
423
|
+
return "cada minuto, " + stepHourSpan(stepSegment(ir, "hour"), opts) + trailingQualifier(ir, opts);
|
|
391
424
|
}
|
|
392
425
|
return "cada minuto " + hourSpanFromTimes(ir, plan.times, opts) + trailingQualifier(ir, opts);
|
|
393
426
|
}
|
|
@@ -398,7 +431,7 @@ function renderMinutesAcrossHours(ir, plan, opts) {
|
|
|
398
431
|
return lead + ", " + atHourTimes(ir, plan.times, opts) + trailingQualifier(ir, opts);
|
|
399
432
|
}
|
|
400
433
|
function renderMinuteSpanAcrossHourStep(ir, plan, opts) {
|
|
401
|
-
const segment = stepSegment(ir
|
|
434
|
+
const segment = stepSegment(ir, "hour");
|
|
402
435
|
const cadence = unevenHourCadence(ir, opts);
|
|
403
436
|
if (plan.form === "wildcard") {
|
|
404
437
|
return "cada minuto, " + stepHourSpan(segment, opts) + trailingQualifier(ir, opts);
|
|
@@ -428,7 +461,7 @@ function renderHourStep(ir, plan, opts) {
|
|
|
428
461
|
if (cadence !== null) {
|
|
429
462
|
return cadence + trailingQualifier(ir, opts);
|
|
430
463
|
}
|
|
431
|
-
return stepHours(stepSegment(ir
|
|
464
|
+
return stepHours(stepSegment(ir, "hour"), opts) + trailingQualifier(ir, opts);
|
|
432
465
|
}
|
|
433
466
|
function boundedWindow(plan) {
|
|
434
467
|
const last = plan.minuteForm === "wildcard" ? plan.boundMinute ?? 0 : 0;
|
|
@@ -449,7 +482,7 @@ function unionMonthLeadFull(ir) {
|
|
|
449
482
|
return "";
|
|
450
483
|
}
|
|
451
484
|
const lead = monthPhrase(ir, monthRanged(ir) ? "de " : "en ");
|
|
452
|
-
const segments = flattenSteps(
|
|
485
|
+
const segments = flattenSteps(segmentsOf(ir, "month"));
|
|
453
486
|
const isEnumeration = !monthRanged(ir) && segments.length >= 2;
|
|
454
487
|
return isEnumeration ? lead + "," : lead;
|
|
455
488
|
}
|
|
@@ -462,7 +495,7 @@ function domArm(ir, opts) {
|
|
|
462
495
|
if (isOpenStep(date)) {
|
|
463
496
|
return stepDates(date, opts);
|
|
464
497
|
}
|
|
465
|
-
const segments =
|
|
498
|
+
const segments = segmentsOf(ir, "date");
|
|
466
499
|
if (segments.length === 1 && segments[0].kind === "range") {
|
|
467
500
|
return "del " + segments[0].bounds[0] + " al " + segments[0].bounds[1] + " del mes";
|
|
468
501
|
}
|
|
@@ -476,7 +509,7 @@ function dowArm(ir) {
|
|
|
476
509
|
if (quartz) {
|
|
477
510
|
return quartz;
|
|
478
511
|
}
|
|
479
|
-
const segments = orderWeekdaysForDisplay(
|
|
512
|
+
const segments = orderWeekdaysForDisplay(segmentsOf(ir, "weekday"));
|
|
480
513
|
const allSingles = segments.every(function single(segment) {
|
|
481
514
|
return segment.kind === "single";
|
|
482
515
|
});
|
|
@@ -691,7 +724,7 @@ function renderCompactClockTimes(ir, plan, opts) {
|
|
|
691
724
|
if (cadence2 !== null) {
|
|
692
725
|
return cadence2;
|
|
693
726
|
}
|
|
694
|
-
const ranged =
|
|
727
|
+
const ranged = segmentsOf(ir, "hour").some(function range(segment) {
|
|
695
728
|
return segment.kind === "range";
|
|
696
729
|
});
|
|
697
730
|
if (ranged && !ir.analyses.clockSecond) {
|
|
@@ -758,16 +791,6 @@ function strideFromSegments(segments, unit, anchor, opts) {
|
|
|
758
791
|
const step = values && arithmeticStep(values);
|
|
759
792
|
return step ? renderStride({ ...step, cycle: 60, unit, anchor }, opts) : null;
|
|
760
793
|
}
|
|
761
|
-
function singleValues(segments) {
|
|
762
|
-
const values = [];
|
|
763
|
-
for (const segment of segments) {
|
|
764
|
-
if (segment.kind !== "single") {
|
|
765
|
-
return null;
|
|
766
|
-
}
|
|
767
|
-
values.push(+segment.value);
|
|
768
|
-
}
|
|
769
|
-
return values;
|
|
770
|
-
}
|
|
771
794
|
function stepHours(segment, opts) {
|
|
772
795
|
if (segment.startToken.indexOf("-") !== -1) {
|
|
773
796
|
return groupClockTimesByArticle(atTimes(segment.fires, opts));
|
|
@@ -794,9 +817,6 @@ function hourStrideCadence(stride, opts) {
|
|
|
794
817
|
}
|
|
795
818
|
return cadence + " de " + timePhrase(start, 0, null, opts) + " a " + timePhrase(last, 0, null, opts);
|
|
796
819
|
}
|
|
797
|
-
function offsetCleanStride(stride) {
|
|
798
|
-
return stride.start < stride.interval && 24 % stride.interval === 0;
|
|
799
|
-
}
|
|
800
820
|
function unevenHourCadence(ir, opts) {
|
|
801
821
|
const stride = hourStride(ir);
|
|
802
822
|
if (!stride || offsetCleanStride(stride)) {
|
|
@@ -804,26 +824,8 @@ function unevenHourCadence(ir, opts) {
|
|
|
804
824
|
}
|
|
805
825
|
return hourStrideCadence(stride, opts);
|
|
806
826
|
}
|
|
807
|
-
function hourListStride(values) {
|
|
808
|
-
if (values.length < 2) {
|
|
809
|
-
return null;
|
|
810
|
-
}
|
|
811
|
-
const interval = values[1] - values[0];
|
|
812
|
-
if (interval < 2) {
|
|
813
|
-
return null;
|
|
814
|
-
}
|
|
815
|
-
for (let i = 2; i < values.length; i += 1) {
|
|
816
|
-
if (values[i] - values[i - 1] !== interval) {
|
|
817
|
-
return null;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
if (values[0] !== 0 && values.length < 5) {
|
|
821
|
-
return null;
|
|
822
|
-
}
|
|
823
|
-
return { interval, last: values[values.length - 1], start: values[0] };
|
|
824
|
-
}
|
|
825
827
|
function hourStride(ir) {
|
|
826
|
-
const segments =
|
|
828
|
+
const segments = segmentsOf(ir, "hour");
|
|
827
829
|
if (segments.length === 1 && segments[0].kind === "step") {
|
|
828
830
|
const segment = segments[0];
|
|
829
831
|
if (segment.fires.length < 2) {
|
|
@@ -870,7 +872,7 @@ function hourCadence(ir, minute, opts) {
|
|
|
870
872
|
return hourCadenceLead(ir, minute, opts) + ", " + hourStrideCadence(stride, opts) + trailingQualifier(ir, opts);
|
|
871
873
|
}
|
|
872
874
|
function cleanStrideSegment(ir) {
|
|
873
|
-
const segments =
|
|
875
|
+
const segments = segmentsOf(ir, "hour");
|
|
874
876
|
const segment = segments.length === 1 && segments[0];
|
|
875
877
|
if (!segment || segment.kind !== "step" || segment.startToken.indexOf("-") !== -1) {
|
|
876
878
|
return null;
|
|
@@ -878,7 +880,7 @@ function cleanStrideSegment(ir) {
|
|
|
878
880
|
return segment;
|
|
879
881
|
}
|
|
880
882
|
function hasHourWindow(ir) {
|
|
881
|
-
return
|
|
883
|
+
return segmentsOf(ir, "hour").some(function range(segment) {
|
|
882
884
|
return segment.kind === "range";
|
|
883
885
|
});
|
|
884
886
|
}
|
|
@@ -892,7 +894,7 @@ function hourRangeCadence(ir, minute, opts) {
|
|
|
892
894
|
return hourCadenceLead(ir, minute, opts) + ", " + hourSegmentTimes(ir, 0, null, opts) + trailingQualifier(ir, opts);
|
|
893
895
|
}
|
|
894
896
|
function hourContextTimes(ir, opts) {
|
|
895
|
-
const segments =
|
|
897
|
+
const segments = segmentsOf(ir, "hour");
|
|
896
898
|
const points = [];
|
|
897
899
|
const hasRange = segments.some(function range(segment) {
|
|
898
900
|
return segment.kind === "range";
|
|
@@ -956,7 +958,7 @@ function hourWindowsFromTimes(ir, times, opts) {
|
|
|
956
958
|
return hourAsWindow(hour, opts);
|
|
957
959
|
}));
|
|
958
960
|
}
|
|
959
|
-
return joinList(
|
|
961
|
+
return joinList(segmentsOf(ir, "hour").map(function window(segment) {
|
|
960
962
|
if (segment.kind === "range") {
|
|
961
963
|
return timeRange(
|
|
962
964
|
{ hour: +segment.bounds[0], minute: 0 },
|
|
@@ -975,7 +977,7 @@ function hourWindowsFromTimes(ir, times, opts) {
|
|
|
975
977
|
function hourSegmentTimes(ir, minute, second, opts) {
|
|
976
978
|
const pieces = [];
|
|
977
979
|
const fromRange = [];
|
|
978
|
-
|
|
980
|
+
segmentsOf(ir, "hour").forEach(function clock(segment) {
|
|
979
981
|
if (segment.kind === "step") {
|
|
980
982
|
segment.fires.forEach(function each(hour) {
|
|
981
983
|
pieces.push(atTime(timePhrase(hour, minute, second, opts)));
|
|
@@ -1135,7 +1137,7 @@ function dateClause(ir, monthPart, opts) {
|
|
|
1135
1137
|
if (isOpenStep(pattern.date)) {
|
|
1136
1138
|
return stepDates(pattern.date, opts);
|
|
1137
1139
|
}
|
|
1138
|
-
const segments =
|
|
1140
|
+
const segments = segmentsOf(ir, "date");
|
|
1139
1141
|
if (segments.length === 1 && segments[0].kind === "range") {
|
|
1140
1142
|
return "del " + segments[0].bounds[0] + " al " + segments[0].bounds[1] + monthPart + foldedYear(ir);
|
|
1141
1143
|
}
|
|
@@ -1145,7 +1147,7 @@ function dateClause(ir, monthPart, opts) {
|
|
|
1145
1147
|
return "los d\xEDas " + joinList(segmentWords(segments)) + monthPart + foldedYear(ir);
|
|
1146
1148
|
}
|
|
1147
1149
|
function monthRanged(ir) {
|
|
1148
|
-
return ir.pattern.month !== "*" &&
|
|
1150
|
+
return ir.pattern.month !== "*" && segmentsOf(ir, "month").some(function range(segment) {
|
|
1149
1151
|
return segment.kind === "range";
|
|
1150
1152
|
});
|
|
1151
1153
|
}
|
|
@@ -1195,7 +1197,7 @@ function weekdayQualifier(ir) {
|
|
|
1195
1197
|
if (quartz) {
|
|
1196
1198
|
return quartz;
|
|
1197
1199
|
}
|
|
1198
|
-
const segments = orderWeekdaysForDisplay(
|
|
1200
|
+
const segments = orderWeekdaysForDisplay(segmentsOf(ir, "weekday"));
|
|
1199
1201
|
const allSingles = segments.every(function single(segment) {
|
|
1200
1202
|
return segment.kind === "single";
|
|
1201
1203
|
});
|
|
@@ -1222,7 +1224,7 @@ function flattenSteps(segments) {
|
|
|
1222
1224
|
});
|
|
1223
1225
|
}
|
|
1224
1226
|
function monthPhrase(ir, lead) {
|
|
1225
|
-
const segments = flattenSteps(
|
|
1227
|
+
const segments = flattenSteps(segmentsOf(ir, "month"));
|
|
1226
1228
|
const ranged = segments.some(function range(segment) {
|
|
1227
1229
|
return segment.kind === "range";
|
|
1228
1230
|
});
|
|
@@ -1319,9 +1321,6 @@ function pluralWeekday(token) {
|
|
|
1319
1321
|
function monthName(token) {
|
|
1320
1322
|
return monthNames[+token];
|
|
1321
1323
|
}
|
|
1322
|
-
function isOpenStep(field) {
|
|
1323
|
-
return field.indexOf("/") !== -1 && field.indexOf("-") === -1 && field.indexOf(",") === -1;
|
|
1324
|
-
}
|
|
1325
1324
|
var es2 = {
|
|
1326
1325
|
describe,
|
|
1327
1326
|
fallback: "un patr\xF3n cron irreconocible",
|
package/dist/lang/fi.cjs
CHANGED
|
@@ -95,6 +95,48 @@ function orderWeekdaysForDisplay(segments) {
|
|
|
95
95
|
function toFieldNumber(token, numberMap) {
|
|
96
96
|
return isNonNegativeInteger(token) ? +token : numberMap[token.toUpperCase()];
|
|
97
97
|
}
|
|
98
|
+
function segmentsOf(ir, field) {
|
|
99
|
+
return ir.analyses.segments[field] ?? [];
|
|
100
|
+
}
|
|
101
|
+
function stepSegment(ir, field) {
|
|
102
|
+
return segmentsOf(ir, field)[0];
|
|
103
|
+
}
|
|
104
|
+
function singleValues(segments) {
|
|
105
|
+
const values = [];
|
|
106
|
+
for (const segment of segments) {
|
|
107
|
+
if (segment.kind !== "single") {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
values.push(+segment.value);
|
|
111
|
+
}
|
|
112
|
+
return values;
|
|
113
|
+
}
|
|
114
|
+
function offsetCleanStride(stride) {
|
|
115
|
+
return stride.start < stride.interval && 24 % stride.interval === 0;
|
|
116
|
+
}
|
|
117
|
+
function hourListStride(values) {
|
|
118
|
+
if (values.length < 2) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const interval = values[1] - values[0];
|
|
122
|
+
if (interval < 2) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
for (let i = 2; i < values.length; i += 1) {
|
|
126
|
+
if (values[i] - values[i - 1] !== interval) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (values[0] !== 0 && values.length < 5) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return { interval, last: values[values.length - 1], start: values[0] };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/core/shapes.ts
|
|
137
|
+
function isOpenStep(field) {
|
|
138
|
+
return field.indexOf("/") !== -1 && field.indexOf("-") === -1 && field.indexOf(",") === -1;
|
|
139
|
+
}
|
|
98
140
|
|
|
99
141
|
// src/lang/fi/dialects.ts
|
|
100
142
|
var dialects = {
|
|
@@ -113,9 +155,6 @@ function resolveDialect(dialect) {
|
|
|
113
155
|
}
|
|
114
156
|
|
|
115
157
|
// src/lang/fi/index.ts
|
|
116
|
-
function stepSegment(segments) {
|
|
117
|
-
return segments[0];
|
|
118
|
-
}
|
|
119
158
|
var genitives = [
|
|
120
159
|
null,
|
|
121
160
|
"yhden",
|
|
@@ -291,7 +330,7 @@ function renderSecondsWithinMinute(ir, plan, opts) {
|
|
|
291
330
|
return secondsLeadClause(ir, opts) + ", " + atMarks(minuteField, units.minute, true) + trailingQualifier(ir, opts);
|
|
292
331
|
}
|
|
293
332
|
function composeSecondsOverMinuteStep(ir, freq, opts) {
|
|
294
|
-
const seg = stepSegment(ir
|
|
333
|
+
const seg = stepSegment(ir, "minute");
|
|
295
334
|
const stepPhrase = stepCycle60(seg, units.minute, opts);
|
|
296
335
|
if (freq.hours.kind === "during" && minuteStepIsAnchored(seg)) {
|
|
297
336
|
const bareHours = kloFromTimes(ir, freq.hours.times, opts);
|
|
@@ -303,7 +342,7 @@ function composeSecondsOverMinuteStep(ir, freq, opts) {
|
|
|
303
342
|
} else if (freq.hours.kind === "window") {
|
|
304
343
|
hourClause = " " + hourWindow(freq.hours, opts);
|
|
305
344
|
} else if (freq.hours.kind === "step") {
|
|
306
|
-
hourClause = " " + everyNthHour(stepSegment(ir
|
|
345
|
+
hourClause = " " + everyNthHour(stepSegment(ir, "hour"), opts);
|
|
307
346
|
}
|
|
308
347
|
return stepPhrase + ", " + secondsLeadClause(ir, opts) + hourClause + trailingQualifier(ir, opts);
|
|
309
348
|
}
|
|
@@ -337,7 +376,7 @@ function isEveryOtherMinuteSeconds(ir, plan) {
|
|
|
337
376
|
if (plan.rest.kind !== "minuteFrequency" || ir.pattern.second !== "*" || ir.shapes.hour !== "wildcard") {
|
|
338
377
|
return false;
|
|
339
378
|
}
|
|
340
|
-
const seg = stepSegment(ir
|
|
379
|
+
const seg = stepSegment(ir, "minute");
|
|
341
380
|
return seg.startToken === "*" && seg.interval === 2;
|
|
342
381
|
}
|
|
343
382
|
function composeMinuteZero(ir, rest, opts) {
|
|
@@ -359,7 +398,7 @@ function secondsLeadClause(ir, opts) {
|
|
|
359
398
|
}
|
|
360
399
|
if (shape === "step") {
|
|
361
400
|
return stepCycle60(
|
|
362
|
-
stepSegment(ir
|
|
401
|
+
stepSegment(ir, "second"),
|
|
363
402
|
units.second,
|
|
364
403
|
opts
|
|
365
404
|
);
|
|
@@ -368,8 +407,8 @@ function secondsLeadClause(ir, opts) {
|
|
|
368
407
|
if (shape === "single") {
|
|
369
408
|
return atMarks(secondField, units.second, marked);
|
|
370
409
|
}
|
|
371
|
-
return strideFromSegments(ir
|
|
372
|
-
joinList(segmentWords(ir
|
|
410
|
+
return strideFromSegments(segmentsOf(ir, "second"), units.second, opts) ?? atMarks(
|
|
411
|
+
joinList(segmentWords(segmentsOf(ir, "second"))),
|
|
373
412
|
units.second,
|
|
374
413
|
marked
|
|
375
414
|
);
|
|
@@ -387,15 +426,15 @@ function renderMultipleMinutes(ir, plan, opts) {
|
|
|
387
426
|
return minutesList(ir, opts) + trailingQualifier(ir, opts);
|
|
388
427
|
}
|
|
389
428
|
function minutesList(ir, opts) {
|
|
390
|
-
return strideFromSegments(ir
|
|
391
|
-
joinList(segmentWords(ir
|
|
429
|
+
return strideFromSegments(segmentsOf(ir, "minute"), units.minute, opts) ?? atMarks(
|
|
430
|
+
joinList(segmentWords(segmentsOf(ir, "minute"))),
|
|
392
431
|
units.minute,
|
|
393
432
|
true
|
|
394
433
|
);
|
|
395
434
|
}
|
|
396
435
|
function bareMinutes(ir, opts) {
|
|
397
|
-
return strideFromSegments(ir
|
|
398
|
-
joinList(segmentWords(ir
|
|
436
|
+
return strideFromSegments(segmentsOf(ir, "minute"), units.minute, opts) ?? atMarks(
|
|
437
|
+
joinList(segmentWords(segmentsOf(ir, "minute"))),
|
|
399
438
|
units.minute,
|
|
400
439
|
false
|
|
401
440
|
);
|
|
@@ -426,15 +465,15 @@ function hoursAreRangeIsolated(segments) {
|
|
|
426
465
|
return hasRange && hasSingle;
|
|
427
466
|
}
|
|
428
467
|
function hoursFirstMinutes(hoursStr, ir, opts) {
|
|
429
|
-
const stride = strideFromSegments(ir
|
|
468
|
+
const stride = strideFromSegments(segmentsOf(ir, "minute"), units.minute, opts);
|
|
430
469
|
if (stride) {
|
|
431
470
|
return hoursStr + " aina " + stride;
|
|
432
471
|
}
|
|
433
|
-
return hoursStr + " aina minuuttien " + joinList(segmentWords(ir
|
|
472
|
+
return hoursStr + " aina minuuttien " + joinList(segmentWords(segmentsOf(ir, "minute"))) + " kohdalla";
|
|
434
473
|
}
|
|
435
474
|
function hourSegmentTimesWithSeka(ir, minute, second, opts) {
|
|
436
475
|
const pieces = [];
|
|
437
|
-
ir
|
|
476
|
+
segmentsOf(ir, "hour").forEach(function clock(segment) {
|
|
438
477
|
if (segment.kind === "range") {
|
|
439
478
|
pieces.push(rangeDigits(
|
|
440
479
|
{ hour: +segment.bounds[0], minute, second },
|
|
@@ -448,7 +487,7 @@ function hourSegmentTimesWithSeka(ir, minute, second, opts) {
|
|
|
448
487
|
return "klo " + pieces.slice(0, -1).join(", ") + " sek\xE4 klo " + pieces[pieces.length - 1];
|
|
449
488
|
}
|
|
450
489
|
function renderMinuteFrequency(ir, plan, opts) {
|
|
451
|
-
const seg = stepSegment(ir
|
|
490
|
+
const seg = stepSegment(ir, "minute");
|
|
452
491
|
if (plan.hours.kind === "during") {
|
|
453
492
|
const cadence = unevenHourCadence(ir, opts);
|
|
454
493
|
if (cadence !== null) {
|
|
@@ -464,7 +503,7 @@ function renderMinuteFrequency(ir, plan, opts) {
|
|
|
464
503
|
if (plan.hours.kind === "window") {
|
|
465
504
|
phrase += " " + hourWindow(plan.hours, opts);
|
|
466
505
|
} else if (plan.hours.kind === "step") {
|
|
467
|
-
phrase += " " + everyNthHour(stepSegment(ir
|
|
506
|
+
phrase += " " + everyNthHour(stepSegment(ir, "hour"), opts);
|
|
468
507
|
}
|
|
469
508
|
return phrase + trailingQualifier(ir, opts);
|
|
470
509
|
}
|
|
@@ -486,14 +525,14 @@ function renderMinutesAcrossHours(ir, plan, opts) {
|
|
|
486
525
|
if (cadence !== null) {
|
|
487
526
|
return bareMinutes(ir, opts) + ", " + cadence + trailingQualifier(ir, opts);
|
|
488
527
|
}
|
|
489
|
-
if (hoursAreRangeIsolated(ir
|
|
528
|
+
if (hoursAreRangeIsolated(segmentsOf(ir, "hour"))) {
|
|
490
529
|
return bareMinutes(ir, opts) + " " + hourSegmentTimesWithSeka(ir, 0, null, opts) + trailingQualifier(ir, opts);
|
|
491
530
|
}
|
|
492
531
|
const hoursStr = kloFromTimes(ir, plan.times, opts);
|
|
493
532
|
return hoursFirstMinutes(hoursStr, ir, opts) + trailingQualifier(ir, opts);
|
|
494
533
|
}
|
|
495
534
|
function renderMinuteSpanAcrossHourStep(ir, plan, opts) {
|
|
496
|
-
const segment = stepSegment(ir
|
|
535
|
+
const segment = stepSegment(ir, "hour");
|
|
497
536
|
const cadence = unevenHourCadence(ir, opts);
|
|
498
537
|
if (plan.form === "wildcard") {
|
|
499
538
|
return "joka minuutti " + everyNthHour(segment, opts) + trailingQualifier(ir, opts);
|
|
@@ -578,7 +617,7 @@ function renderHourStep(ir, plan, opts) {
|
|
|
578
617
|
if (cadence !== null) {
|
|
579
618
|
return cadence + trailingQualifier(ir, opts);
|
|
580
619
|
}
|
|
581
|
-
return stepHours(stepSegment(ir
|
|
620
|
+
return stepHours(stepSegment(ir, "hour"), opts) + trailingQualifier(ir, opts);
|
|
582
621
|
}
|
|
583
622
|
function boundedWindow(plan) {
|
|
584
623
|
return { from: plan.from, last: plan.boundMinute ?? 0, to: plan.to };
|
|
@@ -614,7 +653,7 @@ function renderCompactClockTimes(ir, plan, opts) {
|
|
|
614
653
|
return cadence2;
|
|
615
654
|
}
|
|
616
655
|
}
|
|
617
|
-
const hourSegs = ir
|
|
656
|
+
const hourSegs = segmentsOf(ir, "hour");
|
|
618
657
|
if (hoursAreRangeIsolated(hourSegs)) {
|
|
619
658
|
if (plan.fold) {
|
|
620
659
|
return leadingQualifier(ir, opts) + hourSegmentTimesWithSeka(
|
|
@@ -675,16 +714,6 @@ function strideFromSegments(segments, unit, opts) {
|
|
|
675
714
|
const step = values && arithmeticStep(values);
|
|
676
715
|
return step ? renderStride({ ...step, cycle: 60, unit }, opts) : null;
|
|
677
716
|
}
|
|
678
|
-
function singleValues(segments) {
|
|
679
|
-
const values = [];
|
|
680
|
-
for (const segment of segments) {
|
|
681
|
-
if (segment.kind !== "single") {
|
|
682
|
-
return null;
|
|
683
|
-
}
|
|
684
|
-
values.push(+segment.value);
|
|
685
|
-
}
|
|
686
|
-
return values;
|
|
687
|
-
}
|
|
688
717
|
function stepCycle60(segment, unit, opts) {
|
|
689
718
|
if (segment.startToken.indexOf("-") !== -1) {
|
|
690
719
|
return atMarks(joinList(wordList(segment.fires)), unit, true);
|
|
@@ -728,27 +757,6 @@ function hourStrideCadence(stride, opts) {
|
|
|
728
757
|
}
|
|
729
758
|
return cadence + " " + kloRange({ hour: start, minute: 0 }, { hour: last, minute: 0 }, opts);
|
|
730
759
|
}
|
|
731
|
-
function hourListStride(values) {
|
|
732
|
-
if (values.length < 2) {
|
|
733
|
-
return null;
|
|
734
|
-
}
|
|
735
|
-
const interval = values[1] - values[0];
|
|
736
|
-
if (interval < 2) {
|
|
737
|
-
return null;
|
|
738
|
-
}
|
|
739
|
-
for (let i = 2; i < values.length; i += 1) {
|
|
740
|
-
if (values[i] - values[i - 1] !== interval) {
|
|
741
|
-
return null;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
if (values[0] !== 0 && values.length < 5) {
|
|
745
|
-
return null;
|
|
746
|
-
}
|
|
747
|
-
return { interval, last: values[values.length - 1], start: values[0] };
|
|
748
|
-
}
|
|
749
|
-
function offsetCleanStride(stride) {
|
|
750
|
-
return stride.start < stride.interval && 24 % stride.interval === 0;
|
|
751
|
-
}
|
|
752
760
|
function hourStride(ir) {
|
|
753
761
|
const segments = ir.analyses.segments.hour;
|
|
754
762
|
if (!segments) {
|
|
@@ -797,8 +805,8 @@ function hourCadence(ir, minute, opts) {
|
|
|
797
805
|
if (ir.pattern.second === "0" && fires <= maxClockTimes && offsetCleanStride(stride)) {
|
|
798
806
|
return null;
|
|
799
807
|
}
|
|
800
|
-
const segment = ir
|
|
801
|
-
const confined = minute === 0 && subMinuteSecond(ir) && ir
|
|
808
|
+
const segment = segmentsOf(ir, "hour")[0];
|
|
809
|
+
const confined = minute === 0 && subMinuteSecond(ir) && segmentsOf(ir, "hour").length === 1 && segment.kind === "step" && cleanHourStride(segment);
|
|
802
810
|
if (confined) {
|
|
803
811
|
return secondsLeadClause(ir, opts) + " minuutin ajan " + everyNthHour(segment, opts) + trailingQualifier(ir, opts);
|
|
804
812
|
}
|
|
@@ -821,7 +829,7 @@ function hasHourWindow(ir) {
|
|
|
821
829
|
});
|
|
822
830
|
}
|
|
823
831
|
function hourRangeWindowTail(ir, opts) {
|
|
824
|
-
return ir
|
|
832
|
+
return segmentsOf(ir, "hour").length === 1 ? hourSegmentTimes(ir, 0, null, opts) : hourSegmentTimesWithSeka(ir, 0, null, opts);
|
|
825
833
|
}
|
|
826
834
|
function hourRangeCadence(ir, minute, opts) {
|
|
827
835
|
if (minute !== 0 || !hasHourWindow(ir) || ir.pattern.second === "0") {
|
|
@@ -849,7 +857,7 @@ function hourWindowsFromTimes(ir, times, opts) {
|
|
|
849
857
|
if (times.kind === "fires") {
|
|
850
858
|
return kloList(times.fires, opts);
|
|
851
859
|
}
|
|
852
|
-
const segments = ir
|
|
860
|
+
const segments = segmentsOf(ir, "hour");
|
|
853
861
|
if (!segments.some(function ranged(segment) {
|
|
854
862
|
return segment.kind === "range";
|
|
855
863
|
})) {
|
|
@@ -889,7 +897,7 @@ function hourWindowDigits(hour, opts) {
|
|
|
889
897
|
}
|
|
890
898
|
function hourSegmentTimes(ir, minute, second, opts) {
|
|
891
899
|
const pieces = [];
|
|
892
|
-
ir
|
|
900
|
+
segmentsOf(ir, "hour").forEach(function clock(segment) {
|
|
893
901
|
if (segment.kind === "step") {
|
|
894
902
|
pieces.push(...segment.fires.map(function each(hour) {
|
|
895
903
|
return timeDigits(hour, minute, second, opts);
|
|
@@ -985,7 +993,7 @@ function weekdayQualifier(ir) {
|
|
|
985
993
|
if (quartz) {
|
|
986
994
|
return quartz;
|
|
987
995
|
}
|
|
988
|
-
const segments = orderWeekdaysForDisplay(ir
|
|
996
|
+
const segments = orderWeekdaysForDisplay(segmentsOf(ir, "weekday"));
|
|
989
997
|
return joinList(segments.map(function piece(segment) {
|
|
990
998
|
if (segment.kind === "range") {
|
|
991
999
|
return weekdays[weekdayNumber(segment.bounds[0])].ela + " " + weekdays[weekdayNumber(segment.bounds[1])].ill;
|
|
@@ -994,7 +1002,7 @@ function weekdayQualifier(ir) {
|
|
|
994
1002
|
}));
|
|
995
1003
|
}
|
|
996
1004
|
function monthPhrase(ir) {
|
|
997
|
-
const segments = flattenSteps(ir
|
|
1005
|
+
const segments = flattenSteps(segmentsOf(ir, "month"));
|
|
998
1006
|
return joinList(segments.map(function piece(segment) {
|
|
999
1007
|
if (segment.kind === "range") {
|
|
1000
1008
|
return monthStems[monthNumber(segment.bounds[0])] + "kuusta " + monthStems[monthNumber(segment.bounds[1])] + "kuuhun";
|
|
@@ -1044,7 +1052,7 @@ function monthAnchor(ir, opts) {
|
|
|
1044
1052
|
if (isOpenStep(monthField)) {
|
|
1045
1053
|
return stepMonths(monthField, opts);
|
|
1046
1054
|
}
|
|
1047
|
-
const segments = flattenSteps(ir
|
|
1055
|
+
const segments = flattenSteps(segmentsOf(ir, "month"));
|
|
1048
1056
|
return joinList(segments.map(function genitiveOf(segment) {
|
|
1049
1057
|
const single = segment;
|
|
1050
1058
|
return monthStems[monthNumber(single.value)] + "kuun";
|
|
@@ -1054,12 +1062,12 @@ function rangedMonthScope(ir) {
|
|
|
1054
1062
|
return monthRanged(ir) ? " " + monthPhrase(ir) : "";
|
|
1055
1063
|
}
|
|
1056
1064
|
function monthRanged(ir) {
|
|
1057
|
-
return ir.pattern.month !== "*" && ir
|
|
1065
|
+
return ir.pattern.month !== "*" && segmentsOf(ir, "month").some(function range(segment) {
|
|
1058
1066
|
return segment.kind === "range";
|
|
1059
1067
|
});
|
|
1060
1068
|
}
|
|
1061
1069
|
function dateWords(ir) {
|
|
1062
|
-
return joinList(ir
|
|
1070
|
+
return joinList(segmentsOf(ir, "date").flatMap(
|
|
1063
1071
|
function word(segment) {
|
|
1064
1072
|
if (segment.kind === "range") {
|
|
1065
1073
|
return [segment.bounds[0] + ".\u2013" + segment.bounds[1] + "."];
|
|
@@ -1161,9 +1169,6 @@ function segmentWords(segments) {
|
|
|
1161
1169
|
return [segment.value];
|
|
1162
1170
|
});
|
|
1163
1171
|
}
|
|
1164
|
-
function isOpenStep(field) {
|
|
1165
|
-
return field.indexOf("/") !== -1 && field.indexOf("-") === -1 && field.indexOf(",") === -1;
|
|
1166
|
-
}
|
|
1167
1172
|
function wordList(fires) {
|
|
1168
1173
|
return fires.map(function digit(value) {
|
|
1169
1174
|
return "" + value;
|