@ultimat3/time 1.0.0 → 1.1.0
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/package.json +2 -2
- package/src/business.d.ts +0 -37
- package/src/business.d.ts.map +0 -1
- package/src/business.js +0 -68
- package/src/business.js.map +0 -1
- package/src/context.d.ts +0 -40
- package/src/context.d.ts.map +0 -1
- package/src/context.js +0 -61
- package/src/context.js.map +0 -1
- package/src/cron.d.ts +0 -60
- package/src/cron.d.ts.map +0 -1
- package/src/cron.js +0 -390
- package/src/cron.js.map +0 -1
- package/src/duration.d.ts +0 -32
- package/src/duration.d.ts.map +0 -1
- package/src/duration.js +0 -134
- package/src/duration.js.map +0 -1
- package/src/errors.d.ts +0 -26
- package/src/errors.d.ts.map +0 -1
- package/src/errors.js +0 -78
- package/src/errors.js.map +0 -1
- package/src/format.d.ts +0 -54
- package/src/format.d.ts.map +0 -1
- package/src/format.js +0 -133
- package/src/format.js.map +0 -1
- package/src/index.d.ts +0 -12
- package/src/index.d.ts.map +0 -1
- package/src/index.js +0 -12
- package/src/index.js.map +0 -1
- package/src/instant.d.ts +0 -38
- package/src/instant.d.ts.map +0 -1
- package/src/instant.js +0 -76
- package/src/instant.js.map +0 -1
- package/src/schedule.d.ts +0 -24
- package/src/schedule.d.ts.map +0 -1
- package/src/schedule.js +0 -67
- package/src/schedule.js.map +0 -1
- package/src/zoned.d.ts +0 -80
- package/src/zoned.d.ts.map +0 -1
- package/src/zoned.js +0 -146
- package/src/zoned.js.map +0 -1
- package/src/zones.d.ts +0 -40
- package/src/zones.d.ts.map +0 -1
- package/src/zones.js +0 -116
- package/src/zones.js.map +0 -1
package/src/cron.js
DELETED
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A real cron parser and occurrence calculator. Timezone-aware through `fromZoned`, so
|
|
3
|
-
* `0 3 * * *` in `Europe/Berlin` fires at 03:00 local on both sides of a DST change
|
|
4
|
-
* instead of drifting to 02:00 or 04:00 for half the year.
|
|
5
|
-
*/
|
|
6
|
-
import { cronInvalid } from './errors';
|
|
7
|
-
import { fromEpochMs } from './instant';
|
|
8
|
-
import { fromZoned, toZoned } from './zoned';
|
|
9
|
-
import { assertTimeZone } from './zones';
|
|
10
|
-
const MACROS = {
|
|
11
|
-
'@yearly': '0 0 1 1 *',
|
|
12
|
-
'@annually': '0 0 1 1 *',
|
|
13
|
-
'@monthly': '0 0 1 * *',
|
|
14
|
-
'@weekly': '0 0 * * 0',
|
|
15
|
-
'@daily': '0 0 * * *',
|
|
16
|
-
'@midnight': '0 0 * * *',
|
|
17
|
-
'@hourly': '0 * * * *',
|
|
18
|
-
};
|
|
19
|
-
const MONTH_NAMES = [
|
|
20
|
-
'jan',
|
|
21
|
-
'feb',
|
|
22
|
-
'mar',
|
|
23
|
-
'apr',
|
|
24
|
-
'may',
|
|
25
|
-
'jun',
|
|
26
|
-
'jul',
|
|
27
|
-
'aug',
|
|
28
|
-
'sep',
|
|
29
|
-
'oct',
|
|
30
|
-
'nov',
|
|
31
|
-
'dec',
|
|
32
|
-
];
|
|
33
|
-
const DAY_NAMES = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
34
|
-
/** Parse 5 fields (`m h dom mon dow`) or 6 with a leading seconds field. */
|
|
35
|
-
export function parseCron(expression) {
|
|
36
|
-
const trimmed = expression.trim().toLowerCase();
|
|
37
|
-
const expanded = MACROS[trimmed] ?? trimmed;
|
|
38
|
-
const fields = expanded.split(/\s+/).filter((field) => field !== '');
|
|
39
|
-
if (fields.length !== 5 && fields.length !== 6) {
|
|
40
|
-
throw cronInvalid(expression, `expected 5 or 6 fields, got ${fields.length}`);
|
|
41
|
-
}
|
|
42
|
-
const withSeconds = fields.length === 6;
|
|
43
|
-
const [secondField, minuteField, hourField, domField, monthField, dowField] = withSeconds
|
|
44
|
-
? fields
|
|
45
|
-
: ['0', ...fields];
|
|
46
|
-
const seconds = parseField(expression, secondField ?? '0', 0, 59);
|
|
47
|
-
const minutes = parseField(expression, minuteField ?? '*', 0, 59);
|
|
48
|
-
const hours = parseField(expression, hourField ?? '*', 0, 23);
|
|
49
|
-
const daysOfMonth = parseField(expression, domField ?? '*', 1, 31);
|
|
50
|
-
const months = parseField(expression, monthField ?? '*', 1, 12, MONTH_NAMES, 1);
|
|
51
|
-
const rawDow = parseField(expression, dowField ?? '*', 0, 7, DAY_NAMES, 0);
|
|
52
|
-
// 0 and 7 are both Sunday in cron; ISO calls Sunday 7.
|
|
53
|
-
const daysOfWeek = [...new Set(rawDow.map((day) => (day === 0 ? 7 : day)))].sort((a, b) => a - b);
|
|
54
|
-
return {
|
|
55
|
-
source: expanded,
|
|
56
|
-
seconds,
|
|
57
|
-
minutes,
|
|
58
|
-
hours,
|
|
59
|
-
daysOfMonth,
|
|
60
|
-
months,
|
|
61
|
-
daysOfWeek,
|
|
62
|
-
dayOfMonthRestricted: isRestricted(domField ?? '*'),
|
|
63
|
-
dayOfWeekRestricted: isRestricted(dowField ?? '*'),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
export function isValidCron(expression) {
|
|
67
|
-
try {
|
|
68
|
-
parseCron(expression);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/** True when `at` matches the expression in `zone`, to the second. */
|
|
76
|
-
export function matchesCron(expression, at, zone) {
|
|
77
|
-
const cron = parseCronOnce(expression);
|
|
78
|
-
const zoned = toZoned(at, zone);
|
|
79
|
-
return (cron.seconds.includes(zoned.second) &&
|
|
80
|
-
cron.minutes.includes(zoned.minute) &&
|
|
81
|
-
cron.hours.includes(zoned.hour) &&
|
|
82
|
-
cron.months.includes(zoned.month) &&
|
|
83
|
-
matchesDay(cron, zoned.day, zoned.weekday));
|
|
84
|
-
}
|
|
85
|
-
/** Iteration guard: ~4 years of minute-level field advancement. */
|
|
86
|
-
const MAX_STEPS = 200_000;
|
|
87
|
-
/**
|
|
88
|
-
* The next instant strictly after `after` that matches, computed on the zone's wall clock
|
|
89
|
-
* and converted with `fromZoned({ gap: 'next', overlap: 'first' })`:
|
|
90
|
-
* - spring forward: a 02:30 daily job runs once, at the first existing local time after
|
|
91
|
-
* the gap, instead of being silently skipped;
|
|
92
|
-
* - fall back: a repeated local time runs once, on its first occurrence.
|
|
93
|
-
*/
|
|
94
|
-
export function nextCronOccurrence(expression, zone, after) {
|
|
95
|
-
const cron = parseCronOnce(expression);
|
|
96
|
-
assertTimeZone(zone);
|
|
97
|
-
const start = toZoned(after, zone);
|
|
98
|
-
const cursor = {
|
|
99
|
-
year: start.year,
|
|
100
|
-
month: start.month,
|
|
101
|
-
day: start.day,
|
|
102
|
-
hour: start.hour,
|
|
103
|
-
minute: start.minute,
|
|
104
|
-
second: start.second + 1,
|
|
105
|
-
};
|
|
106
|
-
carry(cursor);
|
|
107
|
-
for (let step = 0; step < MAX_STEPS; step += 1) {
|
|
108
|
-
if (!cron.months.includes(cursor.month)) {
|
|
109
|
-
cursor.month += 1;
|
|
110
|
-
cursor.day = 1;
|
|
111
|
-
resetTime(cursor);
|
|
112
|
-
carry(cursor);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (cursor.day > daysInMonth(cursor.year, cursor.month)) {
|
|
116
|
-
cursor.month += 1;
|
|
117
|
-
cursor.day = 1;
|
|
118
|
-
resetTime(cursor);
|
|
119
|
-
carry(cursor);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (!matchesDay(cron, cursor.day, isoWeekday(cursor))) {
|
|
123
|
-
cursor.day += 1;
|
|
124
|
-
resetTime(cursor);
|
|
125
|
-
carry(cursor);
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (!cron.hours.includes(cursor.hour)) {
|
|
129
|
-
cursor.hour += 1;
|
|
130
|
-
cursor.minute = 0;
|
|
131
|
-
cursor.second = 0;
|
|
132
|
-
carry(cursor);
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
if (!cron.minutes.includes(cursor.minute)) {
|
|
136
|
-
cursor.minute += 1;
|
|
137
|
-
cursor.second = 0;
|
|
138
|
-
carry(cursor);
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
if (!cron.seconds.includes(cursor.second)) {
|
|
142
|
-
cursor.second += 1;
|
|
143
|
-
carry(cursor);
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
const candidate = fromZoned({ ...cursor }, zone, { gap: 'next', overlap: 'first' });
|
|
147
|
-
if (candidate.getTime() > after.getTime())
|
|
148
|
-
return candidate;
|
|
149
|
-
// The DST gap can push a candidate onto an instant we have already passed; step on.
|
|
150
|
-
cursor.second += 1;
|
|
151
|
-
carry(cursor);
|
|
152
|
-
}
|
|
153
|
-
throw cronInvalid(typeof expression === 'string' ? expression : cron.source, 'no occurrence within the next ~4 years — the date fields can never all match (e.g. "0 0 30 2 *")');
|
|
154
|
-
}
|
|
155
|
-
/** The next `count` occurrences, each strictly after the previous one. */
|
|
156
|
-
export function nextCronOccurrences(expression, zone, after, count) {
|
|
157
|
-
const cron = parseCronOnce(expression);
|
|
158
|
-
const results = [];
|
|
159
|
-
let cursor = after;
|
|
160
|
-
for (let index = 0; index < count; index += 1) {
|
|
161
|
-
cursor = nextCronOccurrence(cron, zone, cursor);
|
|
162
|
-
results.push(cursor);
|
|
163
|
-
}
|
|
164
|
-
return results;
|
|
165
|
-
}
|
|
166
|
-
/** English defaults; the admin dashboard passes `t('time.cron.*')` instead. */
|
|
167
|
-
export const DEFAULT_CRON_PHRASES = {
|
|
168
|
-
everyMinute: 'every minute',
|
|
169
|
-
everyNMinutes: 'every {n} minutes',
|
|
170
|
-
everyHour: 'every hour',
|
|
171
|
-
everyNHours: 'every {n} hours',
|
|
172
|
-
at: 'at {time}',
|
|
173
|
-
onDaysOfMonth: 'on day {days}',
|
|
174
|
-
onWeekdays: 'on {days}',
|
|
175
|
-
inMonths: 'in {months}',
|
|
176
|
-
everyDay: 'every day',
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* `describeCron('0 3 * * MON-FRI', 'en')` → `at 03:00 on Monday–Friday`.
|
|
180
|
-
* Month and weekday names come from `Intl`; the connective phrases are injected so this
|
|
181
|
-
* package never hardcodes a user-facing English string.
|
|
182
|
-
*/
|
|
183
|
-
export function describeCron(expression, locale, phrases = {}) {
|
|
184
|
-
const cron = parseCronOnce(expression);
|
|
185
|
-
const words = { ...DEFAULT_CRON_PHRASES, ...phrases };
|
|
186
|
-
const list = new Intl.ListFormat(locale, { style: 'long', type: 'conjunction' });
|
|
187
|
-
const segments = [];
|
|
188
|
-
const minuteStep = uniformStep(cron.minutes, 60);
|
|
189
|
-
const hourStep = uniformStep(cron.hours, 24);
|
|
190
|
-
// Only a fixed clock time reads as "at 03:00 every day"; an interval already says it.
|
|
191
|
-
let explicitTime = false;
|
|
192
|
-
if (cron.minutes.length === 60 && cron.hours.length === 24) {
|
|
193
|
-
segments.push(words.everyMinute);
|
|
194
|
-
}
|
|
195
|
-
else if (minuteStep !== undefined && cron.hours.length === 24) {
|
|
196
|
-
segments.push(fill(words.everyNMinutes, { n: minuteStep }));
|
|
197
|
-
}
|
|
198
|
-
else if (cron.minutes.length === 1 && hourStep !== undefined) {
|
|
199
|
-
segments.push(fill(words.everyNHours, { n: hourStep }));
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
explicitTime = true;
|
|
203
|
-
const times = cron.hours.flatMap((hour) => cron.minutes.map((minute) => `${pad2(hour)}:${pad2(minute)}`));
|
|
204
|
-
segments.push(fill(words.at, { time: list.format(times.slice(0, 6)) }));
|
|
205
|
-
}
|
|
206
|
-
if (cron.dayOfMonthRestricted) {
|
|
207
|
-
const days = list.format(cron.daysOfMonth.map(String));
|
|
208
|
-
segments.push(fill(words.onDaysOfMonth, { days }));
|
|
209
|
-
}
|
|
210
|
-
if (cron.dayOfWeekRestricted) {
|
|
211
|
-
const days = list.format(cron.daysOfWeek.map((day) => weekdayName(day, locale)));
|
|
212
|
-
segments.push(fill(words.onWeekdays, { days }));
|
|
213
|
-
}
|
|
214
|
-
if (cron.months.length < 12) {
|
|
215
|
-
const months = list.format(cron.months.map((month) => monthName(month, locale)));
|
|
216
|
-
segments.push(fill(words.inMonths, { months }));
|
|
217
|
-
}
|
|
218
|
-
if (explicitTime && segments.length === 1)
|
|
219
|
-
segments.push(words.everyDay);
|
|
220
|
-
return segments.join(' ');
|
|
221
|
-
}
|
|
222
|
-
function parseCronOnce(expression) {
|
|
223
|
-
return typeof expression === 'string' ? parseCron(expression) : expression;
|
|
224
|
-
}
|
|
225
|
-
function matchesDay(cron, day, weekday) {
|
|
226
|
-
const domHit = cron.daysOfMonth.includes(day);
|
|
227
|
-
const dowHit = cron.daysOfWeek.includes(weekday);
|
|
228
|
-
if (cron.dayOfMonthRestricted && cron.dayOfWeekRestricted)
|
|
229
|
-
return domHit || dowHit;
|
|
230
|
-
if (cron.dayOfMonthRestricted)
|
|
231
|
-
return domHit;
|
|
232
|
-
if (cron.dayOfWeekRestricted)
|
|
233
|
-
return dowHit;
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
function parseField(expression, field, min, max, names = [], nameOffset = 0) {
|
|
237
|
-
const values = new Set();
|
|
238
|
-
for (const part of field.split(',')) {
|
|
239
|
-
if (part === '')
|
|
240
|
-
throw cronInvalid(expression, `empty list item in "${field}"`);
|
|
241
|
-
const [rangePart, stepPart] = part.split('/');
|
|
242
|
-
if (rangePart === undefined || (part.includes('/') && stepPart === undefined)) {
|
|
243
|
-
throw cronInvalid(expression, `malformed step in "${part}"`);
|
|
244
|
-
}
|
|
245
|
-
const step = stepPart === undefined ? 1 : Number.parseInt(stepPart, 10);
|
|
246
|
-
if (!Number.isInteger(step) || step < 1) {
|
|
247
|
-
throw cronInvalid(expression, `step must be a positive integer in "${part}"`);
|
|
248
|
-
}
|
|
249
|
-
let from;
|
|
250
|
-
let to;
|
|
251
|
-
if (isWildcard(rangePart)) {
|
|
252
|
-
from = min;
|
|
253
|
-
to = max;
|
|
254
|
-
}
|
|
255
|
-
else if (rangePart.includes('-')) {
|
|
256
|
-
const [left, right] = rangePart.split('-');
|
|
257
|
-
from = toNumber(expression, left, min, max, names, nameOffset);
|
|
258
|
-
to = toNumber(expression, right, min, max, names, nameOffset);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
from = toNumber(expression, rangePart, min, max, names, nameOffset);
|
|
262
|
-
to = stepPart === undefined ? from : max;
|
|
263
|
-
}
|
|
264
|
-
if (from > to) {
|
|
265
|
-
// Wrapping ranges (`fri-mon`, `22-2`) are a real cron idiom.
|
|
266
|
-
for (let value = from; value <= max; value += step)
|
|
267
|
-
values.add(value);
|
|
268
|
-
for (let value = min; value <= to; value += step)
|
|
269
|
-
values.add(value);
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
for (let value = from; value <= to; value += step)
|
|
273
|
-
values.add(value);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (values.size === 0)
|
|
277
|
-
throw cronInvalid(expression, `field "${field}" matches nothing`);
|
|
278
|
-
return [...values].sort((a, b) => a - b);
|
|
279
|
-
}
|
|
280
|
-
function toNumber(expression, token, min, max, names, nameOffset) {
|
|
281
|
-
if (token === undefined || token === '')
|
|
282
|
-
throw cronInvalid(expression, 'missing value');
|
|
283
|
-
const named = names.indexOf(token.slice(0, 3));
|
|
284
|
-
const value = named === -1 ? Number.parseInt(token, 10) : named + nameOffset;
|
|
285
|
-
if (!Number.isInteger(value) || value < min || value > max) {
|
|
286
|
-
throw cronInvalid(expression, `"${token}" is out of range ${min}-${max}`);
|
|
287
|
-
}
|
|
288
|
-
return value;
|
|
289
|
-
}
|
|
290
|
-
function isWildcard(field) {
|
|
291
|
-
const [head] = field.split('/');
|
|
292
|
-
return head === '*' || head === '?';
|
|
293
|
-
}
|
|
294
|
-
/** `*` and `?` are "any"; a step like every-2nd-day restricts, and Vixie's OR rule sees that. */
|
|
295
|
-
function isRestricted(field) {
|
|
296
|
-
return field !== '*' && field !== '?';
|
|
297
|
-
}
|
|
298
|
-
/** Step fields: an evenly spaced set starting at 0 that covers the whole range. */
|
|
299
|
-
function uniformStep(values, size) {
|
|
300
|
-
const first = values[0];
|
|
301
|
-
if (values.length < 2 || first !== 0)
|
|
302
|
-
return undefined;
|
|
303
|
-
const step = (values[1] ?? 0) - first;
|
|
304
|
-
if (step <= 0 || values.length !== Math.ceil(size / step))
|
|
305
|
-
return undefined;
|
|
306
|
-
for (let index = 1; index < values.length; index += 1) {
|
|
307
|
-
if ((values[index] ?? -1) - (values[index - 1] ?? -1) !== step)
|
|
308
|
-
return undefined;
|
|
309
|
-
}
|
|
310
|
-
return step;
|
|
311
|
-
}
|
|
312
|
-
function isoWeekday(cursor) {
|
|
313
|
-
const day = new Date(Date.UTC(cursor.year, cursor.month - 1, cursor.day)).getUTCDay();
|
|
314
|
-
return ((day + 6) % 7) + 1;
|
|
315
|
-
}
|
|
316
|
-
function daysInMonth(year, month) {
|
|
317
|
-
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
318
|
-
}
|
|
319
|
-
function resetTime(cursor) {
|
|
320
|
-
cursor.hour = 0;
|
|
321
|
-
cursor.minute = 0;
|
|
322
|
-
cursor.second = 0;
|
|
323
|
-
}
|
|
324
|
-
/** Carry overflow up the fields so the cursor stays a real calendar date. */
|
|
325
|
-
function carry(cursor) {
|
|
326
|
-
if (cursor.second > 59) {
|
|
327
|
-
cursor.minute += Math.floor(cursor.second / 60);
|
|
328
|
-
cursor.second %= 60;
|
|
329
|
-
}
|
|
330
|
-
if (cursor.minute > 59) {
|
|
331
|
-
cursor.hour += Math.floor(cursor.minute / 60);
|
|
332
|
-
cursor.minute %= 60;
|
|
333
|
-
}
|
|
334
|
-
if (cursor.hour > 23) {
|
|
335
|
-
cursor.day += Math.floor(cursor.hour / 24);
|
|
336
|
-
cursor.hour %= 24;
|
|
337
|
-
}
|
|
338
|
-
while (cursor.month > 12) {
|
|
339
|
-
cursor.month -= 12;
|
|
340
|
-
cursor.year += 1;
|
|
341
|
-
}
|
|
342
|
-
while (cursor.day > daysInMonth(cursor.year, cursor.month)) {
|
|
343
|
-
cursor.day -= daysInMonth(cursor.year, cursor.month);
|
|
344
|
-
cursor.month += 1;
|
|
345
|
-
if (cursor.month > 12) {
|
|
346
|
-
cursor.month = 1;
|
|
347
|
-
cursor.year += 1;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
function fill(template, vars) {
|
|
352
|
-
return template.replace(/\{(\w+)\}/g, (match, name) => {
|
|
353
|
-
const value = vars[name];
|
|
354
|
-
return value === undefined ? match : String(value);
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
const monthFormatters = new Map();
|
|
358
|
-
const weekdayFormatters = new Map();
|
|
359
|
-
function monthName(month, locale) {
|
|
360
|
-
let formatter = monthFormatters.get(locale);
|
|
361
|
-
if (formatter === undefined) {
|
|
362
|
-
formatter = new Intl.DateTimeFormat(locale, { month: 'long', timeZone: 'UTC' });
|
|
363
|
-
monthFormatters.set(locale, formatter);
|
|
364
|
-
}
|
|
365
|
-
return formatter.format(new Date(Date.UTC(2026, month - 1, 1)));
|
|
366
|
-
}
|
|
367
|
-
function weekdayName(isoDay, locale) {
|
|
368
|
-
let formatter = weekdayFormatters.get(locale);
|
|
369
|
-
if (formatter === undefined) {
|
|
370
|
-
formatter = new Intl.DateTimeFormat(locale, { weekday: 'long', timeZone: 'UTC' });
|
|
371
|
-
weekdayFormatters.set(locale, formatter);
|
|
372
|
-
}
|
|
373
|
-
// 2026-06-01 is a Monday, so ISO day N is that date + (N - 1).
|
|
374
|
-
return formatter.format(new Date(Date.UTC(2026, 5, isoDay)));
|
|
375
|
-
}
|
|
376
|
-
function pad2(value) {
|
|
377
|
-
return String(value).padStart(2, '0');
|
|
378
|
-
}
|
|
379
|
-
/** Exported for the scheduler's leader loop: has this expression fired since `since`? */
|
|
380
|
-
export function firedSince(expression, zone, since, until) {
|
|
381
|
-
if (until.getTime() <= since.getTime())
|
|
382
|
-
return false;
|
|
383
|
-
const next = nextCronOccurrence(expression, zone, since);
|
|
384
|
-
return next.getTime() <= until.getTime();
|
|
385
|
-
}
|
|
386
|
-
/** Epoch-ms helper used by the jobs package when it only has a number. */
|
|
387
|
-
export function nextCronOccurrenceMs(expression, zone, afterMs) {
|
|
388
|
-
return nextCronOccurrence(expression, zone, fromEpochMs(afterMs)).getTime();
|
|
389
|
-
}
|
|
390
|
-
//# sourceMappingURL=cron.js.map
|
package/src/cron.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cron.js","sourceRoot":"","sources":["cron.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,WAAW,EAAgB,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAiB,MAAM,SAAS,CAAC;AAiBxD,MAAM,MAAM,GAAqC;IAC/C,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,WAAW;IACvB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,WAAW;IACxB,SAAS,EAAE,WAAW;CACvB,CAAC;AAEF,MAAM,WAAW,GAAG;IAClB,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC;AACF,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAEpE,4EAA4E;AAC5E,MAAM,UAAU,SAAS,CAAC,UAA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,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,UAAU,CACxB,UAAmC,EACnC,IAAc,EACd,KAAc,EACd,KAAc;IAEd,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE;QAAE,OAAO,KAAK,CAAC;IACrD,MAAM,IAAI,GAAG,kBAAkB,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACzD,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;AAC3C,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,oBAAoB,CAClC,UAAmC,EACnC,IAAc,EACd,OAAe;IAEf,OAAO,kBAAkB,CAAC,UAAU,EAAE,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAC9E,CAAC"}
|
package/src/duration.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Durations as milliseconds, parsed from a human string.
|
|
3
|
-
* `step.sleep('3d')` in @ultimat3/jobs and every `retry.backoff` value comes through here.
|
|
4
|
-
*/
|
|
5
|
-
export declare const MS = 1;
|
|
6
|
-
export declare const SECOND = 1000;
|
|
7
|
-
export declare const MINUTE: number;
|
|
8
|
-
export declare const HOUR: number;
|
|
9
|
-
export declare const DAY: number;
|
|
10
|
-
export declare const WEEK: number;
|
|
11
|
-
/**
|
|
12
|
-
* `'90s'` → 90000 · `'2h30m'` → 9000000 · `'3d'` → 259200000 · `'PT2H30M'` → 9000000.
|
|
13
|
-
* A bare number is rejected: `sleep(3)` is ambiguous, `sleep('3s')` is not.
|
|
14
|
-
*/
|
|
15
|
-
export declare function parseDuration(input: string): number;
|
|
16
|
-
/** Parse-or-passthrough for APIs that accept either form. */
|
|
17
|
-
export declare function toMs(duration: string | number): number;
|
|
18
|
-
export declare function toSeconds(duration: string | number): number;
|
|
19
|
-
export interface FormatDurationOptions {
|
|
20
|
-
/** Largest unit count to show: `2h 30m` with 2, `2h` with 1. */
|
|
21
|
-
maxUnits?: number;
|
|
22
|
-
style?: 'long' | 'short' | 'narrow';
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* `formatDuration(9_000_000, 'de-DE')` → `2 Std., 30 Min.`
|
|
26
|
-
* Built from `Intl.NumberFormat` unit style + `Intl.ListFormat`, so unit names and the
|
|
27
|
-
* list separator are both localized. `Intl.DurationFormat` is not yet everywhere.
|
|
28
|
-
*/
|
|
29
|
-
export declare function formatDuration(ms: number, locale: string, options?: FormatDurationOptions): string;
|
|
30
|
-
/** `PT2H30M` — for OpenAPI schemas and cron metadata. */
|
|
31
|
-
export declare function formatDurationIso(ms: number): string;
|
|
32
|
-
//# sourceMappingURL=duration.d.ts.map
|
package/src/duration.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["duration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,eAAO,MAAM,EAAE,IAAI,CAAC;AACpB,eAAO,MAAM,MAAM,OAAO,CAAC;AAC3B,eAAO,MAAM,MAAM,QAAc,CAAC;AAClC,eAAO,MAAM,IAAI,QAAc,CAAC;AAChC,eAAO,MAAM,GAAG,QAAY,CAAC;AAC7B,eAAO,MAAM,IAAI,QAAU,CAAC;AAkB5B;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA0BnD;AAED,6DAA6D;AAC7D,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE3D;AAED,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;CACrC;AAUD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,qBAA0B,GAClC,MAAM,CA0BR;AAED,yDAAyD;AACzD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAcpD"}
|
package/src/duration.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Durations as milliseconds, parsed from a human string.
|
|
3
|
-
* `step.sleep('3d')` in @ultimat3/jobs and every `retry.backoff` value comes through here.
|
|
4
|
-
*/
|
|
5
|
-
import { durationInvalid } from './errors';
|
|
6
|
-
export const MS = 1;
|
|
7
|
-
export const SECOND = 1000;
|
|
8
|
-
export const MINUTE = 60 * SECOND;
|
|
9
|
-
export const HOUR = 60 * MINUTE;
|
|
10
|
-
export const DAY = 24 * HOUR;
|
|
11
|
-
export const WEEK = 7 * DAY;
|
|
12
|
-
/** Accepted suffixes. `m` is minutes and `ms` is milliseconds — never months. */
|
|
13
|
-
const UNITS = {
|
|
14
|
-
ms: MS,
|
|
15
|
-
s: SECOND,
|
|
16
|
-
sec: SECOND,
|
|
17
|
-
m: MINUTE,
|
|
18
|
-
min: MINUTE,
|
|
19
|
-
h: HOUR,
|
|
20
|
-
hr: HOUR,
|
|
21
|
-
d: DAY,
|
|
22
|
-
w: WEEK,
|
|
23
|
-
};
|
|
24
|
-
const COMPONENT = /(\d+(?:\.\d+)?)\s*(ms|sec|min|hr|[smhdw])\s*/iy;
|
|
25
|
-
const ISO_8601 = /^P(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/i;
|
|
26
|
-
/**
|
|
27
|
-
* `'90s'` → 90000 · `'2h30m'` → 9000000 · `'3d'` → 259200000 · `'PT2H30M'` → 9000000.
|
|
28
|
-
* A bare number is rejected: `sleep(3)` is ambiguous, `sleep('3s')` is not.
|
|
29
|
-
*/
|
|
30
|
-
export function parseDuration(input) {
|
|
31
|
-
const value = input.trim();
|
|
32
|
-
if (value === '')
|
|
33
|
-
throw durationInvalid(input);
|
|
34
|
-
const negative = value.startsWith('-');
|
|
35
|
-
const body = negative ? value.slice(1) : value;
|
|
36
|
-
if (/^p/i.test(body))
|
|
37
|
-
return (negative ? -1 : 1) * parseIso8601Duration(body, input);
|
|
38
|
-
COMPONENT.lastIndex = 0;
|
|
39
|
-
let total = 0;
|
|
40
|
-
let matched = 0;
|
|
41
|
-
let match = COMPONENT.exec(body);
|
|
42
|
-
while (match !== null) {
|
|
43
|
-
const amount = Number.parseFloat(match[1] ?? '');
|
|
44
|
-
const unit = (match[2] ?? '').toLowerCase();
|
|
45
|
-
const scale = UNITS[unit];
|
|
46
|
-
if (!Number.isFinite(amount) || scale === undefined)
|
|
47
|
-
throw durationInvalid(input);
|
|
48
|
-
total += amount * scale;
|
|
49
|
-
matched = COMPONENT.lastIndex;
|
|
50
|
-
match = COMPONENT.exec(body);
|
|
51
|
-
}
|
|
52
|
-
// Sticky matching starts at 0, so anything short of the end is trailing junk, and a
|
|
53
|
-
// zero-length match means there was no unit at all (`'3'` must not mean 3 of anything).
|
|
54
|
-
if (matched === 0 || matched !== body.length)
|
|
55
|
-
throw durationInvalid(input);
|
|
56
|
-
return (negative ? -1 : 1) * Math.round(total);
|
|
57
|
-
}
|
|
58
|
-
/** Parse-or-passthrough for APIs that accept either form. */
|
|
59
|
-
export function toMs(duration) {
|
|
60
|
-
return typeof duration === 'number' ? duration : parseDuration(duration);
|
|
61
|
-
}
|
|
62
|
-
export function toSeconds(duration) {
|
|
63
|
-
return Math.round(toMs(duration) / SECOND);
|
|
64
|
-
}
|
|
65
|
-
const FORMAT_UNITS = [
|
|
66
|
-
['day', DAY],
|
|
67
|
-
['hour', HOUR],
|
|
68
|
-
['minute', MINUTE],
|
|
69
|
-
['second', SECOND],
|
|
70
|
-
['millisecond', MS],
|
|
71
|
-
];
|
|
72
|
-
/**
|
|
73
|
-
* `formatDuration(9_000_000, 'de-DE')` → `2 Std., 30 Min.`
|
|
74
|
-
* Built from `Intl.NumberFormat` unit style + `Intl.ListFormat`, so unit names and the
|
|
75
|
-
* list separator are both localized. `Intl.DurationFormat` is not yet everywhere.
|
|
76
|
-
*/
|
|
77
|
-
export function formatDuration(ms, locale, options = {}) {
|
|
78
|
-
const style = options.style ?? 'short';
|
|
79
|
-
const maxUnits = options.maxUnits ?? 2;
|
|
80
|
-
let remaining = Math.abs(Math.round(ms));
|
|
81
|
-
const pieces = [];
|
|
82
|
-
for (const [unit, scale] of FORMAT_UNITS) {
|
|
83
|
-
if (pieces.length >= maxUnits)
|
|
84
|
-
break;
|
|
85
|
-
const count = Math.floor(remaining / scale);
|
|
86
|
-
if (count === 0)
|
|
87
|
-
continue;
|
|
88
|
-
remaining -= count * scale;
|
|
89
|
-
pieces.push(new Intl.NumberFormat(locale, { style: 'unit', unit, unitDisplay: style }).format(count));
|
|
90
|
-
}
|
|
91
|
-
if (pieces.length === 0) {
|
|
92
|
-
return new Intl.NumberFormat(locale, {
|
|
93
|
-
style: 'unit',
|
|
94
|
-
unit: 'second',
|
|
95
|
-
unitDisplay: style,
|
|
96
|
-
}).format(0);
|
|
97
|
-
}
|
|
98
|
-
const joined = new Intl.ListFormat(locale, { style: 'narrow', type: 'unit' }).format(pieces);
|
|
99
|
-
return ms < 0 ? `-${joined}` : joined;
|
|
100
|
-
}
|
|
101
|
-
/** `PT2H30M` — for OpenAPI schemas and cron metadata. */
|
|
102
|
-
export function formatDurationIso(ms) {
|
|
103
|
-
const total = Math.abs(Math.round(ms));
|
|
104
|
-
const days = Math.floor(total / DAY);
|
|
105
|
-
const hours = Math.floor((total % DAY) / HOUR);
|
|
106
|
-
const minutes = Math.floor((total % HOUR) / MINUTE);
|
|
107
|
-
const seconds = (total % MINUTE) / SECOND;
|
|
108
|
-
const date = days > 0 ? `${days}D` : '';
|
|
109
|
-
const time = [
|
|
110
|
-
hours > 0 ? `${hours}H` : '',
|
|
111
|
-
minutes > 0 ? `${minutes}M` : '',
|
|
112
|
-
seconds > 0 ? `${seconds}S` : '',
|
|
113
|
-
].join('');
|
|
114
|
-
const body = `${date}${time === '' ? '' : `T${time}`}`;
|
|
115
|
-
return `${ms < 0 ? '-' : ''}P${body === '' ? '0D' : body}`;
|
|
116
|
-
}
|
|
117
|
-
function parseIso8601Duration(body, original) {
|
|
118
|
-
const match = ISO_8601.exec(body);
|
|
119
|
-
if (match === null)
|
|
120
|
-
throw durationInvalid(original);
|
|
121
|
-
const [, weeks, days, hours, minutes, seconds] = match;
|
|
122
|
-
const total = number(weeks) * WEEK +
|
|
123
|
-
number(days) * DAY +
|
|
124
|
-
number(hours) * HOUR +
|
|
125
|
-
number(minutes) * MINUTE +
|
|
126
|
-
number(seconds) * SECOND;
|
|
127
|
-
if (total === 0 && body.toUpperCase() !== 'P0D')
|
|
128
|
-
throw durationInvalid(original);
|
|
129
|
-
return Math.round(total);
|
|
130
|
-
}
|
|
131
|
-
function number(value) {
|
|
132
|
-
return value === undefined ? 0 : Number.parseFloat(value);
|
|
133
|
-
}
|
|
134
|
-
//# sourceMappingURL=duration.js.map
|
package/src/duration.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"duration.js","sourceRoot":"","sources":["duration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACpB,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC;AAClC,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC;AAChC,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7B,MAAM,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AAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7D,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY,EAAE,QAAgB;IAC1D,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,eAAe,CAAC,QAAQ,CAAC,CAAC;IACpD,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC;IACvD,MAAM,KAAK,GACT,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI;QACpB,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG;QAClB,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI;QACpB,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM;QACxB,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAC3B,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK;QAAE,MAAM,eAAe,CAAC,QAAQ,CAAC,CAAC;IACjF,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAS,MAAM,CAAC,KAAyB;IACvC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC"}
|
package/src/errors.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The X_* error codes owned by @ultimat3/time.
|
|
3
|
-
* DST ambiguity is a real state of the world, so it gets a code instead of a guess.
|
|
4
|
-
*/
|
|
5
|
-
import { UltimateError } from '@ultimat3/core';
|
|
6
|
-
export declare const TIME_ERROR_CODES: readonly ['X_TIMEZONE_INVALID', 'X_CRON_INVALID', 'X_DURATION_INVALID', 'X_DST_AMBIGUOUS', 'X_DST_NONEXISTENT', 'X_INSTANT_INVALID', 'X_SCHEDULE_INVALID'];
|
|
7
|
-
export type TimeErrorCode = (typeof TIME_ERROR_CODES)[number];
|
|
8
|
-
export declare class TimeError extends UltimateError {
|
|
9
|
-
constructor(init: {
|
|
10
|
-
code: TimeErrorCode;
|
|
11
|
-
cause: string;
|
|
12
|
-
fix: string;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* A wall-clock field outside its range. Separate from `X_DST_*`, which are about times that
|
|
17
|
-
* are legitimately absent or doubled — this one is a spec the caller got wrong.
|
|
18
|
-
*/
|
|
19
|
-
export declare function scheduleInvalid(field: string, value: unknown, range: string): TimeError;
|
|
20
|
-
export declare function timezoneInvalid(zone: string): TimeError;
|
|
21
|
-
export declare function cronInvalid(expression: string, reason: string): TimeError;
|
|
22
|
-
export declare function durationInvalid(input: string): TimeError;
|
|
23
|
-
export declare function dstAmbiguous(wall: string, zone: string): TimeError;
|
|
24
|
-
export declare function dstNonexistent(wall: string, zone: string): TimeError;
|
|
25
|
-
export declare function instantInvalid(input: string): TimeError;
|
|
26
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/src/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,eAAO,MAAM,gBAAgB,YAC3B,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,CACZ,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,qBAAa,SAAU,SAAQ,aAAa;IAC1C,YAAY,IAAI,EAAE;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAOpE;CACF;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAMvF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAMvD;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAMzE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAMxD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAMlE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAMpE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAMvD"}
|