donebear 0.3.6 → 0.3.7
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/AGENTS.md +3 -3
- package/dist/cli.mjs +3098 -150
- package/dist/cli.mjs.map +1 -1
- package/dist/context-store-DH561Z1u.mjs.map +1 -1
- package/package.json +3 -7
package/dist/cli.mjs
CHANGED
|
@@ -14,10 +14,12 @@ import { styleText } from "node:util";
|
|
|
14
14
|
import jmespath from "jmespath";
|
|
15
15
|
import { stringify } from "yaml";
|
|
16
16
|
import { createServer } from "node:http";
|
|
17
|
-
import rrule from "rrule";
|
|
18
17
|
import { fileURLToPath } from "node:url";
|
|
19
18
|
import Database from "better-sqlite3";
|
|
20
19
|
import { createInterface } from "node:readline";
|
|
20
|
+
//#region \0rolldown/runtime.js
|
|
21
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
22
|
+
//#endregion
|
|
21
23
|
//#region src/jwt.ts
|
|
22
24
|
const parseJwtBase64Url = (input) => {
|
|
23
25
|
const normalized = input.replaceAll("-", "+").replaceAll("_", "/");
|
|
@@ -415,6 +417,118 @@ const parseCliDateOnlyToEpoch = (value, fieldLabel) => {
|
|
|
415
417
|
};
|
|
416
418
|
const dateOnlyEpochFromLocalDate = (now = /* @__PURE__ */ new Date()) => Date.UTC(now.getFullYear(), now.getMonth(), now.getDate());
|
|
417
419
|
//#endregion
|
|
420
|
+
//#region src/output.ts
|
|
421
|
+
const writeLine = (stream, message) => {
|
|
422
|
+
stream.write(`${message}\n`);
|
|
423
|
+
};
|
|
424
|
+
const colorize = (context, format, message) => {
|
|
425
|
+
if (!context.color) return message;
|
|
426
|
+
return styleText(format, message);
|
|
427
|
+
};
|
|
428
|
+
const writeJson = (value) => {
|
|
429
|
+
writeLine(process.stdout, JSON.stringify(value, null, 2));
|
|
430
|
+
};
|
|
431
|
+
const writeYaml = (value) => {
|
|
432
|
+
process.stdout.write(stringify(value));
|
|
433
|
+
};
|
|
434
|
+
const writeInfo = (context, message) => {
|
|
435
|
+
writeLine(process.stdout, colorize(context, "cyan", message));
|
|
436
|
+
};
|
|
437
|
+
const writeSuccess = (context, message) => {
|
|
438
|
+
writeLine(process.stdout, colorize(context, "green", message));
|
|
439
|
+
};
|
|
440
|
+
const writeWarning = (context, message) => {
|
|
441
|
+
writeLine(process.stderr, colorize(context, "yellow", message));
|
|
442
|
+
};
|
|
443
|
+
const writeError = (context, message) => {
|
|
444
|
+
writeLine(process.stderr, colorize(context, "red", message));
|
|
445
|
+
};
|
|
446
|
+
const writeDebug = (context, message) => {
|
|
447
|
+
if (!context.debug) return;
|
|
448
|
+
writeLine(process.stderr, colorize(context, "gray", `[debug] ${message}`));
|
|
449
|
+
};
|
|
450
|
+
const writeTotal = (context, count) => {
|
|
451
|
+
writeLine(process.stdout, colorize(context, "cyan", String(count)));
|
|
452
|
+
};
|
|
453
|
+
const escapeCsvField = (value) => {
|
|
454
|
+
if (value.includes(",") || value.includes("\"") || value.includes("\n")) return `"${value.replaceAll("\"", "\"\"")}"`;
|
|
455
|
+
return value;
|
|
456
|
+
};
|
|
457
|
+
const writeCsv = (headers, rows) => {
|
|
458
|
+
writeLine(process.stdout, headers.map(escapeCsvField).join(","));
|
|
459
|
+
for (const row of rows) writeLine(process.stdout, row.map(escapeCsvField).join(","));
|
|
460
|
+
};
|
|
461
|
+
const writeTsv = (headers, rows) => {
|
|
462
|
+
writeLine(process.stdout, headers.join(" "));
|
|
463
|
+
for (const row of rows) writeLine(process.stdout, row.join(" "));
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Write structured data to stdout, applying --jq filter and --limit if set.
|
|
467
|
+
* Use this for all JSON/YAML/structured output from commands.
|
|
468
|
+
*/
|
|
469
|
+
const writeOutput = (context, data) => {
|
|
470
|
+
let result = data;
|
|
471
|
+
if (context.jq) try {
|
|
472
|
+
result = jmespath.search(result, context.jq);
|
|
473
|
+
} catch (error) {
|
|
474
|
+
throw new CliError(`Invalid --jq expression: ${error instanceof Error ? error.message : String(error)}`, EXIT_CODES.VALIDATION);
|
|
475
|
+
}
|
|
476
|
+
if (context.limit !== null && Array.isArray(result)) result = result.slice(0, context.limit);
|
|
477
|
+
switch (context.format) {
|
|
478
|
+
case "yaml":
|
|
479
|
+
writeYaml(result);
|
|
480
|
+
break;
|
|
481
|
+
case "json":
|
|
482
|
+
writeJson(result);
|
|
483
|
+
break;
|
|
484
|
+
default:
|
|
485
|
+
writeJson(result);
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
if (context.copy) copyToClipboard(JSON.stringify(result, null, 2));
|
|
489
|
+
};
|
|
490
|
+
/**
|
|
491
|
+
* Handles --total, --format csv, --format tsv, --format yaml output.
|
|
492
|
+
* Returns true if the format was handled; caller renders text mode if false.
|
|
493
|
+
*/
|
|
494
|
+
const writeFormattedRows = (context, totalCount, headers, rows) => {
|
|
495
|
+
if (context.total) {
|
|
496
|
+
writeTotal(context, totalCount);
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
if (context.format === "yaml") {
|
|
500
|
+
const objects = rows.map((row) => Object.fromEntries(headers.map((h, i) => [h, row[i]])));
|
|
501
|
+
writeYaml(objects);
|
|
502
|
+
if (context.copy) copyToClipboard(stringify(objects));
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
if (context.format === "csv") {
|
|
506
|
+
writeCsv(headers, rows);
|
|
507
|
+
if (context.copy) copyToClipboard([headers.join(","), ...rows.map((r) => r.join(","))].join("\n"));
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
if (context.format === "tsv") {
|
|
511
|
+
writeTsv(headers, rows);
|
|
512
|
+
if (context.copy) copyToClipboard([headers.join(" "), ...rows.map((r) => r.join(" "))].join("\n"));
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
return false;
|
|
516
|
+
};
|
|
517
|
+
const copyToClipboard = (text) => {
|
|
518
|
+
try {
|
|
519
|
+
if (process.platform === "darwin") execSync("pbcopy", { input: text });
|
|
520
|
+
else if (process.platform === "win32") execSync("clip", { input: text });
|
|
521
|
+
else try {
|
|
522
|
+
execSync("xclip -selection clipboard", { input: text });
|
|
523
|
+
} catch {
|
|
524
|
+
execSync("xsel --clipboard --input", { input: text });
|
|
525
|
+
}
|
|
526
|
+
return true;
|
|
527
|
+
} catch {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
//#endregion
|
|
418
532
|
//#region src/manage-api.ts
|
|
419
533
|
const TASK_FIELDS = `
|
|
420
534
|
id
|
|
@@ -910,6 +1024,19 @@ const loadChecklistItemsByTask = async (context, options) => {
|
|
|
910
1024
|
return results;
|
|
911
1025
|
};
|
|
912
1026
|
const mutateModel = async (context, options) => {
|
|
1027
|
+
if (context.dryRun) {
|
|
1028
|
+
writeWarning(context, "dry run: mutation skipped");
|
|
1029
|
+
writeOutput(context, {
|
|
1030
|
+
dryRun: true,
|
|
1031
|
+
transactions: options.request.transactions.map((tx) => ({
|
|
1032
|
+
action: tx.action,
|
|
1033
|
+
modelId: tx.modelId,
|
|
1034
|
+
modelName: tx.modelName,
|
|
1035
|
+
payload: tx.payload
|
|
1036
|
+
}))
|
|
1037
|
+
});
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
913
1040
|
const response = await requestJson(context, `${options.baseUrl}/sync/mutate`, {
|
|
914
1041
|
body: options.request,
|
|
915
1042
|
method: "POST",
|
|
@@ -1019,118 +1146,6 @@ const requireUserId = (resolvedToken) => {
|
|
|
1019
1146
|
return userId;
|
|
1020
1147
|
};
|
|
1021
1148
|
//#endregion
|
|
1022
|
-
//#region src/output.ts
|
|
1023
|
-
const writeLine = (stream, message) => {
|
|
1024
|
-
stream.write(`${message}\n`);
|
|
1025
|
-
};
|
|
1026
|
-
const colorize = (context, format, message) => {
|
|
1027
|
-
if (!context.color) return message;
|
|
1028
|
-
return styleText(format, message);
|
|
1029
|
-
};
|
|
1030
|
-
const writeJson = (value) => {
|
|
1031
|
-
writeLine(process.stdout, JSON.stringify(value, null, 2));
|
|
1032
|
-
};
|
|
1033
|
-
const writeYaml = (value) => {
|
|
1034
|
-
process.stdout.write(stringify(value));
|
|
1035
|
-
};
|
|
1036
|
-
const writeInfo = (context, message) => {
|
|
1037
|
-
writeLine(process.stdout, colorize(context, "cyan", message));
|
|
1038
|
-
};
|
|
1039
|
-
const writeSuccess = (context, message) => {
|
|
1040
|
-
writeLine(process.stdout, colorize(context, "green", message));
|
|
1041
|
-
};
|
|
1042
|
-
const writeWarning = (context, message) => {
|
|
1043
|
-
writeLine(process.stderr, colorize(context, "yellow", message));
|
|
1044
|
-
};
|
|
1045
|
-
const writeError = (context, message) => {
|
|
1046
|
-
writeLine(process.stderr, colorize(context, "red", message));
|
|
1047
|
-
};
|
|
1048
|
-
const writeDebug = (context, message) => {
|
|
1049
|
-
if (!context.debug) return;
|
|
1050
|
-
writeLine(process.stderr, colorize(context, "gray", `[debug] ${message}`));
|
|
1051
|
-
};
|
|
1052
|
-
const writeTotal = (context, count) => {
|
|
1053
|
-
writeLine(process.stdout, colorize(context, "cyan", String(count)));
|
|
1054
|
-
};
|
|
1055
|
-
const escapeCsvField = (value) => {
|
|
1056
|
-
if (value.includes(",") || value.includes("\"") || value.includes("\n")) return `"${value.replaceAll("\"", "\"\"")}"`;
|
|
1057
|
-
return value;
|
|
1058
|
-
};
|
|
1059
|
-
const writeCsv = (headers, rows) => {
|
|
1060
|
-
writeLine(process.stdout, headers.map(escapeCsvField).join(","));
|
|
1061
|
-
for (const row of rows) writeLine(process.stdout, row.map(escapeCsvField).join(","));
|
|
1062
|
-
};
|
|
1063
|
-
const writeTsv = (headers, rows) => {
|
|
1064
|
-
writeLine(process.stdout, headers.join(" "));
|
|
1065
|
-
for (const row of rows) writeLine(process.stdout, row.join(" "));
|
|
1066
|
-
};
|
|
1067
|
-
/**
|
|
1068
|
-
* Write structured data to stdout, applying --jq filter and --limit if set.
|
|
1069
|
-
* Use this for all JSON/YAML/structured output from commands.
|
|
1070
|
-
*/
|
|
1071
|
-
const writeOutput = (context, data) => {
|
|
1072
|
-
let result = data;
|
|
1073
|
-
if (context.jq) try {
|
|
1074
|
-
result = jmespath.search(result, context.jq);
|
|
1075
|
-
} catch (error) {
|
|
1076
|
-
throw new CliError(`Invalid --jq expression: ${error instanceof Error ? error.message : String(error)}`, EXIT_CODES.VALIDATION);
|
|
1077
|
-
}
|
|
1078
|
-
if (context.limit !== null && Array.isArray(result)) result = result.slice(0, context.limit);
|
|
1079
|
-
switch (context.format) {
|
|
1080
|
-
case "yaml":
|
|
1081
|
-
writeYaml(result);
|
|
1082
|
-
break;
|
|
1083
|
-
case "json":
|
|
1084
|
-
writeJson(result);
|
|
1085
|
-
break;
|
|
1086
|
-
default:
|
|
1087
|
-
writeJson(result);
|
|
1088
|
-
break;
|
|
1089
|
-
}
|
|
1090
|
-
if (context.copy) copyToClipboard(JSON.stringify(result, null, 2));
|
|
1091
|
-
};
|
|
1092
|
-
/**
|
|
1093
|
-
* Handles --total, --format csv, --format tsv, --format yaml output.
|
|
1094
|
-
* Returns true if the format was handled; caller renders text mode if false.
|
|
1095
|
-
*/
|
|
1096
|
-
const writeFormattedRows = (context, totalCount, headers, rows) => {
|
|
1097
|
-
if (context.total) {
|
|
1098
|
-
writeTotal(context, totalCount);
|
|
1099
|
-
return true;
|
|
1100
|
-
}
|
|
1101
|
-
if (context.format === "yaml") {
|
|
1102
|
-
const objects = rows.map((row) => Object.fromEntries(headers.map((h, i) => [h, row[i]])));
|
|
1103
|
-
writeYaml(objects);
|
|
1104
|
-
if (context.copy) copyToClipboard(stringify(objects));
|
|
1105
|
-
return true;
|
|
1106
|
-
}
|
|
1107
|
-
if (context.format === "csv") {
|
|
1108
|
-
writeCsv(headers, rows);
|
|
1109
|
-
if (context.copy) copyToClipboard([headers.join(","), ...rows.map((r) => r.join(","))].join("\n"));
|
|
1110
|
-
return true;
|
|
1111
|
-
}
|
|
1112
|
-
if (context.format === "tsv") {
|
|
1113
|
-
writeTsv(headers, rows);
|
|
1114
|
-
if (context.copy) copyToClipboard([headers.join(" "), ...rows.map((r) => r.join(" "))].join("\n"));
|
|
1115
|
-
return true;
|
|
1116
|
-
}
|
|
1117
|
-
return false;
|
|
1118
|
-
};
|
|
1119
|
-
const copyToClipboard = (text) => {
|
|
1120
|
-
try {
|
|
1121
|
-
if (process.platform === "darwin") execSync("pbcopy", { input: text });
|
|
1122
|
-
else if (process.platform === "win32") execSync("clip", { input: text });
|
|
1123
|
-
else try {
|
|
1124
|
-
execSync("xclip -selection clipboard", { input: text });
|
|
1125
|
-
} catch {
|
|
1126
|
-
execSync("xsel --clipboard --input", { input: text });
|
|
1127
|
-
}
|
|
1128
|
-
return true;
|
|
1129
|
-
} catch {
|
|
1130
|
-
return false;
|
|
1131
|
-
}
|
|
1132
|
-
};
|
|
1133
|
-
//#endregion
|
|
1134
1149
|
//#region src/options.ts
|
|
1135
1150
|
const parseOutputFormat = (value) => {
|
|
1136
1151
|
switch (value?.trim().toLowerCase()) {
|
|
@@ -2212,8 +2227,8 @@ const createUuidV5 = (name, namespace) => {
|
|
|
2212
2227
|
const namespaceBytes = uuidToBytes(namespace);
|
|
2213
2228
|
const hash = createHash("sha1").update(namespaceBytes).update(Buffer.from(name, "utf8")).digest();
|
|
2214
2229
|
const bytes = Uint8Array.from(hash.subarray(0, 16));
|
|
2215
|
-
const versionByte = bytes
|
|
2216
|
-
const variantByte = bytes
|
|
2230
|
+
const versionByte = bytes.at(6);
|
|
2231
|
+
const variantByte = bytes.at(8);
|
|
2217
2232
|
if (typeof versionByte !== "number" || typeof variantByte !== "number") throw new TypeError("Failed to generate a deterministic UUID.");
|
|
2218
2233
|
bytes[6] = versionByte & 15 | 80;
|
|
2219
2234
|
bytes[8] = variantByte & 63 | 128;
|
|
@@ -2233,36 +2248,2792 @@ const createTeamProjectId = (params) => createCompositeSyncId("TeamProject", [
|
|
|
2233
2248
|
]);
|
|
2234
2249
|
//#endregion
|
|
2235
2250
|
//#region src/import/things-values.ts
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2251
|
+
var import_rrule = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2252
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2253
|
+
if (typeof exports === "object" && typeof module === "object") module.exports = factory();
|
|
2254
|
+
else if (typeof define === "function" && define.amd) define([], factory);
|
|
2255
|
+
else if (typeof exports === "object") exports["rrule"] = factory();
|
|
2256
|
+
else root["rrule"] = factory();
|
|
2257
|
+
})(typeof self !== "undefined" ? self : exports, () => {
|
|
2258
|
+
return (() => {
|
|
2259
|
+
"use strict";
|
|
2260
|
+
var __webpack_require__ = {};
|
|
2261
|
+
__webpack_require__.d = (exports$1, definition) => {
|
|
2262
|
+
for (var key in definition) if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports$1, key)) Object.defineProperty(exports$1, key, {
|
|
2263
|
+
enumerable: true,
|
|
2264
|
+
get: definition[key]
|
|
2265
|
+
});
|
|
2266
|
+
};
|
|
2267
|
+
__webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
2268
|
+
__webpack_require__.r = (exports$2) => {
|
|
2269
|
+
if (typeof Symbol !== "undefined" && Symbol.toStringTag) Object.defineProperty(exports$2, Symbol.toStringTag, { value: "Module" });
|
|
2270
|
+
Object.defineProperty(exports$2, "__esModule", { value: true });
|
|
2271
|
+
};
|
|
2272
|
+
var __webpack_exports__ = {};
|
|
2273
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2274
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
2275
|
+
"ALL_WEEKDAYS": () => ALL_WEEKDAYS,
|
|
2276
|
+
"Frequency": () => Frequency,
|
|
2277
|
+
"RRule": () => RRule,
|
|
2278
|
+
"RRuleSet": () => RRuleSet,
|
|
2279
|
+
"Weekday": () => Weekday,
|
|
2280
|
+
"datetime": () => datetime,
|
|
2281
|
+
"rrulestr": () => rrulestr
|
|
2282
|
+
});
|
|
2283
|
+
var ALL_WEEKDAYS = [
|
|
2284
|
+
"MO",
|
|
2285
|
+
"TU",
|
|
2286
|
+
"WE",
|
|
2287
|
+
"TH",
|
|
2288
|
+
"FR",
|
|
2289
|
+
"SA",
|
|
2290
|
+
"SU"
|
|
2291
|
+
];
|
|
2292
|
+
var Weekday = function() {
|
|
2293
|
+
function Weekday(weekday, n) {
|
|
2294
|
+
if (n === 0) throw new Error("Can't create weekday with n == 0");
|
|
2295
|
+
this.weekday = weekday;
|
|
2296
|
+
this.n = n;
|
|
2297
|
+
}
|
|
2298
|
+
Weekday.fromStr = function(str) {
|
|
2299
|
+
return new Weekday(ALL_WEEKDAYS.indexOf(str));
|
|
2300
|
+
};
|
|
2301
|
+
Weekday.prototype.nth = function(n) {
|
|
2302
|
+
return this.n === n ? this : new Weekday(this.weekday, n);
|
|
2303
|
+
};
|
|
2304
|
+
Weekday.prototype.equals = function(other) {
|
|
2305
|
+
return this.weekday === other.weekday && this.n === other.n;
|
|
2306
|
+
};
|
|
2307
|
+
Weekday.prototype.toString = function() {
|
|
2308
|
+
var s = ALL_WEEKDAYS[this.weekday];
|
|
2309
|
+
if (this.n) s = (this.n > 0 ? "+" : "") + String(this.n) + s;
|
|
2310
|
+
return s;
|
|
2311
|
+
};
|
|
2312
|
+
Weekday.prototype.getJsWeekday = function() {
|
|
2313
|
+
return this.weekday === 6 ? 0 : this.weekday + 1;
|
|
2314
|
+
};
|
|
2315
|
+
return Weekday;
|
|
2316
|
+
}();
|
|
2317
|
+
var isPresent = function(value) {
|
|
2318
|
+
return value !== null && value !== void 0;
|
|
2319
|
+
};
|
|
2320
|
+
var isNumber = function(value) {
|
|
2321
|
+
return typeof value === "number";
|
|
2322
|
+
};
|
|
2323
|
+
var isWeekdayStr = function(value) {
|
|
2324
|
+
return typeof value === "string" && ALL_WEEKDAYS.includes(value);
|
|
2325
|
+
};
|
|
2326
|
+
var isArray = Array.isArray;
|
|
2327
|
+
/**
|
|
2328
|
+
* Simplified version of python's range()
|
|
2329
|
+
*/
|
|
2330
|
+
var range = function(start, end) {
|
|
2331
|
+
if (end === void 0) end = start;
|
|
2332
|
+
if (arguments.length === 1) {
|
|
2333
|
+
end = start;
|
|
2334
|
+
start = 0;
|
|
2335
|
+
}
|
|
2336
|
+
var rang = [];
|
|
2337
|
+
for (var i = start; i < end; i++) rang.push(i);
|
|
2338
|
+
return rang;
|
|
2339
|
+
};
|
|
2340
|
+
var repeat = function(value, times) {
|
|
2341
|
+
var i = 0;
|
|
2342
|
+
var array = [];
|
|
2343
|
+
if (isArray(value)) for (; i < times; i++) array[i] = [].concat(value);
|
|
2344
|
+
else for (; i < times; i++) array[i] = value;
|
|
2345
|
+
return array;
|
|
2346
|
+
};
|
|
2347
|
+
var toArray = function(item) {
|
|
2348
|
+
if (isArray(item)) return item;
|
|
2349
|
+
return [item];
|
|
2350
|
+
};
|
|
2351
|
+
function padStart(item, targetLength, padString) {
|
|
2352
|
+
if (padString === void 0) padString = " ";
|
|
2353
|
+
var str = String(item);
|
|
2354
|
+
targetLength = targetLength >> 0;
|
|
2355
|
+
if (str.length > targetLength) return String(str);
|
|
2356
|
+
targetLength = targetLength - str.length;
|
|
2357
|
+
if (targetLength > padString.length) padString += repeat(padString, targetLength / padString.length);
|
|
2358
|
+
return padString.slice(0, targetLength) + String(str);
|
|
2359
|
+
}
|
|
2360
|
+
/**
|
|
2361
|
+
* Python like split
|
|
2362
|
+
*/
|
|
2363
|
+
var split = function(str, sep, num) {
|
|
2364
|
+
var splits = str.split(sep);
|
|
2365
|
+
return num ? splits.slice(0, num).concat([splits.slice(num).join(sep)]) : splits;
|
|
2366
|
+
};
|
|
2367
|
+
/**
|
|
2368
|
+
* closure/goog/math/math.js:modulo
|
|
2369
|
+
* Copyright 2006 The Closure Library Authors.
|
|
2370
|
+
* The % operator in JavaScript returns the remainder of a / b, but differs from
|
|
2371
|
+
* some other languages in that the result will have the same sign as the
|
|
2372
|
+
* dividend. For example, -1 % 8 == -1, whereas in some other languages
|
|
2373
|
+
* (such as Python) the result would be 7. This function emulates the more
|
|
2374
|
+
* correct modulo behavior, which is useful for certain applications such as
|
|
2375
|
+
* calculating an offset index in a circular list.
|
|
2376
|
+
*
|
|
2377
|
+
* @param {number} a The dividend.
|
|
2378
|
+
* @param {number} b The divisor.
|
|
2379
|
+
* @return {number} a % b where the result is between 0 and b (either 0 <= x < b
|
|
2380
|
+
* or b < x <= 0, depending on the sign of b).
|
|
2381
|
+
*/
|
|
2382
|
+
var pymod = function(a, b) {
|
|
2383
|
+
var r = a % b;
|
|
2384
|
+
return r * b < 0 ? r + b : r;
|
|
2385
|
+
};
|
|
2386
|
+
/**
|
|
2387
|
+
* @see: <http://docs.python.org/library/functions.html#divmod>
|
|
2388
|
+
*/
|
|
2389
|
+
var divmod = function(a, b) {
|
|
2390
|
+
return {
|
|
2391
|
+
div: Math.floor(a / b),
|
|
2392
|
+
mod: pymod(a, b)
|
|
2393
|
+
};
|
|
2394
|
+
};
|
|
2395
|
+
var empty = function(obj) {
|
|
2396
|
+
return !isPresent(obj) || obj.length === 0;
|
|
2397
|
+
};
|
|
2398
|
+
/**
|
|
2399
|
+
* Python-like boolean
|
|
2400
|
+
*
|
|
2401
|
+
* @return {Boolean} value of an object/primitive, taking into account
|
|
2402
|
+
* the fact that in Python an empty list's/tuple's
|
|
2403
|
+
* boolean value is False, whereas in JS it's true
|
|
2404
|
+
*/
|
|
2405
|
+
var notEmpty = function(obj) {
|
|
2406
|
+
return !empty(obj);
|
|
2407
|
+
};
|
|
2408
|
+
/**
|
|
2409
|
+
* Return true if a value is in an array
|
|
2410
|
+
*/
|
|
2411
|
+
var includes = function(arr, val) {
|
|
2412
|
+
return notEmpty(arr) && arr.indexOf(val) !== -1;
|
|
2413
|
+
};
|
|
2414
|
+
var datetime = function(y, m, d, h, i, s) {
|
|
2415
|
+
if (h === void 0) h = 0;
|
|
2416
|
+
if (i === void 0) i = 0;
|
|
2417
|
+
if (s === void 0) s = 0;
|
|
2418
|
+
return new Date(Date.UTC(y, m - 1, d, h, i, s));
|
|
2419
|
+
};
|
|
2420
|
+
/**
|
|
2421
|
+
* General date-related utilities.
|
|
2422
|
+
* Also handles several incompatibilities between JavaScript and Python
|
|
2423
|
+
*
|
|
2424
|
+
*/
|
|
2425
|
+
var MONTH_DAYS = [
|
|
2426
|
+
31,
|
|
2427
|
+
28,
|
|
2428
|
+
31,
|
|
2429
|
+
30,
|
|
2430
|
+
31,
|
|
2431
|
+
30,
|
|
2432
|
+
31,
|
|
2433
|
+
31,
|
|
2434
|
+
30,
|
|
2435
|
+
31,
|
|
2436
|
+
30,
|
|
2437
|
+
31
|
|
2438
|
+
];
|
|
2439
|
+
/**
|
|
2440
|
+
* Number of milliseconds of one day
|
|
2441
|
+
*/
|
|
2442
|
+
var ONE_DAY = 1e3 * 60 * 60 * 24;
|
|
2443
|
+
/**
|
|
2444
|
+
* @see: <http://docs.python.org/library/datetime.html#datetime.MAXYEAR>
|
|
2445
|
+
*/
|
|
2446
|
+
var MAXYEAR = 9999;
|
|
2447
|
+
/**
|
|
2448
|
+
* Python uses 1-Jan-1 as the base for calculating ordinals but we don't
|
|
2449
|
+
* want to confuse the JS engine with milliseconds > Number.MAX_NUMBER,
|
|
2450
|
+
* therefore we use 1-Jan-1970 instead
|
|
2451
|
+
*/
|
|
2452
|
+
var ORDINAL_BASE = datetime(1970, 1, 1);
|
|
2453
|
+
/**
|
|
2454
|
+
* Python: MO-SU: 0 - 6
|
|
2455
|
+
* JS: SU-SAT 0 - 6
|
|
2456
|
+
*/
|
|
2457
|
+
var PY_WEEKDAYS = [
|
|
2458
|
+
6,
|
|
2459
|
+
0,
|
|
2460
|
+
1,
|
|
2461
|
+
2,
|
|
2462
|
+
3,
|
|
2463
|
+
4,
|
|
2464
|
+
5
|
|
2465
|
+
];
|
|
2466
|
+
var isLeapYear = function(year) {
|
|
2467
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
2468
|
+
};
|
|
2469
|
+
var isDate = function(value) {
|
|
2470
|
+
return value instanceof Date;
|
|
2471
|
+
};
|
|
2472
|
+
var isValidDate = function(value) {
|
|
2473
|
+
return isDate(value) && !isNaN(value.getTime());
|
|
2474
|
+
};
|
|
2475
|
+
/**
|
|
2476
|
+
* @see: <http://www.mcfedries.com/JavaScript/DaysBetween.asp>
|
|
2477
|
+
*/
|
|
2478
|
+
var daysBetween = function(date1, date2) {
|
|
2479
|
+
var differencems = date1.getTime() - date2.getTime();
|
|
2480
|
+
return Math.round(differencems / ONE_DAY);
|
|
2481
|
+
};
|
|
2482
|
+
/**
|
|
2483
|
+
* @see: <http://docs.python.org/library/datetime.html#datetime.date.toordinal>
|
|
2484
|
+
*/
|
|
2485
|
+
var toOrdinal = function(date) {
|
|
2486
|
+
return daysBetween(date, ORDINAL_BASE);
|
|
2487
|
+
};
|
|
2488
|
+
/**
|
|
2489
|
+
* @see - <http://docs.python.org/library/datetime.html#datetime.date.fromordinal>
|
|
2490
|
+
*/
|
|
2491
|
+
var fromOrdinal = function(ordinal) {
|
|
2492
|
+
return new Date(ORDINAL_BASE.getTime() + ordinal * ONE_DAY);
|
|
2493
|
+
};
|
|
2494
|
+
var getMonthDays = function(date) {
|
|
2495
|
+
var month = date.getUTCMonth();
|
|
2496
|
+
return month === 1 && isLeapYear(date.getUTCFullYear()) ? 29 : MONTH_DAYS[month];
|
|
2497
|
+
};
|
|
2498
|
+
/**
|
|
2499
|
+
* @return {Number} python-like weekday
|
|
2500
|
+
*/
|
|
2501
|
+
var getWeekday = function(date) {
|
|
2502
|
+
return PY_WEEKDAYS[date.getUTCDay()];
|
|
2503
|
+
};
|
|
2504
|
+
/**
|
|
2505
|
+
* @see: <http://docs.python.org/library/calendar.html#calendar.monthrange>
|
|
2506
|
+
*/
|
|
2507
|
+
var monthRange = function(year, month) {
|
|
2508
|
+
var date = datetime(year, month + 1, 1);
|
|
2509
|
+
return [getWeekday(date), getMonthDays(date)];
|
|
2510
|
+
};
|
|
2511
|
+
/**
|
|
2512
|
+
* @see: <http://docs.python.org/library/datetime.html#datetime.datetime.combine>
|
|
2513
|
+
*/
|
|
2514
|
+
var combine = function(date, time) {
|
|
2515
|
+
time = time || date;
|
|
2516
|
+
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds()));
|
|
2517
|
+
};
|
|
2518
|
+
var dateutil_clone = function(date) {
|
|
2519
|
+
return new Date(date.getTime());
|
|
2520
|
+
};
|
|
2521
|
+
var cloneDates = function(dates) {
|
|
2522
|
+
var clones = [];
|
|
2523
|
+
for (var i = 0; i < dates.length; i++) clones.push(dateutil_clone(dates[i]));
|
|
2524
|
+
return clones;
|
|
2525
|
+
};
|
|
2526
|
+
/**
|
|
2527
|
+
* Sorts an array of Date or Time objects
|
|
2528
|
+
*/
|
|
2529
|
+
var sort = function(dates) {
|
|
2530
|
+
dates.sort(function(a, b) {
|
|
2531
|
+
return a.getTime() - b.getTime();
|
|
2532
|
+
});
|
|
2533
|
+
};
|
|
2534
|
+
var timeToUntilString = function(time, utc) {
|
|
2535
|
+
if (utc === void 0) utc = true;
|
|
2536
|
+
var date = new Date(time);
|
|
2537
|
+
return [
|
|
2538
|
+
padStart(date.getUTCFullYear().toString(), 4, "0"),
|
|
2539
|
+
padStart(date.getUTCMonth() + 1, 2, "0"),
|
|
2540
|
+
padStart(date.getUTCDate(), 2, "0"),
|
|
2541
|
+
"T",
|
|
2542
|
+
padStart(date.getUTCHours(), 2, "0"),
|
|
2543
|
+
padStart(date.getUTCMinutes(), 2, "0"),
|
|
2544
|
+
padStart(date.getUTCSeconds(), 2, "0"),
|
|
2545
|
+
utc ? "Z" : ""
|
|
2546
|
+
].join("");
|
|
2547
|
+
};
|
|
2548
|
+
var untilStringToDate = function(until) {
|
|
2549
|
+
var bits = /^(\d{4})(\d{2})(\d{2})(T(\d{2})(\d{2})(\d{2})Z?)?$/.exec(until);
|
|
2550
|
+
if (!bits) throw new Error("Invalid UNTIL value: ".concat(until));
|
|
2551
|
+
return new Date(Date.UTC(parseInt(bits[1], 10), parseInt(bits[2], 10) - 1, parseInt(bits[3], 10), parseInt(bits[5], 10) || 0, parseInt(bits[6], 10) || 0, parseInt(bits[7], 10) || 0));
|
|
2552
|
+
};
|
|
2553
|
+
var dateTZtoISO8601 = function(date, timeZone) {
|
|
2554
|
+
return date.toLocaleString("sv-SE", { timeZone }).replace(" ", "T") + "Z";
|
|
2555
|
+
};
|
|
2556
|
+
var dateInTimeZone = function(date, timeZone) {
|
|
2557
|
+
var localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2558
|
+
var dateInLocalTZ = new Date(dateTZtoISO8601(date, localTimeZone));
|
|
2559
|
+
var tzOffset = new Date(dateTZtoISO8601(date, timeZone !== null && timeZone !== void 0 ? timeZone : "UTC")).getTime() - dateInLocalTZ.getTime();
|
|
2560
|
+
return new Date(date.getTime() - tzOffset);
|
|
2561
|
+
};
|
|
2562
|
+
const iterresult = function() {
|
|
2563
|
+
function IterResult(method, args) {
|
|
2564
|
+
this.minDate = null;
|
|
2565
|
+
this.maxDate = null;
|
|
2566
|
+
this._result = [];
|
|
2567
|
+
this.total = 0;
|
|
2568
|
+
this.method = method;
|
|
2569
|
+
this.args = args;
|
|
2570
|
+
if (method === "between") {
|
|
2571
|
+
this.maxDate = args.inc ? args.before : /* @__PURE__ */ new Date(args.before.getTime() - 1);
|
|
2572
|
+
this.minDate = args.inc ? args.after : new Date(args.after.getTime() + 1);
|
|
2573
|
+
} else if (method === "before") this.maxDate = args.inc ? args.dt : /* @__PURE__ */ new Date(args.dt.getTime() - 1);
|
|
2574
|
+
else if (method === "after") this.minDate = args.inc ? args.dt : new Date(args.dt.getTime() + 1);
|
|
2575
|
+
}
|
|
2576
|
+
/**
|
|
2577
|
+
* Possibly adds a date into the result.
|
|
2578
|
+
*
|
|
2579
|
+
* @param {Date} date - the date isn't necessarly added to the result
|
|
2580
|
+
* list (if it is too late/too early)
|
|
2581
|
+
* @return {Boolean} true if it makes sense to continue the iteration
|
|
2582
|
+
* false if we're done.
|
|
2583
|
+
*/
|
|
2584
|
+
IterResult.prototype.accept = function(date) {
|
|
2585
|
+
++this.total;
|
|
2586
|
+
var tooEarly = this.minDate && date < this.minDate;
|
|
2587
|
+
var tooLate = this.maxDate && date > this.maxDate;
|
|
2588
|
+
if (this.method === "between") {
|
|
2589
|
+
if (tooEarly) return true;
|
|
2590
|
+
if (tooLate) return false;
|
|
2591
|
+
} else if (this.method === "before") {
|
|
2592
|
+
if (tooLate) return false;
|
|
2593
|
+
} else if (this.method === "after") {
|
|
2594
|
+
if (tooEarly) return true;
|
|
2595
|
+
this.add(date);
|
|
2596
|
+
return false;
|
|
2597
|
+
}
|
|
2598
|
+
return this.add(date);
|
|
2599
|
+
};
|
|
2600
|
+
/**
|
|
2601
|
+
*
|
|
2602
|
+
* @param {Date} date that is part of the result.
|
|
2603
|
+
* @return {Boolean} whether we are interested in more values.
|
|
2604
|
+
*/
|
|
2605
|
+
IterResult.prototype.add = function(date) {
|
|
2606
|
+
this._result.push(date);
|
|
2607
|
+
return true;
|
|
2608
|
+
};
|
|
2609
|
+
/**
|
|
2610
|
+
* 'before' and 'after' return only one date, whereas 'all'
|
|
2611
|
+
* and 'between' an array.
|
|
2612
|
+
*
|
|
2613
|
+
* @return {Date,Array?}
|
|
2614
|
+
*/
|
|
2615
|
+
IterResult.prototype.getValue = function() {
|
|
2616
|
+
var res = this._result;
|
|
2617
|
+
switch (this.method) {
|
|
2618
|
+
case "all":
|
|
2619
|
+
case "between": return res;
|
|
2620
|
+
default: return res.length ? res[res.length - 1] : null;
|
|
2621
|
+
}
|
|
2622
|
+
};
|
|
2623
|
+
IterResult.prototype.clone = function() {
|
|
2624
|
+
return new IterResult(this.method, this.args);
|
|
2625
|
+
};
|
|
2626
|
+
return IterResult;
|
|
2627
|
+
}();
|
|
2628
|
+
/******************************************************************************
|
|
2629
|
+
Copyright (c) Microsoft Corporation.
|
|
2630
|
+
|
|
2631
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
2632
|
+
purpose with or without fee is hereby granted.
|
|
2633
|
+
|
|
2634
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2635
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2636
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2637
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2638
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2639
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2640
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
2641
|
+
***************************************************************************** */
|
|
2642
|
+
var extendStatics = function(d, b) {
|
|
2643
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d, b) {
|
|
2644
|
+
d.__proto__ = b;
|
|
2645
|
+
} || function(d, b) {
|
|
2646
|
+
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
2647
|
+
};
|
|
2648
|
+
return extendStatics(d, b);
|
|
2649
|
+
};
|
|
2650
|
+
function __extends(d, b) {
|
|
2651
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
2652
|
+
extendStatics(d, b);
|
|
2653
|
+
function __() {
|
|
2654
|
+
this.constructor = d;
|
|
2655
|
+
}
|
|
2656
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2657
|
+
}
|
|
2658
|
+
var __assign = function() {
|
|
2659
|
+
__assign = Object.assign || function __assign(t) {
|
|
2660
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
2661
|
+
s = arguments[i];
|
|
2662
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
2663
|
+
}
|
|
2664
|
+
return t;
|
|
2665
|
+
};
|
|
2666
|
+
return __assign.apply(this, arguments);
|
|
2667
|
+
};
|
|
2668
|
+
Object.create;
|
|
2669
|
+
function __spreadArray(to, from, pack) {
|
|
2670
|
+
if (pack || arguments.length === 2) {
|
|
2671
|
+
for (var i = 0, l = from.length, ar; i < l; i++) if (ar || !(i in from)) {
|
|
2672
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
2673
|
+
ar[i] = from[i];
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
2677
|
+
}
|
|
2678
|
+
function __await(v) {
|
|
2679
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
2680
|
+
}
|
|
2681
|
+
Object.create;
|
|
2682
|
+
const callbackiterresult = function(_super) {
|
|
2683
|
+
__extends(CallbackIterResult, _super);
|
|
2684
|
+
function CallbackIterResult(method, args, iterator) {
|
|
2685
|
+
var _this = _super.call(this, method, args) || this;
|
|
2686
|
+
_this.iterator = iterator;
|
|
2687
|
+
return _this;
|
|
2688
|
+
}
|
|
2689
|
+
CallbackIterResult.prototype.add = function(date) {
|
|
2690
|
+
if (this.iterator(date, this._result.length)) {
|
|
2691
|
+
this._result.push(date);
|
|
2692
|
+
return true;
|
|
2693
|
+
}
|
|
2694
|
+
return false;
|
|
2695
|
+
};
|
|
2696
|
+
return CallbackIterResult;
|
|
2697
|
+
}(iterresult);
|
|
2698
|
+
const i18n = {
|
|
2699
|
+
dayNames: [
|
|
2700
|
+
"Sunday",
|
|
2701
|
+
"Monday",
|
|
2702
|
+
"Tuesday",
|
|
2703
|
+
"Wednesday",
|
|
2704
|
+
"Thursday",
|
|
2705
|
+
"Friday",
|
|
2706
|
+
"Saturday"
|
|
2707
|
+
],
|
|
2708
|
+
monthNames: [
|
|
2709
|
+
"January",
|
|
2710
|
+
"February",
|
|
2711
|
+
"March",
|
|
2712
|
+
"April",
|
|
2713
|
+
"May",
|
|
2714
|
+
"June",
|
|
2715
|
+
"July",
|
|
2716
|
+
"August",
|
|
2717
|
+
"September",
|
|
2718
|
+
"October",
|
|
2719
|
+
"November",
|
|
2720
|
+
"December"
|
|
2721
|
+
],
|
|
2722
|
+
tokens: {
|
|
2723
|
+
SKIP: /^[ \r\n\t]+|^\.$/,
|
|
2724
|
+
number: /^[1-9][0-9]*/,
|
|
2725
|
+
numberAsText: /^(one|two|three)/i,
|
|
2726
|
+
every: /^every/i,
|
|
2727
|
+
"day(s)": /^days?/i,
|
|
2728
|
+
"weekday(s)": /^weekdays?/i,
|
|
2729
|
+
"week(s)": /^weeks?/i,
|
|
2730
|
+
"hour(s)": /^hours?/i,
|
|
2731
|
+
"minute(s)": /^minutes?/i,
|
|
2732
|
+
"month(s)": /^months?/i,
|
|
2733
|
+
"year(s)": /^years?/i,
|
|
2734
|
+
on: /^(on|in)/i,
|
|
2735
|
+
at: /^(at)/i,
|
|
2736
|
+
the: /^the/i,
|
|
2737
|
+
first: /^first/i,
|
|
2738
|
+
second: /^second/i,
|
|
2739
|
+
third: /^third/i,
|
|
2740
|
+
nth: /^([1-9][0-9]*)(\.|th|nd|rd|st)/i,
|
|
2741
|
+
last: /^last/i,
|
|
2742
|
+
for: /^for/i,
|
|
2743
|
+
"time(s)": /^times?/i,
|
|
2744
|
+
until: /^(un)?til/i,
|
|
2745
|
+
monday: /^mo(n(day)?)?/i,
|
|
2746
|
+
tuesday: /^tu(e(s(day)?)?)?/i,
|
|
2747
|
+
wednesday: /^we(d(n(esday)?)?)?/i,
|
|
2748
|
+
thursday: /^th(u(r(sday)?)?)?/i,
|
|
2749
|
+
friday: /^fr(i(day)?)?/i,
|
|
2750
|
+
saturday: /^sa(t(urday)?)?/i,
|
|
2751
|
+
sunday: /^su(n(day)?)?/i,
|
|
2752
|
+
january: /^jan(uary)?/i,
|
|
2753
|
+
february: /^feb(ruary)?/i,
|
|
2754
|
+
march: /^mar(ch)?/i,
|
|
2755
|
+
april: /^apr(il)?/i,
|
|
2756
|
+
may: /^may/i,
|
|
2757
|
+
june: /^june?/i,
|
|
2758
|
+
july: /^july?/i,
|
|
2759
|
+
august: /^aug(ust)?/i,
|
|
2760
|
+
september: /^sep(t(ember)?)?/i,
|
|
2761
|
+
october: /^oct(ober)?/i,
|
|
2762
|
+
november: /^nov(ember)?/i,
|
|
2763
|
+
december: /^dec(ember)?/i,
|
|
2764
|
+
comma: /^(,\s*|(and|or)\s*)+/i
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
/**
|
|
2768
|
+
* Return true if a value is in an array
|
|
2769
|
+
*/
|
|
2770
|
+
var contains = function(arr, val) {
|
|
2771
|
+
return arr.indexOf(val) !== -1;
|
|
2772
|
+
};
|
|
2773
|
+
var defaultGetText = function(id) {
|
|
2774
|
+
return id.toString();
|
|
2775
|
+
};
|
|
2776
|
+
var defaultDateFormatter = function(year, month, day) {
|
|
2777
|
+
return "".concat(month, " ").concat(day, ", ").concat(year);
|
|
2778
|
+
};
|
|
2779
|
+
const totext = function() {
|
|
2780
|
+
function ToText(rrule, gettext, language, dateFormatter) {
|
|
2781
|
+
if (gettext === void 0) gettext = defaultGetText;
|
|
2782
|
+
if (language === void 0) language = i18n;
|
|
2783
|
+
if (dateFormatter === void 0) dateFormatter = defaultDateFormatter;
|
|
2784
|
+
this.text = [];
|
|
2785
|
+
this.language = language || i18n;
|
|
2786
|
+
this.gettext = gettext;
|
|
2787
|
+
this.dateFormatter = dateFormatter;
|
|
2788
|
+
this.rrule = rrule;
|
|
2789
|
+
this.options = rrule.options;
|
|
2790
|
+
this.origOptions = rrule.origOptions;
|
|
2791
|
+
if (this.origOptions.bymonthday) {
|
|
2792
|
+
var bymonthday = [].concat(this.options.bymonthday);
|
|
2793
|
+
var bynmonthday = [].concat(this.options.bynmonthday);
|
|
2794
|
+
bymonthday.sort(function(a, b) {
|
|
2795
|
+
return a - b;
|
|
2796
|
+
});
|
|
2797
|
+
bynmonthday.sort(function(a, b) {
|
|
2798
|
+
return b - a;
|
|
2799
|
+
});
|
|
2800
|
+
this.bymonthday = bymonthday.concat(bynmonthday);
|
|
2801
|
+
if (!this.bymonthday.length) this.bymonthday = null;
|
|
2802
|
+
}
|
|
2803
|
+
if (isPresent(this.origOptions.byweekday)) {
|
|
2804
|
+
var byweekday = !isArray(this.origOptions.byweekday) ? [this.origOptions.byweekday] : this.origOptions.byweekday;
|
|
2805
|
+
var days = String(byweekday);
|
|
2806
|
+
this.byweekday = {
|
|
2807
|
+
allWeeks: byweekday.filter(function(weekday) {
|
|
2808
|
+
return !weekday.n;
|
|
2809
|
+
}),
|
|
2810
|
+
someWeeks: byweekday.filter(function(weekday) {
|
|
2811
|
+
return Boolean(weekday.n);
|
|
2812
|
+
}),
|
|
2813
|
+
isWeekdays: days.indexOf("MO") !== -1 && days.indexOf("TU") !== -1 && days.indexOf("WE") !== -1 && days.indexOf("TH") !== -1 && days.indexOf("FR") !== -1 && days.indexOf("SA") === -1 && days.indexOf("SU") === -1,
|
|
2814
|
+
isEveryDay: days.indexOf("MO") !== -1 && days.indexOf("TU") !== -1 && days.indexOf("WE") !== -1 && days.indexOf("TH") !== -1 && days.indexOf("FR") !== -1 && days.indexOf("SA") !== -1 && days.indexOf("SU") !== -1
|
|
2815
|
+
};
|
|
2816
|
+
var sortWeekDays = function(a, b) {
|
|
2817
|
+
return a.weekday - b.weekday;
|
|
2818
|
+
};
|
|
2819
|
+
this.byweekday.allWeeks.sort(sortWeekDays);
|
|
2820
|
+
this.byweekday.someWeeks.sort(sortWeekDays);
|
|
2821
|
+
if (!this.byweekday.allWeeks.length) this.byweekday.allWeeks = null;
|
|
2822
|
+
if (!this.byweekday.someWeeks.length) this.byweekday.someWeeks = null;
|
|
2823
|
+
} else this.byweekday = null;
|
|
2824
|
+
}
|
|
2825
|
+
/**
|
|
2826
|
+
* Test whether the rrule can be fully converted to text.
|
|
2827
|
+
*
|
|
2828
|
+
* @param {RRule} rrule
|
|
2829
|
+
* @return {Boolean}
|
|
2830
|
+
*/
|
|
2831
|
+
ToText.isFullyConvertible = function(rrule) {
|
|
2832
|
+
var canConvert = true;
|
|
2833
|
+
if (!(rrule.options.freq in ToText.IMPLEMENTED)) return false;
|
|
2834
|
+
if (rrule.origOptions.until && rrule.origOptions.count) return false;
|
|
2835
|
+
for (var key in rrule.origOptions) {
|
|
2836
|
+
if (contains([
|
|
2837
|
+
"dtstart",
|
|
2838
|
+
"tzid",
|
|
2839
|
+
"wkst",
|
|
2840
|
+
"freq"
|
|
2841
|
+
], key)) return true;
|
|
2842
|
+
if (!contains(ToText.IMPLEMENTED[rrule.options.freq], key)) return false;
|
|
2843
|
+
}
|
|
2844
|
+
return canConvert;
|
|
2845
|
+
};
|
|
2846
|
+
ToText.prototype.isFullyConvertible = function() {
|
|
2847
|
+
return ToText.isFullyConvertible(this.rrule);
|
|
2848
|
+
};
|
|
2849
|
+
/**
|
|
2850
|
+
* Perform the conversion. Only some of the frequencies are supported.
|
|
2851
|
+
* If some of the rrule's options aren't supported, they'll
|
|
2852
|
+
* be omitted from the output an "(~ approximate)" will be appended.
|
|
2853
|
+
*
|
|
2854
|
+
* @return {*}
|
|
2855
|
+
*/
|
|
2856
|
+
ToText.prototype.toString = function() {
|
|
2857
|
+
var gettext = this.gettext;
|
|
2858
|
+
if (!(this.options.freq in ToText.IMPLEMENTED)) return gettext("RRule error: Unable to fully convert this rrule to text");
|
|
2859
|
+
this.text = [gettext("every")];
|
|
2860
|
+
this[RRule.FREQUENCIES[this.options.freq]]();
|
|
2861
|
+
if (this.options.until) {
|
|
2862
|
+
this.add(gettext("until"));
|
|
2863
|
+
var until = this.options.until;
|
|
2864
|
+
this.add(this.dateFormatter(until.getUTCFullYear(), this.language.monthNames[until.getUTCMonth()], until.getUTCDate()));
|
|
2865
|
+
} else if (this.options.count) this.add(gettext("for")).add(this.options.count.toString()).add(this.plural(this.options.count) ? gettext("times") : gettext("time"));
|
|
2866
|
+
if (!this.isFullyConvertible()) this.add(gettext("(~ approximate)"));
|
|
2867
|
+
return this.text.join("");
|
|
2868
|
+
};
|
|
2869
|
+
ToText.prototype.HOURLY = function() {
|
|
2870
|
+
var gettext = this.gettext;
|
|
2871
|
+
if (this.options.interval !== 1) this.add(this.options.interval.toString());
|
|
2872
|
+
this.add(this.plural(this.options.interval) ? gettext("hours") : gettext("hour"));
|
|
2873
|
+
};
|
|
2874
|
+
ToText.prototype.MINUTELY = function() {
|
|
2875
|
+
var gettext = this.gettext;
|
|
2876
|
+
if (this.options.interval !== 1) this.add(this.options.interval.toString());
|
|
2877
|
+
this.add(this.plural(this.options.interval) ? gettext("minutes") : gettext("minute"));
|
|
2878
|
+
};
|
|
2879
|
+
ToText.prototype.DAILY = function() {
|
|
2880
|
+
var gettext = this.gettext;
|
|
2881
|
+
if (this.options.interval !== 1) this.add(this.options.interval.toString());
|
|
2882
|
+
if (this.byweekday && this.byweekday.isWeekdays) this.add(this.plural(this.options.interval) ? gettext("weekdays") : gettext("weekday"));
|
|
2883
|
+
else this.add(this.plural(this.options.interval) ? gettext("days") : gettext("day"));
|
|
2884
|
+
if (this.origOptions.bymonth) {
|
|
2885
|
+
this.add(gettext("in"));
|
|
2886
|
+
this._bymonth();
|
|
2887
|
+
}
|
|
2888
|
+
if (this.bymonthday) this._bymonthday();
|
|
2889
|
+
else if (this.byweekday) this._byweekday();
|
|
2890
|
+
else if (this.origOptions.byhour) this._byhour();
|
|
2891
|
+
};
|
|
2892
|
+
ToText.prototype.WEEKLY = function() {
|
|
2893
|
+
var gettext = this.gettext;
|
|
2894
|
+
if (this.options.interval !== 1) this.add(this.options.interval.toString()).add(this.plural(this.options.interval) ? gettext("weeks") : gettext("week"));
|
|
2895
|
+
if (this.byweekday && this.byweekday.isWeekdays) if (this.options.interval === 1) this.add(this.plural(this.options.interval) ? gettext("weekdays") : gettext("weekday"));
|
|
2896
|
+
else this.add(gettext("on")).add(gettext("weekdays"));
|
|
2897
|
+
else if (this.byweekday && this.byweekday.isEveryDay) this.add(this.plural(this.options.interval) ? gettext("days") : gettext("day"));
|
|
2898
|
+
else {
|
|
2899
|
+
if (this.options.interval === 1) this.add(gettext("week"));
|
|
2900
|
+
if (this.origOptions.bymonth) {
|
|
2901
|
+
this.add(gettext("in"));
|
|
2902
|
+
this._bymonth();
|
|
2903
|
+
}
|
|
2904
|
+
if (this.bymonthday) this._bymonthday();
|
|
2905
|
+
else if (this.byweekday) this._byweekday();
|
|
2906
|
+
if (this.origOptions.byhour) this._byhour();
|
|
2907
|
+
}
|
|
2908
|
+
};
|
|
2909
|
+
ToText.prototype.MONTHLY = function() {
|
|
2910
|
+
var gettext = this.gettext;
|
|
2911
|
+
if (this.origOptions.bymonth) {
|
|
2912
|
+
if (this.options.interval !== 1) {
|
|
2913
|
+
this.add(this.options.interval.toString()).add(gettext("months"));
|
|
2914
|
+
if (this.plural(this.options.interval)) this.add(gettext("in"));
|
|
2915
|
+
}
|
|
2916
|
+
this._bymonth();
|
|
2917
|
+
} else {
|
|
2918
|
+
if (this.options.interval !== 1) this.add(this.options.interval.toString());
|
|
2919
|
+
this.add(this.plural(this.options.interval) ? gettext("months") : gettext("month"));
|
|
2920
|
+
}
|
|
2921
|
+
if (this.bymonthday) this._bymonthday();
|
|
2922
|
+
else if (this.byweekday && this.byweekday.isWeekdays) this.add(gettext("on")).add(gettext("weekdays"));
|
|
2923
|
+
else if (this.byweekday) this._byweekday();
|
|
2924
|
+
};
|
|
2925
|
+
ToText.prototype.YEARLY = function() {
|
|
2926
|
+
var gettext = this.gettext;
|
|
2927
|
+
if (this.origOptions.bymonth) {
|
|
2928
|
+
if (this.options.interval !== 1) {
|
|
2929
|
+
this.add(this.options.interval.toString());
|
|
2930
|
+
this.add(gettext("years"));
|
|
2931
|
+
}
|
|
2932
|
+
this._bymonth();
|
|
2933
|
+
} else {
|
|
2934
|
+
if (this.options.interval !== 1) this.add(this.options.interval.toString());
|
|
2935
|
+
this.add(this.plural(this.options.interval) ? gettext("years") : gettext("year"));
|
|
2936
|
+
}
|
|
2937
|
+
if (this.bymonthday) this._bymonthday();
|
|
2938
|
+
else if (this.byweekday) this._byweekday();
|
|
2939
|
+
if (this.options.byyearday) this.add(gettext("on the")).add(this.list(this.options.byyearday, this.nth, gettext("and"))).add(gettext("day"));
|
|
2940
|
+
if (this.options.byweekno) this.add(gettext("in")).add(this.plural(this.options.byweekno.length) ? gettext("weeks") : gettext("week")).add(this.list(this.options.byweekno, void 0, gettext("and")));
|
|
2941
|
+
};
|
|
2942
|
+
ToText.prototype._bymonthday = function() {
|
|
2943
|
+
var gettext = this.gettext;
|
|
2944
|
+
if (this.byweekday && this.byweekday.allWeeks) this.add(gettext("on")).add(this.list(this.byweekday.allWeeks, this.weekdaytext, gettext("or"))).add(gettext("the")).add(this.list(this.bymonthday, this.nth, gettext("or")));
|
|
2945
|
+
else this.add(gettext("on the")).add(this.list(this.bymonthday, this.nth, gettext("and")));
|
|
2946
|
+
};
|
|
2947
|
+
ToText.prototype._byweekday = function() {
|
|
2948
|
+
var gettext = this.gettext;
|
|
2949
|
+
if (this.byweekday.allWeeks && !this.byweekday.isWeekdays) this.add(gettext("on")).add(this.list(this.byweekday.allWeeks, this.weekdaytext));
|
|
2950
|
+
if (this.byweekday.someWeeks) {
|
|
2951
|
+
if (this.byweekday.allWeeks) this.add(gettext("and"));
|
|
2952
|
+
this.add(gettext("on the")).add(this.list(this.byweekday.someWeeks, this.weekdaytext, gettext("and")));
|
|
2953
|
+
}
|
|
2954
|
+
};
|
|
2955
|
+
ToText.prototype._byhour = function() {
|
|
2956
|
+
var gettext = this.gettext;
|
|
2957
|
+
this.add(gettext("at")).add(this.list(this.origOptions.byhour, void 0, gettext("and")));
|
|
2958
|
+
};
|
|
2959
|
+
ToText.prototype._bymonth = function() {
|
|
2960
|
+
this.add(this.list(this.options.bymonth, this.monthtext, this.gettext("and")));
|
|
2961
|
+
};
|
|
2962
|
+
ToText.prototype.nth = function(n) {
|
|
2963
|
+
n = parseInt(n.toString(), 10);
|
|
2964
|
+
var nth;
|
|
2965
|
+
var gettext = this.gettext;
|
|
2966
|
+
if (n === -1) return gettext("last");
|
|
2967
|
+
var npos = Math.abs(n);
|
|
2968
|
+
switch (npos) {
|
|
2969
|
+
case 1:
|
|
2970
|
+
case 21:
|
|
2971
|
+
case 31:
|
|
2972
|
+
nth = npos + gettext("st");
|
|
2973
|
+
break;
|
|
2974
|
+
case 2:
|
|
2975
|
+
case 22:
|
|
2976
|
+
nth = npos + gettext("nd");
|
|
2977
|
+
break;
|
|
2978
|
+
case 3:
|
|
2979
|
+
case 23:
|
|
2980
|
+
nth = npos + gettext("rd");
|
|
2981
|
+
break;
|
|
2982
|
+
default: nth = npos + gettext("th");
|
|
2983
|
+
}
|
|
2984
|
+
return n < 0 ? nth + " " + gettext("last") : nth;
|
|
2985
|
+
};
|
|
2986
|
+
ToText.prototype.monthtext = function(m) {
|
|
2987
|
+
return this.language.monthNames[m - 1];
|
|
2988
|
+
};
|
|
2989
|
+
ToText.prototype.weekdaytext = function(wday) {
|
|
2990
|
+
var weekday = isNumber(wday) ? (wday + 1) % 7 : wday.getJsWeekday();
|
|
2991
|
+
return (wday.n ? this.nth(wday.n) + " " : "") + this.language.dayNames[weekday];
|
|
2992
|
+
};
|
|
2993
|
+
ToText.prototype.plural = function(n) {
|
|
2994
|
+
return n % 100 !== 1;
|
|
2995
|
+
};
|
|
2996
|
+
ToText.prototype.add = function(s) {
|
|
2997
|
+
this.text.push(" ");
|
|
2998
|
+
this.text.push(s);
|
|
2999
|
+
return this;
|
|
3000
|
+
};
|
|
3001
|
+
ToText.prototype.list = function(arr, callback, finalDelim, delim) {
|
|
3002
|
+
var _this = this;
|
|
3003
|
+
if (delim === void 0) delim = ",";
|
|
3004
|
+
if (!isArray(arr)) arr = [arr];
|
|
3005
|
+
var delimJoin = function(array, delimiter, finalDelimiter) {
|
|
3006
|
+
var list = "";
|
|
3007
|
+
for (var i = 0; i < array.length; i++) {
|
|
3008
|
+
if (i !== 0) if (i === array.length - 1) list += " " + finalDelimiter + " ";
|
|
3009
|
+
else list += delimiter + " ";
|
|
3010
|
+
list += array[i];
|
|
3011
|
+
}
|
|
3012
|
+
return list;
|
|
3013
|
+
};
|
|
3014
|
+
callback = callback || function(o) {
|
|
3015
|
+
return o.toString();
|
|
3016
|
+
};
|
|
3017
|
+
var realCallback = function(arg) {
|
|
3018
|
+
return callback && callback.call(_this, arg);
|
|
3019
|
+
};
|
|
3020
|
+
if (finalDelim) return delimJoin(arr.map(realCallback), delim, finalDelim);
|
|
3021
|
+
else return arr.map(realCallback).join(delim + " ");
|
|
3022
|
+
};
|
|
3023
|
+
return ToText;
|
|
3024
|
+
}();
|
|
3025
|
+
var Parser = function() {
|
|
3026
|
+
function Parser(rules) {
|
|
3027
|
+
this.done = true;
|
|
3028
|
+
this.rules = rules;
|
|
3029
|
+
}
|
|
3030
|
+
Parser.prototype.start = function(text) {
|
|
3031
|
+
this.text = text;
|
|
3032
|
+
this.done = false;
|
|
3033
|
+
return this.nextSymbol();
|
|
3034
|
+
};
|
|
3035
|
+
Parser.prototype.isDone = function() {
|
|
3036
|
+
return this.done && this.symbol === null;
|
|
3037
|
+
};
|
|
3038
|
+
Parser.prototype.nextSymbol = function() {
|
|
3039
|
+
var best;
|
|
3040
|
+
var bestSymbol;
|
|
3041
|
+
this.symbol = null;
|
|
3042
|
+
this.value = null;
|
|
3043
|
+
do {
|
|
3044
|
+
if (this.done) return false;
|
|
3045
|
+
var rule = void 0;
|
|
3046
|
+
best = null;
|
|
3047
|
+
for (var name_1 in this.rules) {
|
|
3048
|
+
rule = this.rules[name_1];
|
|
3049
|
+
var match = rule.exec(this.text);
|
|
3050
|
+
if (match) {
|
|
3051
|
+
if (best === null || match[0].length > best[0].length) {
|
|
3052
|
+
best = match;
|
|
3053
|
+
bestSymbol = name_1;
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
if (best != null) {
|
|
3058
|
+
this.text = this.text.substr(best[0].length);
|
|
3059
|
+
if (this.text === "") this.done = true;
|
|
3060
|
+
}
|
|
3061
|
+
if (best == null) {
|
|
3062
|
+
this.done = true;
|
|
3063
|
+
this.symbol = null;
|
|
3064
|
+
this.value = null;
|
|
3065
|
+
return;
|
|
3066
|
+
}
|
|
3067
|
+
} while (bestSymbol === "SKIP");
|
|
3068
|
+
this.symbol = bestSymbol;
|
|
3069
|
+
this.value = best;
|
|
3070
|
+
return true;
|
|
3071
|
+
};
|
|
3072
|
+
Parser.prototype.accept = function(name) {
|
|
3073
|
+
if (this.symbol === name) {
|
|
3074
|
+
if (this.value) {
|
|
3075
|
+
var v = this.value;
|
|
3076
|
+
this.nextSymbol();
|
|
3077
|
+
return v;
|
|
3078
|
+
}
|
|
3079
|
+
this.nextSymbol();
|
|
3080
|
+
return true;
|
|
3081
|
+
}
|
|
3082
|
+
return false;
|
|
3083
|
+
};
|
|
3084
|
+
Parser.prototype.acceptNumber = function() {
|
|
3085
|
+
return this.accept("number");
|
|
3086
|
+
};
|
|
3087
|
+
Parser.prototype.expect = function(name) {
|
|
3088
|
+
if (this.accept(name)) return true;
|
|
3089
|
+
throw new Error("expected " + name + " but found " + this.symbol);
|
|
3090
|
+
};
|
|
3091
|
+
return Parser;
|
|
3092
|
+
}();
|
|
3093
|
+
function parseText(text, language) {
|
|
3094
|
+
if (language === void 0) language = i18n;
|
|
3095
|
+
var options = {};
|
|
3096
|
+
var ttr = new Parser(language.tokens);
|
|
3097
|
+
if (!ttr.start(text)) return null;
|
|
3098
|
+
S();
|
|
3099
|
+
return options;
|
|
3100
|
+
function S() {
|
|
3101
|
+
ttr.expect("every");
|
|
3102
|
+
var n = ttr.acceptNumber();
|
|
3103
|
+
if (n) options.interval = parseInt(n[0], 10);
|
|
3104
|
+
if (ttr.isDone()) throw new Error("Unexpected end");
|
|
3105
|
+
switch (ttr.symbol) {
|
|
3106
|
+
case "day(s)":
|
|
3107
|
+
options.freq = RRule.DAILY;
|
|
3108
|
+
if (ttr.nextSymbol()) {
|
|
3109
|
+
AT();
|
|
3110
|
+
F();
|
|
3111
|
+
}
|
|
3112
|
+
break;
|
|
3113
|
+
case "weekday(s)":
|
|
3114
|
+
options.freq = RRule.WEEKLY;
|
|
3115
|
+
options.byweekday = [
|
|
3116
|
+
RRule.MO,
|
|
3117
|
+
RRule.TU,
|
|
3118
|
+
RRule.WE,
|
|
3119
|
+
RRule.TH,
|
|
3120
|
+
RRule.FR
|
|
3121
|
+
];
|
|
3122
|
+
ttr.nextSymbol();
|
|
3123
|
+
AT();
|
|
3124
|
+
F();
|
|
3125
|
+
break;
|
|
3126
|
+
case "week(s)":
|
|
3127
|
+
options.freq = RRule.WEEKLY;
|
|
3128
|
+
if (ttr.nextSymbol()) {
|
|
3129
|
+
ON();
|
|
3130
|
+
AT();
|
|
3131
|
+
F();
|
|
3132
|
+
}
|
|
3133
|
+
break;
|
|
3134
|
+
case "hour(s)":
|
|
3135
|
+
options.freq = RRule.HOURLY;
|
|
3136
|
+
if (ttr.nextSymbol()) {
|
|
3137
|
+
ON();
|
|
3138
|
+
F();
|
|
3139
|
+
}
|
|
3140
|
+
break;
|
|
3141
|
+
case "minute(s)":
|
|
3142
|
+
options.freq = RRule.MINUTELY;
|
|
3143
|
+
if (ttr.nextSymbol()) {
|
|
3144
|
+
ON();
|
|
3145
|
+
F();
|
|
3146
|
+
}
|
|
3147
|
+
break;
|
|
3148
|
+
case "month(s)":
|
|
3149
|
+
options.freq = RRule.MONTHLY;
|
|
3150
|
+
if (ttr.nextSymbol()) {
|
|
3151
|
+
ON();
|
|
3152
|
+
F();
|
|
3153
|
+
}
|
|
3154
|
+
break;
|
|
3155
|
+
case "year(s)":
|
|
3156
|
+
options.freq = RRule.YEARLY;
|
|
3157
|
+
if (ttr.nextSymbol()) {
|
|
3158
|
+
ON();
|
|
3159
|
+
F();
|
|
3160
|
+
}
|
|
3161
|
+
break;
|
|
3162
|
+
case "monday":
|
|
3163
|
+
case "tuesday":
|
|
3164
|
+
case "wednesday":
|
|
3165
|
+
case "thursday":
|
|
3166
|
+
case "friday":
|
|
3167
|
+
case "saturday":
|
|
3168
|
+
case "sunday":
|
|
3169
|
+
options.freq = RRule.WEEKLY;
|
|
3170
|
+
options.byweekday = [RRule[ttr.symbol.substr(0, 2).toUpperCase()]];
|
|
3171
|
+
if (!ttr.nextSymbol()) return;
|
|
3172
|
+
while (ttr.accept("comma")) {
|
|
3173
|
+
if (ttr.isDone()) throw new Error("Unexpected end");
|
|
3174
|
+
var wkd = decodeWKD();
|
|
3175
|
+
if (!wkd) throw new Error("Unexpected symbol " + ttr.symbol + ", expected weekday");
|
|
3176
|
+
options.byweekday.push(RRule[wkd]);
|
|
3177
|
+
ttr.nextSymbol();
|
|
3178
|
+
}
|
|
3179
|
+
AT();
|
|
3180
|
+
MDAYs();
|
|
3181
|
+
F();
|
|
3182
|
+
break;
|
|
3183
|
+
case "january":
|
|
3184
|
+
case "february":
|
|
3185
|
+
case "march":
|
|
3186
|
+
case "april":
|
|
3187
|
+
case "may":
|
|
3188
|
+
case "june":
|
|
3189
|
+
case "july":
|
|
3190
|
+
case "august":
|
|
3191
|
+
case "september":
|
|
3192
|
+
case "october":
|
|
3193
|
+
case "november":
|
|
3194
|
+
case "december":
|
|
3195
|
+
options.freq = RRule.YEARLY;
|
|
3196
|
+
options.bymonth = [decodeM()];
|
|
3197
|
+
if (!ttr.nextSymbol()) return;
|
|
3198
|
+
while (ttr.accept("comma")) {
|
|
3199
|
+
if (ttr.isDone()) throw new Error("Unexpected end");
|
|
3200
|
+
var m = decodeM();
|
|
3201
|
+
if (!m) throw new Error("Unexpected symbol " + ttr.symbol + ", expected month");
|
|
3202
|
+
options.bymonth.push(m);
|
|
3203
|
+
ttr.nextSymbol();
|
|
3204
|
+
}
|
|
3205
|
+
ON();
|
|
3206
|
+
F();
|
|
3207
|
+
break;
|
|
3208
|
+
default: throw new Error("Unknown symbol");
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
function ON() {
|
|
3212
|
+
var on = ttr.accept("on");
|
|
3213
|
+
var the = ttr.accept("the");
|
|
3214
|
+
if (!(on || the)) return;
|
|
3215
|
+
do {
|
|
3216
|
+
var nth = decodeNTH();
|
|
3217
|
+
var wkd = decodeWKD();
|
|
3218
|
+
var m = decodeM();
|
|
3219
|
+
if (nth) if (wkd) {
|
|
3220
|
+
ttr.nextSymbol();
|
|
3221
|
+
if (!options.byweekday) options.byweekday = [];
|
|
3222
|
+
options.byweekday.push(RRule[wkd].nth(nth));
|
|
3223
|
+
} else {
|
|
3224
|
+
if (!options.bymonthday) options.bymonthday = [];
|
|
3225
|
+
options.bymonthday.push(nth);
|
|
3226
|
+
ttr.accept("day(s)");
|
|
3227
|
+
}
|
|
3228
|
+
else if (wkd) {
|
|
3229
|
+
ttr.nextSymbol();
|
|
3230
|
+
if (!options.byweekday) options.byweekday = [];
|
|
3231
|
+
options.byweekday.push(RRule[wkd]);
|
|
3232
|
+
} else if (ttr.symbol === "weekday(s)") {
|
|
3233
|
+
ttr.nextSymbol();
|
|
3234
|
+
if (!options.byweekday) options.byweekday = [
|
|
3235
|
+
RRule.MO,
|
|
3236
|
+
RRule.TU,
|
|
3237
|
+
RRule.WE,
|
|
3238
|
+
RRule.TH,
|
|
3239
|
+
RRule.FR
|
|
3240
|
+
];
|
|
3241
|
+
} else if (ttr.symbol === "week(s)") {
|
|
3242
|
+
ttr.nextSymbol();
|
|
3243
|
+
var n = ttr.acceptNumber();
|
|
3244
|
+
if (!n) throw new Error("Unexpected symbol " + ttr.symbol + ", expected week number");
|
|
3245
|
+
options.byweekno = [parseInt(n[0], 10)];
|
|
3246
|
+
while (ttr.accept("comma")) {
|
|
3247
|
+
n = ttr.acceptNumber();
|
|
3248
|
+
if (!n) throw new Error("Unexpected symbol " + ttr.symbol + "; expected monthday");
|
|
3249
|
+
options.byweekno.push(parseInt(n[0], 10));
|
|
3250
|
+
}
|
|
3251
|
+
} else if (m) {
|
|
3252
|
+
ttr.nextSymbol();
|
|
3253
|
+
if (!options.bymonth) options.bymonth = [];
|
|
3254
|
+
options.bymonth.push(m);
|
|
3255
|
+
} else return;
|
|
3256
|
+
} while (ttr.accept("comma") || ttr.accept("the") || ttr.accept("on"));
|
|
3257
|
+
}
|
|
3258
|
+
function AT() {
|
|
3259
|
+
if (!ttr.accept("at")) return;
|
|
3260
|
+
do {
|
|
3261
|
+
var n = ttr.acceptNumber();
|
|
3262
|
+
if (!n) throw new Error("Unexpected symbol " + ttr.symbol + ", expected hour");
|
|
3263
|
+
options.byhour = [parseInt(n[0], 10)];
|
|
3264
|
+
while (ttr.accept("comma")) {
|
|
3265
|
+
n = ttr.acceptNumber();
|
|
3266
|
+
if (!n) throw new Error("Unexpected symbol " + ttr.symbol + "; expected hour");
|
|
3267
|
+
options.byhour.push(parseInt(n[0], 10));
|
|
3268
|
+
}
|
|
3269
|
+
} while (ttr.accept("comma") || ttr.accept("at"));
|
|
3270
|
+
}
|
|
3271
|
+
function decodeM() {
|
|
3272
|
+
switch (ttr.symbol) {
|
|
3273
|
+
case "january": return 1;
|
|
3274
|
+
case "february": return 2;
|
|
3275
|
+
case "march": return 3;
|
|
3276
|
+
case "april": return 4;
|
|
3277
|
+
case "may": return 5;
|
|
3278
|
+
case "june": return 6;
|
|
3279
|
+
case "july": return 7;
|
|
3280
|
+
case "august": return 8;
|
|
3281
|
+
case "september": return 9;
|
|
3282
|
+
case "october": return 10;
|
|
3283
|
+
case "november": return 11;
|
|
3284
|
+
case "december": return 12;
|
|
3285
|
+
default: return false;
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
function decodeWKD() {
|
|
3289
|
+
switch (ttr.symbol) {
|
|
3290
|
+
case "monday":
|
|
3291
|
+
case "tuesday":
|
|
3292
|
+
case "wednesday":
|
|
3293
|
+
case "thursday":
|
|
3294
|
+
case "friday":
|
|
3295
|
+
case "saturday":
|
|
3296
|
+
case "sunday": return ttr.symbol.substr(0, 2).toUpperCase();
|
|
3297
|
+
default: return false;
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
function decodeNTH() {
|
|
3301
|
+
switch (ttr.symbol) {
|
|
3302
|
+
case "last":
|
|
3303
|
+
ttr.nextSymbol();
|
|
3304
|
+
return -1;
|
|
3305
|
+
case "first":
|
|
3306
|
+
ttr.nextSymbol();
|
|
3307
|
+
return 1;
|
|
3308
|
+
case "second":
|
|
3309
|
+
ttr.nextSymbol();
|
|
3310
|
+
return ttr.accept("last") ? -2 : 2;
|
|
3311
|
+
case "third":
|
|
3312
|
+
ttr.nextSymbol();
|
|
3313
|
+
return ttr.accept("last") ? -3 : 3;
|
|
3314
|
+
case "nth":
|
|
3315
|
+
var v = parseInt(ttr.value[1], 10);
|
|
3316
|
+
if (v < -366 || v > 366) throw new Error("Nth out of range: " + v);
|
|
3317
|
+
ttr.nextSymbol();
|
|
3318
|
+
return ttr.accept("last") ? -v : v;
|
|
3319
|
+
default: return false;
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
function MDAYs() {
|
|
3323
|
+
ttr.accept("on");
|
|
3324
|
+
ttr.accept("the");
|
|
3325
|
+
var nth = decodeNTH();
|
|
3326
|
+
if (!nth) return;
|
|
3327
|
+
options.bymonthday = [nth];
|
|
3328
|
+
ttr.nextSymbol();
|
|
3329
|
+
while (ttr.accept("comma")) {
|
|
3330
|
+
nth = decodeNTH();
|
|
3331
|
+
if (!nth) throw new Error("Unexpected symbol " + ttr.symbol + "; expected monthday");
|
|
3332
|
+
options.bymonthday.push(nth);
|
|
3333
|
+
ttr.nextSymbol();
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
function F() {
|
|
3337
|
+
if (ttr.symbol === "until") {
|
|
3338
|
+
var date = Date.parse(ttr.text);
|
|
3339
|
+
if (!date) throw new Error("Cannot parse until date:" + ttr.text);
|
|
3340
|
+
options.until = new Date(date);
|
|
3341
|
+
} else if (ttr.accept("for")) {
|
|
3342
|
+
options.count = parseInt(ttr.value[0], 10);
|
|
3343
|
+
ttr.expect("number");
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
var Frequency;
|
|
3348
|
+
(function(Frequency) {
|
|
3349
|
+
Frequency[Frequency["YEARLY"] = 0] = "YEARLY";
|
|
3350
|
+
Frequency[Frequency["MONTHLY"] = 1] = "MONTHLY";
|
|
3351
|
+
Frequency[Frequency["WEEKLY"] = 2] = "WEEKLY";
|
|
3352
|
+
Frequency[Frequency["DAILY"] = 3] = "DAILY";
|
|
3353
|
+
Frequency[Frequency["HOURLY"] = 4] = "HOURLY";
|
|
3354
|
+
Frequency[Frequency["MINUTELY"] = 5] = "MINUTELY";
|
|
3355
|
+
Frequency[Frequency["SECONDLY"] = 6] = "SECONDLY";
|
|
3356
|
+
})(Frequency || (Frequency = {}));
|
|
3357
|
+
function freqIsDailyOrGreater(freq) {
|
|
3358
|
+
return freq < Frequency.HOURLY;
|
|
3359
|
+
}
|
|
3360
|
+
/**
|
|
3361
|
+
*
|
|
3362
|
+
* Implementation of RRule.fromText() and RRule::toText().
|
|
3363
|
+
*
|
|
3364
|
+
*
|
|
3365
|
+
* On the client side, this file needs to be included
|
|
3366
|
+
* when those functions are used.
|
|
3367
|
+
*
|
|
3368
|
+
*/
|
|
3369
|
+
/**
|
|
3370
|
+
* Will be able to convert some of the below described rules from
|
|
3371
|
+
* text format to a rule object.
|
|
3372
|
+
*
|
|
3373
|
+
*
|
|
3374
|
+
* RULES
|
|
3375
|
+
*
|
|
3376
|
+
* Every ([n])
|
|
3377
|
+
* day(s)
|
|
3378
|
+
* | [weekday], ..., (and) [weekday]
|
|
3379
|
+
* | weekday(s)
|
|
3380
|
+
* | week(s)
|
|
3381
|
+
* | month(s)
|
|
3382
|
+
* | [month], ..., (and) [month]
|
|
3383
|
+
* | year(s)
|
|
3384
|
+
*
|
|
3385
|
+
*
|
|
3386
|
+
* Plus 0, 1, or multiple of these:
|
|
3387
|
+
*
|
|
3388
|
+
* on [weekday], ..., (or) [weekday] the [monthday], [monthday], ... (or) [monthday]
|
|
3389
|
+
*
|
|
3390
|
+
* on [weekday], ..., (and) [weekday]
|
|
3391
|
+
*
|
|
3392
|
+
* on the [monthday], [monthday], ... (and) [monthday] (day of the month)
|
|
3393
|
+
*
|
|
3394
|
+
* on the [nth-weekday], ..., (and) [nth-weekday] (of the month/year)
|
|
3395
|
+
*
|
|
3396
|
+
*
|
|
3397
|
+
* Plus 0 or 1 of these:
|
|
3398
|
+
*
|
|
3399
|
+
* for [n] time(s)
|
|
3400
|
+
*
|
|
3401
|
+
* until [date]
|
|
3402
|
+
*
|
|
3403
|
+
* Plus (.)
|
|
3404
|
+
*
|
|
3405
|
+
*
|
|
3406
|
+
* Definitely no supported for parsing:
|
|
3407
|
+
*
|
|
3408
|
+
* (for year):
|
|
3409
|
+
* in week(s) [n], ..., (and) [n]
|
|
3410
|
+
*
|
|
3411
|
+
* on the [yearday], ..., (and) [n] day of the year
|
|
3412
|
+
* on day [yearday], ..., (and) [n]
|
|
3413
|
+
*
|
|
3414
|
+
*
|
|
3415
|
+
* NON-TERMINALS
|
|
3416
|
+
*
|
|
3417
|
+
* [n]: 1, 2 ..., one, two, three ..
|
|
3418
|
+
* [month]: January, February, March, April, May, ... December
|
|
3419
|
+
* [weekday]: Monday, ... Sunday
|
|
3420
|
+
* [nth-weekday]: first [weekday], 2nd [weekday], ... last [weekday], ...
|
|
3421
|
+
* [monthday]: first, 1., 2., 1st, 2nd, second, ... 31st, last day, 2nd last day, ..
|
|
3422
|
+
* [date]:
|
|
3423
|
+
* - [month] (0-31(,) ([year])),
|
|
3424
|
+
* - (the) 0-31.(1-12.([year])),
|
|
3425
|
+
* - (the) 0-31/(1-12/([year])),
|
|
3426
|
+
* - [weekday]
|
|
3427
|
+
*
|
|
3428
|
+
* [year]: 0000, 0001, ... 01, 02, ..
|
|
3429
|
+
*
|
|
3430
|
+
* Definitely not supported for parsing:
|
|
3431
|
+
*
|
|
3432
|
+
* [yearday]: first, 1., 2., 1st, 2nd, second, ... 366th, last day, 2nd last day, ..
|
|
3433
|
+
*
|
|
3434
|
+
* @param {String} text
|
|
3435
|
+
* @return {Object, Boolean} the rule, or null.
|
|
3436
|
+
*/
|
|
3437
|
+
var fromText = function(text, language) {
|
|
3438
|
+
if (language === void 0) language = i18n;
|
|
3439
|
+
return new RRule(parseText(text, language) || void 0);
|
|
3440
|
+
};
|
|
3441
|
+
var common = [
|
|
3442
|
+
"count",
|
|
3443
|
+
"until",
|
|
3444
|
+
"interval",
|
|
3445
|
+
"byweekday",
|
|
3446
|
+
"bymonthday",
|
|
3447
|
+
"bymonth"
|
|
3448
|
+
];
|
|
3449
|
+
totext.IMPLEMENTED = [];
|
|
3450
|
+
totext.IMPLEMENTED[Frequency.HOURLY] = common;
|
|
3451
|
+
totext.IMPLEMENTED[Frequency.MINUTELY] = common;
|
|
3452
|
+
totext.IMPLEMENTED[Frequency.DAILY] = ["byhour"].concat(common);
|
|
3453
|
+
totext.IMPLEMENTED[Frequency.WEEKLY] = common;
|
|
3454
|
+
totext.IMPLEMENTED[Frequency.MONTHLY] = common;
|
|
3455
|
+
totext.IMPLEMENTED[Frequency.YEARLY] = ["byweekno", "byyearday"].concat(common);
|
|
3456
|
+
var toText = function(rrule, gettext, language, dateFormatter) {
|
|
3457
|
+
return new totext(rrule, gettext, language, dateFormatter).toString();
|
|
3458
|
+
};
|
|
3459
|
+
var isFullyConvertible = totext.isFullyConvertible;
|
|
3460
|
+
var Time = function() {
|
|
3461
|
+
function Time(hour, minute, second, millisecond) {
|
|
3462
|
+
this.hour = hour;
|
|
3463
|
+
this.minute = minute;
|
|
3464
|
+
this.second = second;
|
|
3465
|
+
this.millisecond = millisecond || 0;
|
|
3466
|
+
}
|
|
3467
|
+
Time.prototype.getHours = function() {
|
|
3468
|
+
return this.hour;
|
|
3469
|
+
};
|
|
3470
|
+
Time.prototype.getMinutes = function() {
|
|
3471
|
+
return this.minute;
|
|
3472
|
+
};
|
|
3473
|
+
Time.prototype.getSeconds = function() {
|
|
3474
|
+
return this.second;
|
|
3475
|
+
};
|
|
3476
|
+
Time.prototype.getMilliseconds = function() {
|
|
3477
|
+
return this.millisecond;
|
|
3478
|
+
};
|
|
3479
|
+
Time.prototype.getTime = function() {
|
|
3480
|
+
return (this.hour * 60 * 60 + this.minute * 60 + this.second) * 1e3 + this.millisecond;
|
|
3481
|
+
};
|
|
3482
|
+
return Time;
|
|
3483
|
+
}();
|
|
3484
|
+
var DateTime = function(_super) {
|
|
3485
|
+
__extends(DateTime, _super);
|
|
3486
|
+
function DateTime(year, month, day, hour, minute, second, millisecond) {
|
|
3487
|
+
var _this = _super.call(this, hour, minute, second, millisecond) || this;
|
|
3488
|
+
_this.year = year;
|
|
3489
|
+
_this.month = month;
|
|
3490
|
+
_this.day = day;
|
|
3491
|
+
return _this;
|
|
3492
|
+
}
|
|
3493
|
+
DateTime.fromDate = function(date) {
|
|
3494
|
+
return new this(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.valueOf() % 1e3);
|
|
3495
|
+
};
|
|
3496
|
+
DateTime.prototype.getWeekday = function() {
|
|
3497
|
+
return getWeekday(new Date(this.getTime()));
|
|
3498
|
+
};
|
|
3499
|
+
DateTime.prototype.getTime = function() {
|
|
3500
|
+
return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond)).getTime();
|
|
3501
|
+
};
|
|
3502
|
+
DateTime.prototype.getDay = function() {
|
|
3503
|
+
return this.day;
|
|
3504
|
+
};
|
|
3505
|
+
DateTime.prototype.getMonth = function() {
|
|
3506
|
+
return this.month;
|
|
3507
|
+
};
|
|
3508
|
+
DateTime.prototype.getYear = function() {
|
|
3509
|
+
return this.year;
|
|
3510
|
+
};
|
|
3511
|
+
DateTime.prototype.addYears = function(years) {
|
|
3512
|
+
this.year += years;
|
|
3513
|
+
};
|
|
3514
|
+
DateTime.prototype.addMonths = function(months) {
|
|
3515
|
+
this.month += months;
|
|
3516
|
+
if (this.month > 12) {
|
|
3517
|
+
var yearDiv = Math.floor(this.month / 12);
|
|
3518
|
+
this.month = pymod(this.month, 12);
|
|
3519
|
+
this.year += yearDiv;
|
|
3520
|
+
if (this.month === 0) {
|
|
3521
|
+
this.month = 12;
|
|
3522
|
+
--this.year;
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
};
|
|
3526
|
+
DateTime.prototype.addWeekly = function(days, wkst) {
|
|
3527
|
+
if (wkst > this.getWeekday()) this.day += -(this.getWeekday() + 1 + (6 - wkst)) + days * 7;
|
|
3528
|
+
else this.day += -(this.getWeekday() - wkst) + days * 7;
|
|
3529
|
+
this.fixDay();
|
|
3530
|
+
};
|
|
3531
|
+
DateTime.prototype.addDaily = function(days) {
|
|
3532
|
+
this.day += days;
|
|
3533
|
+
this.fixDay();
|
|
3534
|
+
};
|
|
3535
|
+
DateTime.prototype.addHours = function(hours, filtered, byhour) {
|
|
3536
|
+
if (filtered) this.hour += Math.floor((23 - this.hour) / hours) * hours;
|
|
3537
|
+
for (;;) {
|
|
3538
|
+
this.hour += hours;
|
|
3539
|
+
var _a = divmod(this.hour, 24), dayDiv = _a.div, hourMod = _a.mod;
|
|
3540
|
+
if (dayDiv) {
|
|
3541
|
+
this.hour = hourMod;
|
|
3542
|
+
this.addDaily(dayDiv);
|
|
3543
|
+
}
|
|
3544
|
+
if (empty(byhour) || includes(byhour, this.hour)) break;
|
|
3545
|
+
}
|
|
3546
|
+
};
|
|
3547
|
+
DateTime.prototype.addMinutes = function(minutes, filtered, byhour, byminute) {
|
|
3548
|
+
if (filtered) this.minute += Math.floor((1439 - (this.hour * 60 + this.minute)) / minutes) * minutes;
|
|
3549
|
+
for (;;) {
|
|
3550
|
+
this.minute += minutes;
|
|
3551
|
+
var _a = divmod(this.minute, 60), hourDiv = _a.div, minuteMod = _a.mod;
|
|
3552
|
+
if (hourDiv) {
|
|
3553
|
+
this.minute = minuteMod;
|
|
3554
|
+
this.addHours(hourDiv, false, byhour);
|
|
3555
|
+
}
|
|
3556
|
+
if ((empty(byhour) || includes(byhour, this.hour)) && (empty(byminute) || includes(byminute, this.minute))) break;
|
|
3557
|
+
}
|
|
3558
|
+
};
|
|
3559
|
+
DateTime.prototype.addSeconds = function(seconds, filtered, byhour, byminute, bysecond) {
|
|
3560
|
+
if (filtered) this.second += Math.floor((86399 - (this.hour * 3600 + this.minute * 60 + this.second)) / seconds) * seconds;
|
|
3561
|
+
for (;;) {
|
|
3562
|
+
this.second += seconds;
|
|
3563
|
+
var _a = divmod(this.second, 60), minuteDiv = _a.div, secondMod = _a.mod;
|
|
3564
|
+
if (minuteDiv) {
|
|
3565
|
+
this.second = secondMod;
|
|
3566
|
+
this.addMinutes(minuteDiv, false, byhour, byminute);
|
|
3567
|
+
}
|
|
3568
|
+
if ((empty(byhour) || includes(byhour, this.hour)) && (empty(byminute) || includes(byminute, this.minute)) && (empty(bysecond) || includes(bysecond, this.second))) break;
|
|
3569
|
+
}
|
|
3570
|
+
};
|
|
3571
|
+
DateTime.prototype.fixDay = function() {
|
|
3572
|
+
if (this.day <= 28) return;
|
|
3573
|
+
var daysinmonth = monthRange(this.year, this.month - 1)[1];
|
|
3574
|
+
if (this.day <= daysinmonth) return;
|
|
3575
|
+
while (this.day > daysinmonth) {
|
|
3576
|
+
this.day -= daysinmonth;
|
|
3577
|
+
++this.month;
|
|
3578
|
+
if (this.month === 13) {
|
|
3579
|
+
this.month = 1;
|
|
3580
|
+
++this.year;
|
|
3581
|
+
if (this.year > MAXYEAR) return;
|
|
3582
|
+
}
|
|
3583
|
+
daysinmonth = monthRange(this.year, this.month - 1)[1];
|
|
3584
|
+
}
|
|
3585
|
+
};
|
|
3586
|
+
DateTime.prototype.add = function(options, filtered) {
|
|
3587
|
+
var freq = options.freq, interval = options.interval, wkst = options.wkst, byhour = options.byhour, byminute = options.byminute, bysecond = options.bysecond;
|
|
3588
|
+
switch (freq) {
|
|
3589
|
+
case Frequency.YEARLY: return this.addYears(interval);
|
|
3590
|
+
case Frequency.MONTHLY: return this.addMonths(interval);
|
|
3591
|
+
case Frequency.WEEKLY: return this.addWeekly(interval, wkst);
|
|
3592
|
+
case Frequency.DAILY: return this.addDaily(interval);
|
|
3593
|
+
case Frequency.HOURLY: return this.addHours(interval, filtered, byhour);
|
|
3594
|
+
case Frequency.MINUTELY: return this.addMinutes(interval, filtered, byhour, byminute);
|
|
3595
|
+
case Frequency.SECONDLY: return this.addSeconds(interval, filtered, byhour, byminute, bysecond);
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3598
|
+
return DateTime;
|
|
3599
|
+
}(Time);
|
|
3600
|
+
function initializeOptions(options) {
|
|
3601
|
+
var invalid = [];
|
|
3602
|
+
var keys = Object.keys(options);
|
|
3603
|
+
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
3604
|
+
var key = keys_1[_i];
|
|
3605
|
+
if (!includes(defaultKeys, key)) invalid.push(key);
|
|
3606
|
+
if (isDate(options[key]) && !isValidDate(options[key])) invalid.push(key);
|
|
3607
|
+
}
|
|
3608
|
+
if (invalid.length) throw new Error("Invalid options: " + invalid.join(", "));
|
|
3609
|
+
return __assign({}, options);
|
|
3610
|
+
}
|
|
3611
|
+
function parseOptions(options) {
|
|
3612
|
+
var opts = __assign(__assign({}, DEFAULT_OPTIONS), initializeOptions(options));
|
|
3613
|
+
if (isPresent(opts.byeaster)) opts.freq = RRule.YEARLY;
|
|
3614
|
+
if (!(isPresent(opts.freq) && RRule.FREQUENCIES[opts.freq])) throw new Error("Invalid frequency: ".concat(opts.freq, " ").concat(options.freq));
|
|
3615
|
+
if (!opts.dtstart) opts.dtstart = new Date((/* @__PURE__ */ new Date()).setMilliseconds(0));
|
|
3616
|
+
if (!isPresent(opts.wkst)) opts.wkst = RRule.MO.weekday;
|
|
3617
|
+
else if (isNumber(opts.wkst)) {} else opts.wkst = opts.wkst.weekday;
|
|
3618
|
+
if (isPresent(opts.bysetpos)) {
|
|
3619
|
+
if (isNumber(opts.bysetpos)) opts.bysetpos = [opts.bysetpos];
|
|
3620
|
+
for (var i = 0; i < opts.bysetpos.length; i++) {
|
|
3621
|
+
var v = opts.bysetpos[i];
|
|
3622
|
+
if (v === 0 || !(v >= -366 && v <= 366)) throw new Error("bysetpos must be between 1 and 366, or between -366 and -1");
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
if (!(Boolean(opts.byweekno) || notEmpty(opts.byweekno) || notEmpty(opts.byyearday) || Boolean(opts.bymonthday) || notEmpty(opts.bymonthday) || isPresent(opts.byweekday) || isPresent(opts.byeaster))) switch (opts.freq) {
|
|
3626
|
+
case RRule.YEARLY:
|
|
3627
|
+
if (!opts.bymonth) opts.bymonth = opts.dtstart.getUTCMonth() + 1;
|
|
3628
|
+
opts.bymonthday = opts.dtstart.getUTCDate();
|
|
3629
|
+
break;
|
|
3630
|
+
case RRule.MONTHLY:
|
|
3631
|
+
opts.bymonthday = opts.dtstart.getUTCDate();
|
|
3632
|
+
break;
|
|
3633
|
+
case RRule.WEEKLY:
|
|
3634
|
+
opts.byweekday = [getWeekday(opts.dtstart)];
|
|
3635
|
+
break;
|
|
3636
|
+
}
|
|
3637
|
+
if (isPresent(opts.bymonth) && !isArray(opts.bymonth)) opts.bymonth = [opts.bymonth];
|
|
3638
|
+
if (isPresent(opts.byyearday) && !isArray(opts.byyearday) && isNumber(opts.byyearday)) opts.byyearday = [opts.byyearday];
|
|
3639
|
+
if (!isPresent(opts.bymonthday)) {
|
|
3640
|
+
opts.bymonthday = [];
|
|
3641
|
+
opts.bynmonthday = [];
|
|
3642
|
+
} else if (isArray(opts.bymonthday)) {
|
|
3643
|
+
var bymonthday = [];
|
|
3644
|
+
var bynmonthday = [];
|
|
3645
|
+
for (var i = 0; i < opts.bymonthday.length; i++) {
|
|
3646
|
+
var v = opts.bymonthday[i];
|
|
3647
|
+
if (v > 0) bymonthday.push(v);
|
|
3648
|
+
else if (v < 0) bynmonthday.push(v);
|
|
3649
|
+
}
|
|
3650
|
+
opts.bymonthday = bymonthday;
|
|
3651
|
+
opts.bynmonthday = bynmonthday;
|
|
3652
|
+
} else if (opts.bymonthday < 0) {
|
|
3653
|
+
opts.bynmonthday = [opts.bymonthday];
|
|
3654
|
+
opts.bymonthday = [];
|
|
3655
|
+
} else {
|
|
3656
|
+
opts.bynmonthday = [];
|
|
3657
|
+
opts.bymonthday = [opts.bymonthday];
|
|
3658
|
+
}
|
|
3659
|
+
if (isPresent(opts.byweekno) && !isArray(opts.byweekno)) opts.byweekno = [opts.byweekno];
|
|
3660
|
+
if (!isPresent(opts.byweekday)) opts.bynweekday = null;
|
|
3661
|
+
else if (isNumber(opts.byweekday)) {
|
|
3662
|
+
opts.byweekday = [opts.byweekday];
|
|
3663
|
+
opts.bynweekday = null;
|
|
3664
|
+
} else if (isWeekdayStr(opts.byweekday)) {
|
|
3665
|
+
opts.byweekday = [Weekday.fromStr(opts.byweekday).weekday];
|
|
3666
|
+
opts.bynweekday = null;
|
|
3667
|
+
} else if (opts.byweekday instanceof Weekday) if (!opts.byweekday.n || opts.freq > RRule.MONTHLY) {
|
|
3668
|
+
opts.byweekday = [opts.byweekday.weekday];
|
|
3669
|
+
opts.bynweekday = null;
|
|
3670
|
+
} else {
|
|
3671
|
+
opts.bynweekday = [[opts.byweekday.weekday, opts.byweekday.n]];
|
|
3672
|
+
opts.byweekday = null;
|
|
3673
|
+
}
|
|
3674
|
+
else {
|
|
3675
|
+
var byweekday = [];
|
|
3676
|
+
var bynweekday = [];
|
|
3677
|
+
for (var i = 0; i < opts.byweekday.length; i++) {
|
|
3678
|
+
var wday = opts.byweekday[i];
|
|
3679
|
+
if (isNumber(wday)) {
|
|
3680
|
+
byweekday.push(wday);
|
|
3681
|
+
continue;
|
|
3682
|
+
} else if (isWeekdayStr(wday)) {
|
|
3683
|
+
byweekday.push(Weekday.fromStr(wday).weekday);
|
|
3684
|
+
continue;
|
|
3685
|
+
}
|
|
3686
|
+
if (!wday.n || opts.freq > RRule.MONTHLY) byweekday.push(wday.weekday);
|
|
3687
|
+
else bynweekday.push([wday.weekday, wday.n]);
|
|
3688
|
+
}
|
|
3689
|
+
opts.byweekday = notEmpty(byweekday) ? byweekday : null;
|
|
3690
|
+
opts.bynweekday = notEmpty(bynweekday) ? bynweekday : null;
|
|
3691
|
+
}
|
|
3692
|
+
if (!isPresent(opts.byhour)) opts.byhour = opts.freq < RRule.HOURLY ? [opts.dtstart.getUTCHours()] : null;
|
|
3693
|
+
else if (isNumber(opts.byhour)) opts.byhour = [opts.byhour];
|
|
3694
|
+
if (!isPresent(opts.byminute)) opts.byminute = opts.freq < RRule.MINUTELY ? [opts.dtstart.getUTCMinutes()] : null;
|
|
3695
|
+
else if (isNumber(opts.byminute)) opts.byminute = [opts.byminute];
|
|
3696
|
+
if (!isPresent(opts.bysecond)) opts.bysecond = opts.freq < RRule.SECONDLY ? [opts.dtstart.getUTCSeconds()] : null;
|
|
3697
|
+
else if (isNumber(opts.bysecond)) opts.bysecond = [opts.bysecond];
|
|
3698
|
+
return { parsedOptions: opts };
|
|
3699
|
+
}
|
|
3700
|
+
function buildTimeset(opts) {
|
|
3701
|
+
var millisecondModulo = opts.dtstart.getTime() % 1e3;
|
|
3702
|
+
if (!freqIsDailyOrGreater(opts.freq)) return [];
|
|
3703
|
+
var timeset = [];
|
|
3704
|
+
opts.byhour.forEach(function(hour) {
|
|
3705
|
+
opts.byminute.forEach(function(minute) {
|
|
3706
|
+
opts.bysecond.forEach(function(second) {
|
|
3707
|
+
timeset.push(new Time(hour, minute, second, millisecondModulo));
|
|
3708
|
+
});
|
|
3709
|
+
});
|
|
3710
|
+
});
|
|
3711
|
+
return timeset;
|
|
3712
|
+
}
|
|
3713
|
+
function parseString(rfcString) {
|
|
3714
|
+
var options = rfcString.split("\n").map(parseLine).filter(function(x) {
|
|
3715
|
+
return x !== null;
|
|
3716
|
+
});
|
|
3717
|
+
return __assign(__assign({}, options[0]), options[1]);
|
|
3718
|
+
}
|
|
3719
|
+
function parseDtstart(line) {
|
|
3720
|
+
var options = {};
|
|
3721
|
+
var dtstartWithZone = /DTSTART(?:;TZID=([^:=]+?))?(?::|=)([^;\s]+)/i.exec(line);
|
|
3722
|
+
if (!dtstartWithZone) return options;
|
|
3723
|
+
var tzid = dtstartWithZone[1], dtstart = dtstartWithZone[2];
|
|
3724
|
+
if (tzid) options.tzid = tzid;
|
|
3725
|
+
options.dtstart = untilStringToDate(dtstart);
|
|
3726
|
+
return options;
|
|
3727
|
+
}
|
|
3728
|
+
function parseLine(rfcString) {
|
|
3729
|
+
rfcString = rfcString.replace(/^\s+|\s+$/, "");
|
|
3730
|
+
if (!rfcString.length) return null;
|
|
3731
|
+
var header = /^([A-Z]+?)[:;]/.exec(rfcString.toUpperCase());
|
|
3732
|
+
if (!header) return parseRrule(rfcString);
|
|
3733
|
+
var key = header[1];
|
|
3734
|
+
switch (key.toUpperCase()) {
|
|
3735
|
+
case "RRULE":
|
|
3736
|
+
case "EXRULE": return parseRrule(rfcString);
|
|
3737
|
+
case "DTSTART": return parseDtstart(rfcString);
|
|
3738
|
+
default: throw new Error("Unsupported RFC prop ".concat(key, " in ").concat(rfcString));
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
function parseRrule(line) {
|
|
3742
|
+
var options = parseDtstart(line.replace(/^RRULE:/i, ""));
|
|
3743
|
+
line.replace(/^(?:RRULE|EXRULE):/i, "").split(";").forEach(function(attr) {
|
|
3744
|
+
var _a = attr.split("="), key = _a[0], value = _a[1];
|
|
3745
|
+
switch (key.toUpperCase()) {
|
|
3746
|
+
case "FREQ":
|
|
3747
|
+
options.freq = Frequency[value.toUpperCase()];
|
|
3748
|
+
break;
|
|
3749
|
+
case "WKST":
|
|
3750
|
+
options.wkst = Days[value.toUpperCase()];
|
|
3751
|
+
break;
|
|
3752
|
+
case "COUNT":
|
|
3753
|
+
case "INTERVAL":
|
|
3754
|
+
case "BYSETPOS":
|
|
3755
|
+
case "BYMONTH":
|
|
3756
|
+
case "BYMONTHDAY":
|
|
3757
|
+
case "BYYEARDAY":
|
|
3758
|
+
case "BYWEEKNO":
|
|
3759
|
+
case "BYHOUR":
|
|
3760
|
+
case "BYMINUTE":
|
|
3761
|
+
case "BYSECOND":
|
|
3762
|
+
var num = parseNumber(value);
|
|
3763
|
+
var optionKey = key.toLowerCase();
|
|
3764
|
+
options[optionKey] = num;
|
|
3765
|
+
break;
|
|
3766
|
+
case "BYWEEKDAY":
|
|
3767
|
+
case "BYDAY":
|
|
3768
|
+
options.byweekday = parseWeekday(value);
|
|
3769
|
+
break;
|
|
3770
|
+
case "DTSTART":
|
|
3771
|
+
case "TZID":
|
|
3772
|
+
var dtstart = parseDtstart(line);
|
|
3773
|
+
options.tzid = dtstart.tzid;
|
|
3774
|
+
options.dtstart = dtstart.dtstart;
|
|
3775
|
+
break;
|
|
3776
|
+
case "UNTIL":
|
|
3777
|
+
options.until = untilStringToDate(value);
|
|
3778
|
+
break;
|
|
3779
|
+
case "BYEASTER":
|
|
3780
|
+
options.byeaster = Number(value);
|
|
3781
|
+
break;
|
|
3782
|
+
default: throw new Error("Unknown RRULE property '" + key + "'");
|
|
3783
|
+
}
|
|
3784
|
+
});
|
|
3785
|
+
return options;
|
|
3786
|
+
}
|
|
3787
|
+
function parseNumber(value) {
|
|
3788
|
+
if (value.indexOf(",") !== -1) return value.split(",").map(parseIndividualNumber);
|
|
3789
|
+
return parseIndividualNumber(value);
|
|
3790
|
+
}
|
|
3791
|
+
function parseIndividualNumber(value) {
|
|
3792
|
+
if (/^[+-]?\d+$/.test(value)) return Number(value);
|
|
3793
|
+
return value;
|
|
3794
|
+
}
|
|
3795
|
+
function parseWeekday(value) {
|
|
3796
|
+
return value.split(",").map(function(day) {
|
|
3797
|
+
if (day.length === 2) return Days[day];
|
|
3798
|
+
var parts = day.match(/^([+-]?\d{1,2})([A-Z]{2})$/);
|
|
3799
|
+
if (!parts || parts.length < 3) throw new SyntaxError("Invalid weekday string: ".concat(day));
|
|
3800
|
+
var n = Number(parts[1]);
|
|
3801
|
+
var wday = Days[parts[2]].weekday;
|
|
3802
|
+
return new Weekday(wday, n);
|
|
3803
|
+
});
|
|
3804
|
+
}
|
|
3805
|
+
var DateWithZone = function() {
|
|
3806
|
+
function DateWithZone(date, tzid) {
|
|
3807
|
+
if (isNaN(date.getTime())) throw new RangeError("Invalid date passed to DateWithZone");
|
|
3808
|
+
this.date = date;
|
|
3809
|
+
this.tzid = tzid;
|
|
3810
|
+
}
|
|
3811
|
+
Object.defineProperty(DateWithZone.prototype, "isUTC", {
|
|
3812
|
+
get: function() {
|
|
3813
|
+
return !this.tzid || this.tzid.toUpperCase() === "UTC";
|
|
3814
|
+
},
|
|
3815
|
+
enumerable: false,
|
|
3816
|
+
configurable: true
|
|
3817
|
+
});
|
|
3818
|
+
DateWithZone.prototype.toString = function() {
|
|
3819
|
+
var datestr = timeToUntilString(this.date.getTime(), this.isUTC);
|
|
3820
|
+
if (!this.isUTC) return ";TZID=".concat(this.tzid, ":").concat(datestr);
|
|
3821
|
+
return ":".concat(datestr);
|
|
3822
|
+
};
|
|
3823
|
+
DateWithZone.prototype.getTime = function() {
|
|
3824
|
+
return this.date.getTime();
|
|
3825
|
+
};
|
|
3826
|
+
DateWithZone.prototype.rezonedDate = function() {
|
|
3827
|
+
if (this.isUTC) return this.date;
|
|
3828
|
+
return dateInTimeZone(this.date, this.tzid);
|
|
3829
|
+
};
|
|
3830
|
+
return DateWithZone;
|
|
3831
|
+
}();
|
|
3832
|
+
function optionsToString(options) {
|
|
3833
|
+
var rrule = [];
|
|
3834
|
+
var dtstart = "";
|
|
3835
|
+
var keys = Object.keys(options);
|
|
3836
|
+
var defaultKeys = Object.keys(DEFAULT_OPTIONS);
|
|
3837
|
+
for (var i = 0; i < keys.length; i++) {
|
|
3838
|
+
if (keys[i] === "tzid") continue;
|
|
3839
|
+
if (!includes(defaultKeys, keys[i])) continue;
|
|
3840
|
+
var key = keys[i].toUpperCase();
|
|
3841
|
+
var value = options[keys[i]];
|
|
3842
|
+
var outValue = "";
|
|
3843
|
+
if (!isPresent(value) || isArray(value) && !value.length) continue;
|
|
3844
|
+
switch (key) {
|
|
3845
|
+
case "FREQ":
|
|
3846
|
+
outValue = RRule.FREQUENCIES[options.freq];
|
|
3847
|
+
break;
|
|
3848
|
+
case "WKST":
|
|
3849
|
+
if (isNumber(value)) outValue = new Weekday(value).toString();
|
|
3850
|
+
else outValue = value.toString();
|
|
3851
|
+
break;
|
|
3852
|
+
case "BYWEEKDAY":
|
|
3853
|
+
key = "BYDAY";
|
|
3854
|
+
outValue = toArray(value).map(function(wday) {
|
|
3855
|
+
if (wday instanceof Weekday) return wday;
|
|
3856
|
+
if (isArray(wday)) return new Weekday(wday[0], wday[1]);
|
|
3857
|
+
return new Weekday(wday);
|
|
3858
|
+
}).toString();
|
|
3859
|
+
break;
|
|
3860
|
+
case "DTSTART":
|
|
3861
|
+
dtstart = buildDtstart(value, options.tzid);
|
|
3862
|
+
break;
|
|
3863
|
+
case "UNTIL":
|
|
3864
|
+
outValue = timeToUntilString(value, !options.tzid);
|
|
3865
|
+
break;
|
|
3866
|
+
default: if (isArray(value)) {
|
|
3867
|
+
var strValues = [];
|
|
3868
|
+
for (var j = 0; j < value.length; j++) strValues[j] = String(value[j]);
|
|
3869
|
+
outValue = strValues.toString();
|
|
3870
|
+
} else outValue = String(value);
|
|
3871
|
+
}
|
|
3872
|
+
if (outValue) rrule.push([key, outValue]);
|
|
3873
|
+
}
|
|
3874
|
+
var rules = rrule.map(function(_a) {
|
|
3875
|
+
var key = _a[0], value = _a[1];
|
|
3876
|
+
return "".concat(key, "=").concat(value.toString());
|
|
3877
|
+
}).join(";");
|
|
3878
|
+
var ruleString = "";
|
|
3879
|
+
if (rules !== "") ruleString = "RRULE:".concat(rules);
|
|
3880
|
+
return [dtstart, ruleString].filter(function(x) {
|
|
3881
|
+
return !!x;
|
|
3882
|
+
}).join("\n");
|
|
3883
|
+
}
|
|
3884
|
+
function buildDtstart(dtstart, tzid) {
|
|
3885
|
+
if (!dtstart) return "";
|
|
3886
|
+
return "DTSTART" + new DateWithZone(new Date(dtstart), tzid).toString();
|
|
3887
|
+
}
|
|
3888
|
+
function argsMatch(left, right) {
|
|
3889
|
+
if (Array.isArray(left)) {
|
|
3890
|
+
if (!Array.isArray(right)) return false;
|
|
3891
|
+
if (left.length !== right.length) return false;
|
|
3892
|
+
return left.every(function(date, i) {
|
|
3893
|
+
return date.getTime() === right[i].getTime();
|
|
3894
|
+
});
|
|
3895
|
+
}
|
|
3896
|
+
if (left instanceof Date) return right instanceof Date && left.getTime() === right.getTime();
|
|
3897
|
+
return left === right;
|
|
3898
|
+
}
|
|
3899
|
+
var Cache = function() {
|
|
3900
|
+
function Cache() {
|
|
3901
|
+
this.all = false;
|
|
3902
|
+
this.before = [];
|
|
3903
|
+
this.after = [];
|
|
3904
|
+
this.between = [];
|
|
3905
|
+
}
|
|
3906
|
+
/**
|
|
3907
|
+
* @param {String} what - all/before/after/between
|
|
3908
|
+
* @param {Array,Date} value - an array of dates, one date, or null
|
|
3909
|
+
* @param {Object?} args - _iter arguments
|
|
3910
|
+
*/
|
|
3911
|
+
Cache.prototype._cacheAdd = function(what, value, args) {
|
|
3912
|
+
if (value) value = value instanceof Date ? dateutil_clone(value) : cloneDates(value);
|
|
3913
|
+
if (what === "all") this.all = value;
|
|
3914
|
+
else {
|
|
3915
|
+
args._value = value;
|
|
3916
|
+
this[what].push(args);
|
|
3917
|
+
}
|
|
3918
|
+
};
|
|
3919
|
+
/**
|
|
3920
|
+
* @return false - not in the cache
|
|
3921
|
+
* @return null - cached, but zero occurrences (before/after)
|
|
3922
|
+
* @return Date - cached (before/after)
|
|
3923
|
+
* @return [] - cached, but zero occurrences (all/between)
|
|
3924
|
+
* @return [Date1, DateN] - cached (all/between)
|
|
3925
|
+
*/
|
|
3926
|
+
Cache.prototype._cacheGet = function(what, args) {
|
|
3927
|
+
var cached = false;
|
|
3928
|
+
var argsKeys = args ? Object.keys(args) : [];
|
|
3929
|
+
var findCacheDiff = function(item) {
|
|
3930
|
+
for (var i = 0; i < argsKeys.length; i++) {
|
|
3931
|
+
var key = argsKeys[i];
|
|
3932
|
+
if (!argsMatch(args[key], item[key])) return true;
|
|
3933
|
+
}
|
|
3934
|
+
return false;
|
|
3935
|
+
};
|
|
3936
|
+
var cachedObject = this[what];
|
|
3937
|
+
if (what === "all") cached = this.all;
|
|
3938
|
+
else if (isArray(cachedObject)) for (var i = 0; i < cachedObject.length; i++) {
|
|
3939
|
+
var item = cachedObject[i];
|
|
3940
|
+
if (argsKeys.length && findCacheDiff(item)) continue;
|
|
3941
|
+
cached = item._value;
|
|
3942
|
+
break;
|
|
3943
|
+
}
|
|
3944
|
+
if (!cached && this.all) {
|
|
3945
|
+
var iterResult = new iterresult(what, args);
|
|
3946
|
+
for (var i = 0; i < this.all.length; i++) if (!iterResult.accept(this.all[i])) break;
|
|
3947
|
+
cached = iterResult.getValue();
|
|
3948
|
+
this._cacheAdd(what, cached, args);
|
|
3949
|
+
}
|
|
3950
|
+
return isArray(cached) ? cloneDates(cached) : cached instanceof Date ? dateutil_clone(cached) : cached;
|
|
3951
|
+
};
|
|
3952
|
+
return Cache;
|
|
3953
|
+
}();
|
|
3954
|
+
var M365MASK = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], repeat(1, 31), true), repeat(2, 28), true), repeat(3, 31), true), repeat(4, 30), true), repeat(5, 31), true), repeat(6, 30), true), repeat(7, 31), true), repeat(8, 31), true), repeat(9, 30), true), repeat(10, 31), true), repeat(11, 30), true), repeat(12, 31), true), repeat(1, 7), true);
|
|
3955
|
+
var M366MASK = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], repeat(1, 31), true), repeat(2, 29), true), repeat(3, 31), true), repeat(4, 30), true), repeat(5, 31), true), repeat(6, 30), true), repeat(7, 31), true), repeat(8, 31), true), repeat(9, 30), true), repeat(10, 31), true), repeat(11, 30), true), repeat(12, 31), true), repeat(1, 7), true);
|
|
3956
|
+
var M28 = range(1, 29);
|
|
3957
|
+
var M29 = range(1, 30);
|
|
3958
|
+
var M30 = range(1, 31);
|
|
3959
|
+
var M31 = range(1, 32);
|
|
3960
|
+
var MDAY366MASK = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], M31, true), M29, true), M31, true), M30, true), M31, true), M30, true), M31, true), M31, true), M30, true), M31, true), M30, true), M31, true), M31.slice(0, 7), true);
|
|
3961
|
+
var MDAY365MASK = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], M31, true), M28, true), M31, true), M30, true), M31, true), M30, true), M31, true), M31, true), M30, true), M31, true), M30, true), M31, true), M31.slice(0, 7), true);
|
|
3962
|
+
var NM28 = range(-28, 0);
|
|
3963
|
+
var NM29 = range(-29, 0);
|
|
3964
|
+
var NM30 = range(-30, 0);
|
|
3965
|
+
var NM31 = range(-31, 0);
|
|
3966
|
+
var NMDAY366MASK = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], NM31, true), NM29, true), NM31, true), NM30, true), NM31, true), NM30, true), NM31, true), NM31, true), NM30, true), NM31, true), NM30, true), NM31, true), NM31.slice(0, 7), true);
|
|
3967
|
+
var NMDAY365MASK = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], NM31, true), NM28, true), NM31, true), NM30, true), NM31, true), NM30, true), NM31, true), NM31, true), NM30, true), NM31, true), NM30, true), NM31, true), NM31.slice(0, 7), true);
|
|
3968
|
+
var M366RANGE = [
|
|
3969
|
+
0,
|
|
3970
|
+
31,
|
|
3971
|
+
60,
|
|
3972
|
+
91,
|
|
3973
|
+
121,
|
|
3974
|
+
152,
|
|
3975
|
+
182,
|
|
3976
|
+
213,
|
|
3977
|
+
244,
|
|
3978
|
+
274,
|
|
3979
|
+
305,
|
|
3980
|
+
335,
|
|
3981
|
+
366
|
|
3982
|
+
];
|
|
3983
|
+
var M365RANGE = [
|
|
3984
|
+
0,
|
|
3985
|
+
31,
|
|
3986
|
+
59,
|
|
3987
|
+
90,
|
|
3988
|
+
120,
|
|
3989
|
+
151,
|
|
3990
|
+
181,
|
|
3991
|
+
212,
|
|
3992
|
+
243,
|
|
3993
|
+
273,
|
|
3994
|
+
304,
|
|
3995
|
+
334,
|
|
3996
|
+
365
|
|
3997
|
+
];
|
|
3998
|
+
var WDAYMASK = (function() {
|
|
3999
|
+
var wdaymask = [];
|
|
4000
|
+
for (var i = 0; i < 55; i++) wdaymask = wdaymask.concat(range(7));
|
|
4001
|
+
return wdaymask;
|
|
4002
|
+
})();
|
|
4003
|
+
function rebuildYear(year, options) {
|
|
4004
|
+
var firstyday = datetime(year, 1, 1);
|
|
4005
|
+
var yearlen = isLeapYear(year) ? 366 : 365;
|
|
4006
|
+
var nextyearlen = isLeapYear(year + 1) ? 366 : 365;
|
|
4007
|
+
var yearordinal = toOrdinal(firstyday);
|
|
4008
|
+
var yearweekday = getWeekday(firstyday);
|
|
4009
|
+
var result = __assign(__assign({
|
|
4010
|
+
yearlen,
|
|
4011
|
+
nextyearlen,
|
|
4012
|
+
yearordinal,
|
|
4013
|
+
yearweekday
|
|
4014
|
+
}, baseYearMasks(year)), { wnomask: null });
|
|
4015
|
+
if (empty(options.byweekno)) return result;
|
|
4016
|
+
result.wnomask = repeat(0, yearlen + 7);
|
|
4017
|
+
var firstwkst;
|
|
4018
|
+
var wyearlen;
|
|
4019
|
+
var no1wkst = firstwkst = pymod(7 - yearweekday + options.wkst, 7);
|
|
4020
|
+
if (no1wkst >= 4) {
|
|
4021
|
+
no1wkst = 0;
|
|
4022
|
+
wyearlen = result.yearlen + pymod(yearweekday - options.wkst, 7);
|
|
4023
|
+
} else wyearlen = yearlen - no1wkst;
|
|
4024
|
+
var div = Math.floor(wyearlen / 7);
|
|
4025
|
+
var mod = pymod(wyearlen, 7);
|
|
4026
|
+
var numweeks = Math.floor(div + mod / 4);
|
|
4027
|
+
for (var j = 0; j < options.byweekno.length; j++) {
|
|
4028
|
+
var n = options.byweekno[j];
|
|
4029
|
+
if (n < 0) n += numweeks + 1;
|
|
4030
|
+
if (!(n > 0 && n <= numweeks)) continue;
|
|
4031
|
+
var i = void 0;
|
|
4032
|
+
if (n > 1) {
|
|
4033
|
+
i = no1wkst + (n - 1) * 7;
|
|
4034
|
+
if (no1wkst !== firstwkst) i -= 7 - firstwkst;
|
|
4035
|
+
} else i = no1wkst;
|
|
4036
|
+
for (var k = 0; k < 7; k++) {
|
|
4037
|
+
result.wnomask[i] = 1;
|
|
4038
|
+
i++;
|
|
4039
|
+
if (result.wdaymask[i] === options.wkst) break;
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4042
|
+
if (includes(options.byweekno, 1)) {
|
|
4043
|
+
var i = no1wkst + numweeks * 7;
|
|
4044
|
+
if (no1wkst !== firstwkst) i -= 7 - firstwkst;
|
|
4045
|
+
if (i < yearlen) for (var j = 0; j < 7; j++) {
|
|
4046
|
+
result.wnomask[i] = 1;
|
|
4047
|
+
i += 1;
|
|
4048
|
+
if (result.wdaymask[i] === options.wkst) break;
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
if (no1wkst) {
|
|
4052
|
+
var lnumweeks = void 0;
|
|
4053
|
+
if (!includes(options.byweekno, -1)) {
|
|
4054
|
+
var lyearweekday = getWeekday(datetime(year - 1, 1, 1));
|
|
4055
|
+
var lno1wkst = pymod(7 - lyearweekday.valueOf() + options.wkst, 7);
|
|
4056
|
+
var lyearlen = isLeapYear(year - 1) ? 366 : 365;
|
|
4057
|
+
var weekst = void 0;
|
|
4058
|
+
if (lno1wkst >= 4) {
|
|
4059
|
+
lno1wkst = 0;
|
|
4060
|
+
weekst = lyearlen + pymod(lyearweekday - options.wkst, 7);
|
|
4061
|
+
} else weekst = yearlen - no1wkst;
|
|
4062
|
+
lnumweeks = Math.floor(52 + pymod(weekst, 7) / 4);
|
|
4063
|
+
} else lnumweeks = -1;
|
|
4064
|
+
if (includes(options.byweekno, lnumweeks)) for (var i = 0; i < no1wkst; i++) result.wnomask[i] = 1;
|
|
4065
|
+
}
|
|
4066
|
+
return result;
|
|
4067
|
+
}
|
|
4068
|
+
function baseYearMasks(year) {
|
|
4069
|
+
var yearlen = isLeapYear(year) ? 366 : 365;
|
|
4070
|
+
var wday = getWeekday(datetime(year, 1, 1));
|
|
4071
|
+
if (yearlen === 365) return {
|
|
4072
|
+
mmask: M365MASK,
|
|
4073
|
+
mdaymask: MDAY365MASK,
|
|
4074
|
+
nmdaymask: NMDAY365MASK,
|
|
4075
|
+
wdaymask: WDAYMASK.slice(wday),
|
|
4076
|
+
mrange: M365RANGE
|
|
4077
|
+
};
|
|
4078
|
+
return {
|
|
4079
|
+
mmask: M366MASK,
|
|
4080
|
+
mdaymask: MDAY366MASK,
|
|
4081
|
+
nmdaymask: NMDAY366MASK,
|
|
4082
|
+
wdaymask: WDAYMASK.slice(wday),
|
|
4083
|
+
mrange: M366RANGE
|
|
4084
|
+
};
|
|
4085
|
+
}
|
|
4086
|
+
function rebuildMonth(year, month, yearlen, mrange, wdaymask, options) {
|
|
4087
|
+
var result = {
|
|
4088
|
+
lastyear: year,
|
|
4089
|
+
lastmonth: month,
|
|
4090
|
+
nwdaymask: []
|
|
4091
|
+
};
|
|
4092
|
+
var ranges = [];
|
|
4093
|
+
if (options.freq === RRule.YEARLY) if (empty(options.bymonth)) ranges = [[0, yearlen]];
|
|
4094
|
+
else for (var j = 0; j < options.bymonth.length; j++) {
|
|
4095
|
+
month = options.bymonth[j];
|
|
4096
|
+
ranges.push(mrange.slice(month - 1, month + 1));
|
|
4097
|
+
}
|
|
4098
|
+
else if (options.freq === RRule.MONTHLY) ranges = [mrange.slice(month - 1, month + 1)];
|
|
4099
|
+
if (empty(ranges)) return result;
|
|
4100
|
+
result.nwdaymask = repeat(0, yearlen);
|
|
4101
|
+
for (var j = 0; j < ranges.length; j++) {
|
|
4102
|
+
var rang = ranges[j];
|
|
4103
|
+
var first = rang[0];
|
|
4104
|
+
var last = rang[1] - 1;
|
|
4105
|
+
for (var k = 0; k < options.bynweekday.length; k++) {
|
|
4106
|
+
var i = void 0;
|
|
4107
|
+
var _a = options.bynweekday[k], wday = _a[0], n = _a[1];
|
|
4108
|
+
if (n < 0) {
|
|
4109
|
+
i = last + (n + 1) * 7;
|
|
4110
|
+
i -= pymod(wdaymask[i] - wday, 7);
|
|
4111
|
+
} else {
|
|
4112
|
+
i = first + (n - 1) * 7;
|
|
4113
|
+
i += pymod(7 - wdaymask[i] + wday, 7);
|
|
4114
|
+
}
|
|
4115
|
+
if (first <= i && i <= last) result.nwdaymask[i] = 1;
|
|
4116
|
+
}
|
|
4117
|
+
}
|
|
4118
|
+
return result;
|
|
4119
|
+
}
|
|
4120
|
+
function easter(y, offset) {
|
|
4121
|
+
if (offset === void 0) offset = 0;
|
|
4122
|
+
var a = y % 19;
|
|
4123
|
+
var b = Math.floor(y / 100);
|
|
4124
|
+
var c = y % 100;
|
|
4125
|
+
var d = Math.floor(b / 4);
|
|
4126
|
+
var e = b % 4;
|
|
4127
|
+
var f = Math.floor((b + 8) / 25);
|
|
4128
|
+
var g = Math.floor((b - f + 1) / 3);
|
|
4129
|
+
var h = Math.floor(19 * a + b - d - g + 15) % 30;
|
|
4130
|
+
var i = Math.floor(c / 4);
|
|
4131
|
+
var k = c % 4;
|
|
4132
|
+
var l = Math.floor(32 + 2 * e + 2 * i - h - k) % 7;
|
|
4133
|
+
var m = Math.floor((a + 11 * h + 22 * l) / 451);
|
|
4134
|
+
var month = Math.floor((h + l - 7 * m + 114) / 31);
|
|
4135
|
+
var day = (h + l - 7 * m + 114) % 31 + 1;
|
|
4136
|
+
var date = Date.UTC(y, month - 1, day + offset);
|
|
4137
|
+
var yearStart = Date.UTC(y, 0, 1);
|
|
4138
|
+
return [Math.ceil((date - yearStart) / (1e3 * 60 * 60 * 24))];
|
|
4139
|
+
}
|
|
4140
|
+
const iterinfo = function() {
|
|
4141
|
+
function Iterinfo(options) {
|
|
4142
|
+
this.options = options;
|
|
4143
|
+
}
|
|
4144
|
+
Iterinfo.prototype.rebuild = function(year, month) {
|
|
4145
|
+
var options = this.options;
|
|
4146
|
+
if (year !== this.lastyear) this.yearinfo = rebuildYear(year, options);
|
|
4147
|
+
if (notEmpty(options.bynweekday) && (month !== this.lastmonth || year !== this.lastyear)) {
|
|
4148
|
+
var _a = this.yearinfo, yearlen = _a.yearlen, mrange = _a.mrange, wdaymask = _a.wdaymask;
|
|
4149
|
+
this.monthinfo = rebuildMonth(year, month, yearlen, mrange, wdaymask, options);
|
|
4150
|
+
}
|
|
4151
|
+
if (isPresent(options.byeaster)) this.eastermask = easter(year, options.byeaster);
|
|
4152
|
+
};
|
|
4153
|
+
Object.defineProperty(Iterinfo.prototype, "lastyear", {
|
|
4154
|
+
get: function() {
|
|
4155
|
+
return this.monthinfo ? this.monthinfo.lastyear : null;
|
|
4156
|
+
},
|
|
4157
|
+
enumerable: false,
|
|
4158
|
+
configurable: true
|
|
4159
|
+
});
|
|
4160
|
+
Object.defineProperty(Iterinfo.prototype, "lastmonth", {
|
|
4161
|
+
get: function() {
|
|
4162
|
+
return this.monthinfo ? this.monthinfo.lastmonth : null;
|
|
4163
|
+
},
|
|
4164
|
+
enumerable: false,
|
|
4165
|
+
configurable: true
|
|
4166
|
+
});
|
|
4167
|
+
Object.defineProperty(Iterinfo.prototype, "yearlen", {
|
|
4168
|
+
get: function() {
|
|
4169
|
+
return this.yearinfo.yearlen;
|
|
4170
|
+
},
|
|
4171
|
+
enumerable: false,
|
|
4172
|
+
configurable: true
|
|
4173
|
+
});
|
|
4174
|
+
Object.defineProperty(Iterinfo.prototype, "yearordinal", {
|
|
4175
|
+
get: function() {
|
|
4176
|
+
return this.yearinfo.yearordinal;
|
|
4177
|
+
},
|
|
4178
|
+
enumerable: false,
|
|
4179
|
+
configurable: true
|
|
4180
|
+
});
|
|
4181
|
+
Object.defineProperty(Iterinfo.prototype, "mrange", {
|
|
4182
|
+
get: function() {
|
|
4183
|
+
return this.yearinfo.mrange;
|
|
4184
|
+
},
|
|
4185
|
+
enumerable: false,
|
|
4186
|
+
configurable: true
|
|
4187
|
+
});
|
|
4188
|
+
Object.defineProperty(Iterinfo.prototype, "wdaymask", {
|
|
4189
|
+
get: function() {
|
|
4190
|
+
return this.yearinfo.wdaymask;
|
|
4191
|
+
},
|
|
4192
|
+
enumerable: false,
|
|
4193
|
+
configurable: true
|
|
4194
|
+
});
|
|
4195
|
+
Object.defineProperty(Iterinfo.prototype, "mmask", {
|
|
4196
|
+
get: function() {
|
|
4197
|
+
return this.yearinfo.mmask;
|
|
4198
|
+
},
|
|
4199
|
+
enumerable: false,
|
|
4200
|
+
configurable: true
|
|
4201
|
+
});
|
|
4202
|
+
Object.defineProperty(Iterinfo.prototype, "wnomask", {
|
|
4203
|
+
get: function() {
|
|
4204
|
+
return this.yearinfo.wnomask;
|
|
4205
|
+
},
|
|
4206
|
+
enumerable: false,
|
|
4207
|
+
configurable: true
|
|
4208
|
+
});
|
|
4209
|
+
Object.defineProperty(Iterinfo.prototype, "nwdaymask", {
|
|
4210
|
+
get: function() {
|
|
4211
|
+
return this.monthinfo ? this.monthinfo.nwdaymask : [];
|
|
4212
|
+
},
|
|
4213
|
+
enumerable: false,
|
|
4214
|
+
configurable: true
|
|
4215
|
+
});
|
|
4216
|
+
Object.defineProperty(Iterinfo.prototype, "nextyearlen", {
|
|
4217
|
+
get: function() {
|
|
4218
|
+
return this.yearinfo.nextyearlen;
|
|
4219
|
+
},
|
|
4220
|
+
enumerable: false,
|
|
4221
|
+
configurable: true
|
|
4222
|
+
});
|
|
4223
|
+
Object.defineProperty(Iterinfo.prototype, "mdaymask", {
|
|
4224
|
+
get: function() {
|
|
4225
|
+
return this.yearinfo.mdaymask;
|
|
4226
|
+
},
|
|
4227
|
+
enumerable: false,
|
|
4228
|
+
configurable: true
|
|
4229
|
+
});
|
|
4230
|
+
Object.defineProperty(Iterinfo.prototype, "nmdaymask", {
|
|
4231
|
+
get: function() {
|
|
4232
|
+
return this.yearinfo.nmdaymask;
|
|
4233
|
+
},
|
|
4234
|
+
enumerable: false,
|
|
4235
|
+
configurable: true
|
|
4236
|
+
});
|
|
4237
|
+
Iterinfo.prototype.ydayset = function() {
|
|
4238
|
+
return [
|
|
4239
|
+
range(this.yearlen),
|
|
4240
|
+
0,
|
|
4241
|
+
this.yearlen
|
|
4242
|
+
];
|
|
4243
|
+
};
|
|
4244
|
+
Iterinfo.prototype.mdayset = function(_, month) {
|
|
4245
|
+
var start = this.mrange[month - 1];
|
|
4246
|
+
var end = this.mrange[month];
|
|
4247
|
+
var set = repeat(null, this.yearlen);
|
|
4248
|
+
for (var i = start; i < end; i++) set[i] = i;
|
|
4249
|
+
return [
|
|
4250
|
+
set,
|
|
4251
|
+
start,
|
|
4252
|
+
end
|
|
4253
|
+
];
|
|
4254
|
+
};
|
|
4255
|
+
Iterinfo.prototype.wdayset = function(year, month, day) {
|
|
4256
|
+
var set = repeat(null, this.yearlen + 7);
|
|
4257
|
+
var i = toOrdinal(datetime(year, month, day)) - this.yearordinal;
|
|
4258
|
+
var start = i;
|
|
4259
|
+
for (var j = 0; j < 7; j++) {
|
|
4260
|
+
set[i] = i;
|
|
4261
|
+
++i;
|
|
4262
|
+
if (this.wdaymask[i] === this.options.wkst) break;
|
|
4263
|
+
}
|
|
4264
|
+
return [
|
|
4265
|
+
set,
|
|
4266
|
+
start,
|
|
4267
|
+
i
|
|
4268
|
+
];
|
|
4269
|
+
};
|
|
4270
|
+
Iterinfo.prototype.ddayset = function(year, month, day) {
|
|
4271
|
+
var set = repeat(null, this.yearlen);
|
|
4272
|
+
var i = toOrdinal(datetime(year, month, day)) - this.yearordinal;
|
|
4273
|
+
set[i] = i;
|
|
4274
|
+
return [
|
|
4275
|
+
set,
|
|
4276
|
+
i,
|
|
4277
|
+
i + 1
|
|
4278
|
+
];
|
|
4279
|
+
};
|
|
4280
|
+
Iterinfo.prototype.htimeset = function(hour, _, second, millisecond) {
|
|
4281
|
+
var _this = this;
|
|
4282
|
+
var set = [];
|
|
4283
|
+
this.options.byminute.forEach(function(minute) {
|
|
4284
|
+
set = set.concat(_this.mtimeset(hour, minute, second, millisecond));
|
|
4285
|
+
});
|
|
4286
|
+
sort(set);
|
|
4287
|
+
return set;
|
|
4288
|
+
};
|
|
4289
|
+
Iterinfo.prototype.mtimeset = function(hour, minute, _, millisecond) {
|
|
4290
|
+
var set = this.options.bysecond.map(function(second) {
|
|
4291
|
+
return new Time(hour, minute, second, millisecond);
|
|
4292
|
+
});
|
|
4293
|
+
sort(set);
|
|
4294
|
+
return set;
|
|
4295
|
+
};
|
|
4296
|
+
Iterinfo.prototype.stimeset = function(hour, minute, second, millisecond) {
|
|
4297
|
+
return [new Time(hour, minute, second, millisecond)];
|
|
4298
|
+
};
|
|
4299
|
+
Iterinfo.prototype.getdayset = function(freq) {
|
|
4300
|
+
switch (freq) {
|
|
4301
|
+
case Frequency.YEARLY: return this.ydayset.bind(this);
|
|
4302
|
+
case Frequency.MONTHLY: return this.mdayset.bind(this);
|
|
4303
|
+
case Frequency.WEEKLY: return this.wdayset.bind(this);
|
|
4304
|
+
case Frequency.DAILY: return this.ddayset.bind(this);
|
|
4305
|
+
default: return this.ddayset.bind(this);
|
|
4306
|
+
}
|
|
4307
|
+
};
|
|
4308
|
+
Iterinfo.prototype.gettimeset = function(freq) {
|
|
4309
|
+
switch (freq) {
|
|
4310
|
+
case Frequency.HOURLY: return this.htimeset.bind(this);
|
|
4311
|
+
case Frequency.MINUTELY: return this.mtimeset.bind(this);
|
|
4312
|
+
case Frequency.SECONDLY: return this.stimeset.bind(this);
|
|
4313
|
+
}
|
|
4314
|
+
};
|
|
4315
|
+
return Iterinfo;
|
|
4316
|
+
}();
|
|
4317
|
+
function buildPoslist(bysetpos, timeset, start, end, ii, dayset) {
|
|
4318
|
+
var poslist = [];
|
|
4319
|
+
for (var j = 0; j < bysetpos.length; j++) {
|
|
4320
|
+
var daypos = void 0;
|
|
4321
|
+
var timepos = void 0;
|
|
4322
|
+
var pos = bysetpos[j];
|
|
4323
|
+
if (pos < 0) {
|
|
4324
|
+
daypos = Math.floor(pos / timeset.length);
|
|
4325
|
+
timepos = pymod(pos, timeset.length);
|
|
4326
|
+
} else {
|
|
4327
|
+
daypos = Math.floor((pos - 1) / timeset.length);
|
|
4328
|
+
timepos = pymod(pos - 1, timeset.length);
|
|
4329
|
+
}
|
|
4330
|
+
var tmp = [];
|
|
4331
|
+
for (var k = start; k < end; k++) {
|
|
4332
|
+
var val = dayset[k];
|
|
4333
|
+
if (!isPresent(val)) continue;
|
|
4334
|
+
tmp.push(val);
|
|
4335
|
+
}
|
|
4336
|
+
var i = void 0;
|
|
4337
|
+
if (daypos < 0) i = tmp.slice(daypos)[0];
|
|
4338
|
+
else i = tmp[daypos];
|
|
4339
|
+
var time = timeset[timepos];
|
|
4340
|
+
var res = combine(fromOrdinal(ii.yearordinal + i), time);
|
|
4341
|
+
if (!includes(poslist, res)) poslist.push(res);
|
|
4342
|
+
}
|
|
4343
|
+
sort(poslist);
|
|
4344
|
+
return poslist;
|
|
4345
|
+
}
|
|
4346
|
+
function iter(iterResult, options) {
|
|
4347
|
+
var dtstart = options.dtstart, freq = options.freq, interval = options.interval, until = options.until, bysetpos = options.bysetpos;
|
|
4348
|
+
var count = options.count;
|
|
4349
|
+
if (count === 0 || interval === 0) return emitResult(iterResult);
|
|
4350
|
+
var counterDate = DateTime.fromDate(dtstart);
|
|
4351
|
+
var ii = new iterinfo(options);
|
|
4352
|
+
ii.rebuild(counterDate.year, counterDate.month);
|
|
4353
|
+
var timeset = makeTimeset(ii, counterDate, options);
|
|
4354
|
+
for (;;) {
|
|
4355
|
+
var _a = ii.getdayset(freq)(counterDate.year, counterDate.month, counterDate.day), dayset = _a[0], start = _a[1], end = _a[2];
|
|
4356
|
+
var filtered = removeFilteredDays(dayset, start, end, ii, options);
|
|
4357
|
+
if (notEmpty(bysetpos)) {
|
|
4358
|
+
var poslist = buildPoslist(bysetpos, timeset, start, end, ii, dayset);
|
|
4359
|
+
for (var j = 0; j < poslist.length; j++) {
|
|
4360
|
+
var res = poslist[j];
|
|
4361
|
+
if (until && res > until) return emitResult(iterResult);
|
|
4362
|
+
if (res >= dtstart) {
|
|
4363
|
+
var rezonedDate = rezoneIfNeeded(res, options);
|
|
4364
|
+
if (!iterResult.accept(rezonedDate)) return emitResult(iterResult);
|
|
4365
|
+
if (count) {
|
|
4366
|
+
--count;
|
|
4367
|
+
if (!count) return emitResult(iterResult);
|
|
4368
|
+
}
|
|
4369
|
+
}
|
|
4370
|
+
}
|
|
4371
|
+
} else for (var j = start; j < end; j++) {
|
|
4372
|
+
var currentDay = dayset[j];
|
|
4373
|
+
if (!isPresent(currentDay)) continue;
|
|
4374
|
+
var date = fromOrdinal(ii.yearordinal + currentDay);
|
|
4375
|
+
for (var k = 0; k < timeset.length; k++) {
|
|
4376
|
+
var time = timeset[k];
|
|
4377
|
+
var res = combine(date, time);
|
|
4378
|
+
if (until && res > until) return emitResult(iterResult);
|
|
4379
|
+
if (res >= dtstart) {
|
|
4380
|
+
var rezonedDate = rezoneIfNeeded(res, options);
|
|
4381
|
+
if (!iterResult.accept(rezonedDate)) return emitResult(iterResult);
|
|
4382
|
+
if (count) {
|
|
4383
|
+
--count;
|
|
4384
|
+
if (!count) return emitResult(iterResult);
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
if (options.interval === 0) return emitResult(iterResult);
|
|
4390
|
+
counterDate.add(options, filtered);
|
|
4391
|
+
if (counterDate.year > MAXYEAR) return emitResult(iterResult);
|
|
4392
|
+
if (!freqIsDailyOrGreater(freq)) timeset = ii.gettimeset(freq)(counterDate.hour, counterDate.minute, counterDate.second, 0);
|
|
4393
|
+
ii.rebuild(counterDate.year, counterDate.month);
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
4396
|
+
function isFiltered(ii, currentDay, options) {
|
|
4397
|
+
var bymonth = options.bymonth, byweekno = options.byweekno, byweekday = options.byweekday, byeaster = options.byeaster, bymonthday = options.bymonthday, bynmonthday = options.bynmonthday, byyearday = options.byyearday;
|
|
4398
|
+
return notEmpty(bymonth) && !includes(bymonth, ii.mmask[currentDay]) || notEmpty(byweekno) && !ii.wnomask[currentDay] || notEmpty(byweekday) && !includes(byweekday, ii.wdaymask[currentDay]) || notEmpty(ii.nwdaymask) && !ii.nwdaymask[currentDay] || byeaster !== null && !includes(ii.eastermask, currentDay) || (notEmpty(bymonthday) || notEmpty(bynmonthday)) && !includes(bymonthday, ii.mdaymask[currentDay]) && !includes(bynmonthday, ii.nmdaymask[currentDay]) || notEmpty(byyearday) && (currentDay < ii.yearlen && !includes(byyearday, currentDay + 1) && !includes(byyearday, -ii.yearlen + currentDay) || currentDay >= ii.yearlen && !includes(byyearday, currentDay + 1 - ii.yearlen) && !includes(byyearday, -ii.nextyearlen + currentDay - ii.yearlen));
|
|
4399
|
+
}
|
|
4400
|
+
function rezoneIfNeeded(date, options) {
|
|
4401
|
+
return new DateWithZone(date, options.tzid).rezonedDate();
|
|
4402
|
+
}
|
|
4403
|
+
function emitResult(iterResult) {
|
|
4404
|
+
return iterResult.getValue();
|
|
4405
|
+
}
|
|
4406
|
+
function removeFilteredDays(dayset, start, end, ii, options) {
|
|
4407
|
+
var filtered = false;
|
|
4408
|
+
for (var dayCounter = start; dayCounter < end; dayCounter++) {
|
|
4409
|
+
var currentDay = dayset[dayCounter];
|
|
4410
|
+
filtered = isFiltered(ii, currentDay, options);
|
|
4411
|
+
if (filtered) dayset[currentDay] = null;
|
|
4412
|
+
}
|
|
4413
|
+
return filtered;
|
|
4414
|
+
}
|
|
4415
|
+
function makeTimeset(ii, counterDate, options) {
|
|
4416
|
+
var freq = options.freq, byhour = options.byhour, byminute = options.byminute, bysecond = options.bysecond;
|
|
4417
|
+
if (freqIsDailyOrGreater(freq)) return buildTimeset(options);
|
|
4418
|
+
if (freq >= RRule.HOURLY && notEmpty(byhour) && !includes(byhour, counterDate.hour) || freq >= RRule.MINUTELY && notEmpty(byminute) && !includes(byminute, counterDate.minute) || freq >= RRule.SECONDLY && notEmpty(bysecond) && !includes(bysecond, counterDate.second)) return [];
|
|
4419
|
+
return ii.gettimeset(freq)(counterDate.hour, counterDate.minute, counterDate.second, counterDate.millisecond);
|
|
4420
|
+
}
|
|
4421
|
+
var Days = {
|
|
4422
|
+
MO: new Weekday(0),
|
|
4423
|
+
TU: new Weekday(1),
|
|
4424
|
+
WE: new Weekday(2),
|
|
4425
|
+
TH: new Weekday(3),
|
|
4426
|
+
FR: new Weekday(4),
|
|
4427
|
+
SA: new Weekday(5),
|
|
4428
|
+
SU: new Weekday(6)
|
|
4429
|
+
};
|
|
4430
|
+
var DEFAULT_OPTIONS = {
|
|
4431
|
+
freq: Frequency.YEARLY,
|
|
4432
|
+
dtstart: null,
|
|
4433
|
+
interval: 1,
|
|
4434
|
+
wkst: Days.MO,
|
|
4435
|
+
count: null,
|
|
4436
|
+
until: null,
|
|
4437
|
+
tzid: null,
|
|
4438
|
+
bysetpos: null,
|
|
4439
|
+
bymonth: null,
|
|
4440
|
+
bymonthday: null,
|
|
4441
|
+
bynmonthday: null,
|
|
4442
|
+
byyearday: null,
|
|
4443
|
+
byweekno: null,
|
|
4444
|
+
byweekday: null,
|
|
4445
|
+
bynweekday: null,
|
|
4446
|
+
byhour: null,
|
|
4447
|
+
byminute: null,
|
|
4448
|
+
bysecond: null,
|
|
4449
|
+
byeaster: null
|
|
4450
|
+
};
|
|
4451
|
+
var defaultKeys = Object.keys(DEFAULT_OPTIONS);
|
|
4452
|
+
/**
|
|
4453
|
+
*
|
|
4454
|
+
* @param {Options?} options - see <http://labix.org/python-dateutil/#head-cf004ee9a75592797e076752b2a889c10f445418>
|
|
4455
|
+
* - The only required option is `freq`, one of RRule.YEARLY, RRule.MONTHLY, ...
|
|
4456
|
+
* @constructor
|
|
4457
|
+
*/
|
|
4458
|
+
var RRule = function() {
|
|
4459
|
+
function RRule(options, noCache) {
|
|
4460
|
+
if (options === void 0) options = {};
|
|
4461
|
+
if (noCache === void 0) noCache = false;
|
|
4462
|
+
this._cache = noCache ? null : new Cache();
|
|
4463
|
+
this.origOptions = initializeOptions(options);
|
|
4464
|
+
this.options = parseOptions(options).parsedOptions;
|
|
4465
|
+
}
|
|
4466
|
+
RRule.parseText = function(text, language) {
|
|
4467
|
+
return parseText(text, language);
|
|
4468
|
+
};
|
|
4469
|
+
RRule.fromText = function(text, language) {
|
|
4470
|
+
return fromText(text, language);
|
|
4471
|
+
};
|
|
4472
|
+
RRule.fromString = function(str) {
|
|
4473
|
+
return new RRule(RRule.parseString(str) || void 0);
|
|
4474
|
+
};
|
|
4475
|
+
RRule.prototype._iter = function(iterResult) {
|
|
4476
|
+
return iter(iterResult, this.options);
|
|
4477
|
+
};
|
|
4478
|
+
RRule.prototype._cacheGet = function(what, args) {
|
|
4479
|
+
if (!this._cache) return false;
|
|
4480
|
+
return this._cache._cacheGet(what, args);
|
|
4481
|
+
};
|
|
4482
|
+
RRule.prototype._cacheAdd = function(what, value, args) {
|
|
4483
|
+
if (!this._cache) return;
|
|
4484
|
+
return this._cache._cacheAdd(what, value, args);
|
|
4485
|
+
};
|
|
4486
|
+
/**
|
|
4487
|
+
* @param {Function} iterator - optional function that will be called
|
|
4488
|
+
* on each date that is added. It can return false
|
|
4489
|
+
* to stop the iteration.
|
|
4490
|
+
* @return Array containing all recurrences.
|
|
4491
|
+
*/
|
|
4492
|
+
RRule.prototype.all = function(iterator) {
|
|
4493
|
+
if (iterator) return this._iter(new callbackiterresult("all", {}, iterator));
|
|
4494
|
+
var result = this._cacheGet("all");
|
|
4495
|
+
if (result === false) {
|
|
4496
|
+
result = this._iter(new iterresult("all", {}));
|
|
4497
|
+
this._cacheAdd("all", result);
|
|
4498
|
+
}
|
|
4499
|
+
return result;
|
|
4500
|
+
};
|
|
4501
|
+
/**
|
|
4502
|
+
* Returns all the occurrences of the rrule between after and before.
|
|
4503
|
+
* The inc keyword defines what happens if after and/or before are
|
|
4504
|
+
* themselves occurrences. With inc == True, they will be included in the
|
|
4505
|
+
* list, if they are found in the recurrence set.
|
|
4506
|
+
*
|
|
4507
|
+
* @return Array
|
|
4508
|
+
*/
|
|
4509
|
+
RRule.prototype.between = function(after, before, inc, iterator) {
|
|
4510
|
+
if (inc === void 0) inc = false;
|
|
4511
|
+
if (!isValidDate(after) || !isValidDate(before)) throw new Error("Invalid date passed in to RRule.between");
|
|
4512
|
+
var args = {
|
|
4513
|
+
before,
|
|
4514
|
+
after,
|
|
4515
|
+
inc
|
|
4516
|
+
};
|
|
4517
|
+
if (iterator) return this._iter(new callbackiterresult("between", args, iterator));
|
|
4518
|
+
var result = this._cacheGet("between", args);
|
|
4519
|
+
if (result === false) {
|
|
4520
|
+
result = this._iter(new iterresult("between", args));
|
|
4521
|
+
this._cacheAdd("between", result, args);
|
|
4522
|
+
}
|
|
4523
|
+
return result;
|
|
4524
|
+
};
|
|
4525
|
+
/**
|
|
4526
|
+
* Returns the last recurrence before the given datetime instance.
|
|
4527
|
+
* The inc keyword defines what happens if dt is an occurrence.
|
|
4528
|
+
* With inc == True, if dt itself is an occurrence, it will be returned.
|
|
4529
|
+
*
|
|
4530
|
+
* @return Date or null
|
|
4531
|
+
*/
|
|
4532
|
+
RRule.prototype.before = function(dt, inc) {
|
|
4533
|
+
if (inc === void 0) inc = false;
|
|
4534
|
+
if (!isValidDate(dt)) throw new Error("Invalid date passed in to RRule.before");
|
|
4535
|
+
var args = {
|
|
4536
|
+
dt,
|
|
4537
|
+
inc
|
|
4538
|
+
};
|
|
4539
|
+
var result = this._cacheGet("before", args);
|
|
4540
|
+
if (result === false) {
|
|
4541
|
+
result = this._iter(new iterresult("before", args));
|
|
4542
|
+
this._cacheAdd("before", result, args);
|
|
4543
|
+
}
|
|
4544
|
+
return result;
|
|
4545
|
+
};
|
|
4546
|
+
/**
|
|
4547
|
+
* Returns the first recurrence after the given datetime instance.
|
|
4548
|
+
* The inc keyword defines what happens if dt is an occurrence.
|
|
4549
|
+
* With inc == True, if dt itself is an occurrence, it will be returned.
|
|
4550
|
+
*
|
|
4551
|
+
* @return Date or null
|
|
4552
|
+
*/
|
|
4553
|
+
RRule.prototype.after = function(dt, inc) {
|
|
4554
|
+
if (inc === void 0) inc = false;
|
|
4555
|
+
if (!isValidDate(dt)) throw new Error("Invalid date passed in to RRule.after");
|
|
4556
|
+
var args = {
|
|
4557
|
+
dt,
|
|
4558
|
+
inc
|
|
4559
|
+
};
|
|
4560
|
+
var result = this._cacheGet("after", args);
|
|
4561
|
+
if (result === false) {
|
|
4562
|
+
result = this._iter(new iterresult("after", args));
|
|
4563
|
+
this._cacheAdd("after", result, args);
|
|
4564
|
+
}
|
|
4565
|
+
return result;
|
|
4566
|
+
};
|
|
4567
|
+
/**
|
|
4568
|
+
* Returns the number of recurrences in this set. It will have go trough
|
|
4569
|
+
* the whole recurrence, if this hasn't been done before.
|
|
4570
|
+
*/
|
|
4571
|
+
RRule.prototype.count = function() {
|
|
4572
|
+
return this.all().length;
|
|
4573
|
+
};
|
|
4574
|
+
/**
|
|
4575
|
+
* Converts the rrule into its string representation
|
|
4576
|
+
*
|
|
4577
|
+
* @see <http://www.ietf.org/rfc/rfc2445.txt>
|
|
4578
|
+
* @return String
|
|
4579
|
+
*/
|
|
4580
|
+
RRule.prototype.toString = function() {
|
|
4581
|
+
return optionsToString(this.origOptions);
|
|
4582
|
+
};
|
|
4583
|
+
/**
|
|
4584
|
+
* Will convert all rules described in nlp:ToText
|
|
4585
|
+
* to text.
|
|
4586
|
+
*/
|
|
4587
|
+
RRule.prototype.toText = function(gettext, language, dateFormatter) {
|
|
4588
|
+
return toText(this, gettext, language, dateFormatter);
|
|
4589
|
+
};
|
|
4590
|
+
RRule.prototype.isFullyConvertibleToText = function() {
|
|
4591
|
+
return isFullyConvertible(this);
|
|
4592
|
+
};
|
|
4593
|
+
/**
|
|
4594
|
+
* @return a RRule instance with the same freq and options
|
|
4595
|
+
* as this one (cache is not cloned)
|
|
4596
|
+
*/
|
|
4597
|
+
RRule.prototype.clone = function() {
|
|
4598
|
+
return new RRule(this.origOptions);
|
|
4599
|
+
};
|
|
4600
|
+
RRule.FREQUENCIES = [
|
|
4601
|
+
"YEARLY",
|
|
4602
|
+
"MONTHLY",
|
|
4603
|
+
"WEEKLY",
|
|
4604
|
+
"DAILY",
|
|
4605
|
+
"HOURLY",
|
|
4606
|
+
"MINUTELY",
|
|
4607
|
+
"SECONDLY"
|
|
4608
|
+
];
|
|
4609
|
+
RRule.YEARLY = Frequency.YEARLY;
|
|
4610
|
+
RRule.MONTHLY = Frequency.MONTHLY;
|
|
4611
|
+
RRule.WEEKLY = Frequency.WEEKLY;
|
|
4612
|
+
RRule.DAILY = Frequency.DAILY;
|
|
4613
|
+
RRule.HOURLY = Frequency.HOURLY;
|
|
4614
|
+
RRule.MINUTELY = Frequency.MINUTELY;
|
|
4615
|
+
RRule.SECONDLY = Frequency.SECONDLY;
|
|
4616
|
+
RRule.MO = Days.MO;
|
|
4617
|
+
RRule.TU = Days.TU;
|
|
4618
|
+
RRule.WE = Days.WE;
|
|
4619
|
+
RRule.TH = Days.TH;
|
|
4620
|
+
RRule.FR = Days.FR;
|
|
4621
|
+
RRule.SA = Days.SA;
|
|
4622
|
+
RRule.SU = Days.SU;
|
|
4623
|
+
RRule.parseString = parseString;
|
|
4624
|
+
RRule.optionsToString = optionsToString;
|
|
4625
|
+
return RRule;
|
|
4626
|
+
}();
|
|
4627
|
+
function iterSet(iterResult, _rrule, _exrule, _rdate, _exdate, tzid) {
|
|
4628
|
+
var _exdateHash = {};
|
|
4629
|
+
var _accept = iterResult.accept;
|
|
4630
|
+
function evalExdate(after, before) {
|
|
4631
|
+
_exrule.forEach(function(rrule) {
|
|
4632
|
+
rrule.between(after, before, true).forEach(function(date) {
|
|
4633
|
+
_exdateHash[Number(date)] = true;
|
|
4634
|
+
});
|
|
4635
|
+
});
|
|
4636
|
+
}
|
|
4637
|
+
_exdate.forEach(function(date) {
|
|
4638
|
+
var zonedDate = new DateWithZone(date, tzid).rezonedDate();
|
|
4639
|
+
_exdateHash[Number(zonedDate)] = true;
|
|
4640
|
+
});
|
|
4641
|
+
iterResult.accept = function(date) {
|
|
4642
|
+
var dt = Number(date);
|
|
4643
|
+
if (isNaN(dt)) return _accept.call(this, date);
|
|
4644
|
+
if (!_exdateHash[dt]) {
|
|
4645
|
+
evalExdate(/* @__PURE__ */ new Date(dt - 1), new Date(dt + 1));
|
|
4646
|
+
if (!_exdateHash[dt]) {
|
|
4647
|
+
_exdateHash[dt] = true;
|
|
4648
|
+
return _accept.call(this, date);
|
|
4649
|
+
}
|
|
4650
|
+
}
|
|
4651
|
+
return true;
|
|
4652
|
+
};
|
|
4653
|
+
if (iterResult.method === "between") {
|
|
4654
|
+
evalExdate(iterResult.args.after, iterResult.args.before);
|
|
4655
|
+
iterResult.accept = function(date) {
|
|
4656
|
+
var dt = Number(date);
|
|
4657
|
+
if (!_exdateHash[dt]) {
|
|
4658
|
+
_exdateHash[dt] = true;
|
|
4659
|
+
return _accept.call(this, date);
|
|
4660
|
+
}
|
|
4661
|
+
return true;
|
|
4662
|
+
};
|
|
4663
|
+
}
|
|
4664
|
+
for (var i = 0; i < _rdate.length; i++) {
|
|
4665
|
+
var zonedDate = new DateWithZone(_rdate[i], tzid).rezonedDate();
|
|
4666
|
+
if (!iterResult.accept(new Date(zonedDate.getTime()))) break;
|
|
4667
|
+
}
|
|
4668
|
+
_rrule.forEach(function(rrule) {
|
|
4669
|
+
iter(iterResult, rrule.options);
|
|
4670
|
+
});
|
|
4671
|
+
var res = iterResult._result;
|
|
4672
|
+
sort(res);
|
|
4673
|
+
switch (iterResult.method) {
|
|
4674
|
+
case "all":
|
|
4675
|
+
case "between": return res;
|
|
4676
|
+
case "before": return res.length && res[res.length - 1] || null;
|
|
4677
|
+
default: return res.length && res[0] || null;
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4680
|
+
/**
|
|
4681
|
+
* RRuleStr
|
|
4682
|
+
* To parse a set of rrule strings
|
|
4683
|
+
*/
|
|
4684
|
+
var rrulestr_DEFAULT_OPTIONS = {
|
|
4685
|
+
dtstart: null,
|
|
4686
|
+
cache: false,
|
|
4687
|
+
unfold: false,
|
|
4688
|
+
forceset: false,
|
|
4689
|
+
compatible: false,
|
|
4690
|
+
tzid: null
|
|
4691
|
+
};
|
|
4692
|
+
function parseInput(s, options) {
|
|
4693
|
+
var rrulevals = [];
|
|
4694
|
+
var rdatevals = [];
|
|
4695
|
+
var exrulevals = [];
|
|
4696
|
+
var exdatevals = [];
|
|
4697
|
+
var parsedDtstart = parseDtstart(s);
|
|
4698
|
+
var dtstart = parsedDtstart.dtstart;
|
|
4699
|
+
var tzid = parsedDtstart.tzid;
|
|
4700
|
+
splitIntoLines(s, options.unfold).forEach(function(line) {
|
|
4701
|
+
var _a;
|
|
4702
|
+
if (!line) return;
|
|
4703
|
+
var _b = breakDownLine(line), name = _b.name, parms = _b.parms, value = _b.value;
|
|
4704
|
+
switch (name.toUpperCase()) {
|
|
4705
|
+
case "RRULE":
|
|
4706
|
+
if (parms.length) throw new Error("unsupported RRULE parm: ".concat(parms.join(",")));
|
|
4707
|
+
rrulevals.push(parseString(line));
|
|
4708
|
+
break;
|
|
4709
|
+
case "RDATE":
|
|
4710
|
+
var rdateTzid = ((_a = /RDATE(?:;TZID=([^:=]+))?/i.exec(line)) !== null && _a !== void 0 ? _a : [])[1];
|
|
4711
|
+
if (rdateTzid && !tzid) tzid = rdateTzid;
|
|
4712
|
+
rdatevals = rdatevals.concat(parseRDate(value, parms));
|
|
4713
|
+
break;
|
|
4714
|
+
case "EXRULE":
|
|
4715
|
+
if (parms.length) throw new Error("unsupported EXRULE parm: ".concat(parms.join(",")));
|
|
4716
|
+
exrulevals.push(parseString(value));
|
|
4717
|
+
break;
|
|
4718
|
+
case "EXDATE":
|
|
4719
|
+
exdatevals = exdatevals.concat(parseRDate(value, parms));
|
|
4720
|
+
break;
|
|
4721
|
+
case "DTSTART": break;
|
|
4722
|
+
default: throw new Error("unsupported property: " + name);
|
|
4723
|
+
}
|
|
4724
|
+
});
|
|
4725
|
+
return {
|
|
4726
|
+
dtstart,
|
|
4727
|
+
tzid,
|
|
4728
|
+
rrulevals,
|
|
4729
|
+
rdatevals,
|
|
4730
|
+
exrulevals,
|
|
4731
|
+
exdatevals
|
|
4732
|
+
};
|
|
4733
|
+
}
|
|
4734
|
+
function buildRule(s, options) {
|
|
4735
|
+
var _a = parseInput(s, options), rrulevals = _a.rrulevals, rdatevals = _a.rdatevals, exrulevals = _a.exrulevals, exdatevals = _a.exdatevals, dtstart = _a.dtstart, tzid = _a.tzid;
|
|
4736
|
+
var noCache = options.cache === false;
|
|
4737
|
+
if (options.compatible) {
|
|
4738
|
+
options.forceset = true;
|
|
4739
|
+
options.unfold = true;
|
|
4740
|
+
}
|
|
4741
|
+
if (options.forceset || rrulevals.length > 1 || rdatevals.length || exrulevals.length || exdatevals.length) {
|
|
4742
|
+
var rset_1 = new RRuleSet(noCache);
|
|
4743
|
+
rset_1.dtstart(dtstart);
|
|
4744
|
+
rset_1.tzid(tzid || void 0);
|
|
4745
|
+
rrulevals.forEach(function(val) {
|
|
4746
|
+
rset_1.rrule(new RRule(groomRruleOptions(val, dtstart, tzid), noCache));
|
|
4747
|
+
});
|
|
4748
|
+
rdatevals.forEach(function(date) {
|
|
4749
|
+
rset_1.rdate(date);
|
|
4750
|
+
});
|
|
4751
|
+
exrulevals.forEach(function(val) {
|
|
4752
|
+
rset_1.exrule(new RRule(groomRruleOptions(val, dtstart, tzid), noCache));
|
|
4753
|
+
});
|
|
4754
|
+
exdatevals.forEach(function(date) {
|
|
4755
|
+
rset_1.exdate(date);
|
|
4756
|
+
});
|
|
4757
|
+
if (options.compatible && options.dtstart) rset_1.rdate(dtstart);
|
|
4758
|
+
return rset_1;
|
|
4759
|
+
}
|
|
4760
|
+
var val = rrulevals[0] || {};
|
|
4761
|
+
return new RRule(groomRruleOptions(val, val.dtstart || options.dtstart || dtstart, val.tzid || options.tzid || tzid), noCache);
|
|
4762
|
+
}
|
|
4763
|
+
function rrulestr(s, options) {
|
|
4764
|
+
if (options === void 0) options = {};
|
|
4765
|
+
return buildRule(s, rrulestr_initializeOptions(options));
|
|
4766
|
+
}
|
|
4767
|
+
function groomRruleOptions(val, dtstart, tzid) {
|
|
4768
|
+
return __assign(__assign({}, val), {
|
|
4769
|
+
dtstart,
|
|
4770
|
+
tzid
|
|
4771
|
+
});
|
|
4772
|
+
}
|
|
4773
|
+
function rrulestr_initializeOptions(options) {
|
|
4774
|
+
var invalid = [];
|
|
4775
|
+
var keys = Object.keys(options);
|
|
4776
|
+
var defaultKeys = Object.keys(rrulestr_DEFAULT_OPTIONS);
|
|
4777
|
+
keys.forEach(function(key) {
|
|
4778
|
+
if (!includes(defaultKeys, key)) invalid.push(key);
|
|
4779
|
+
});
|
|
4780
|
+
if (invalid.length) throw new Error("Invalid options: " + invalid.join(", "));
|
|
4781
|
+
return __assign(__assign({}, rrulestr_DEFAULT_OPTIONS), options);
|
|
4782
|
+
}
|
|
4783
|
+
function extractName(line) {
|
|
4784
|
+
if (line.indexOf(":") === -1) return {
|
|
4785
|
+
name: "RRULE",
|
|
4786
|
+
value: line
|
|
4787
|
+
};
|
|
4788
|
+
var _a = split(line, ":", 1);
|
|
4789
|
+
return {
|
|
4790
|
+
name: _a[0],
|
|
4791
|
+
value: _a[1]
|
|
4792
|
+
};
|
|
4793
|
+
}
|
|
4794
|
+
function breakDownLine(line) {
|
|
4795
|
+
var _a = extractName(line), name = _a.name, value = _a.value;
|
|
4796
|
+
var parms = name.split(";");
|
|
4797
|
+
if (!parms) throw new Error("empty property name");
|
|
4798
|
+
return {
|
|
4799
|
+
name: parms[0].toUpperCase(),
|
|
4800
|
+
parms: parms.slice(1),
|
|
4801
|
+
value
|
|
4802
|
+
};
|
|
4803
|
+
}
|
|
4804
|
+
function splitIntoLines(s, unfold) {
|
|
4805
|
+
if (unfold === void 0) unfold = false;
|
|
4806
|
+
s = s && s.trim();
|
|
4807
|
+
if (!s) throw new Error("Invalid empty string");
|
|
4808
|
+
if (!unfold) return s.split(/\s/);
|
|
4809
|
+
var lines = s.split("\n");
|
|
4810
|
+
var i = 0;
|
|
4811
|
+
while (i < lines.length) {
|
|
4812
|
+
var line = lines[i] = lines[i].replace(/\s+$/g, "");
|
|
4813
|
+
if (!line) lines.splice(i, 1);
|
|
4814
|
+
else if (i > 0 && line[0] === " ") {
|
|
4815
|
+
lines[i - 1] += line.slice(1);
|
|
4816
|
+
lines.splice(i, 1);
|
|
4817
|
+
} else i += 1;
|
|
4818
|
+
}
|
|
4819
|
+
return lines;
|
|
4820
|
+
}
|
|
4821
|
+
function validateDateParm(parms) {
|
|
4822
|
+
parms.forEach(function(parm) {
|
|
4823
|
+
if (!/(VALUE=DATE(-TIME)?)|(TZID=)/.test(parm)) throw new Error("unsupported RDATE/EXDATE parm: " + parm);
|
|
4824
|
+
});
|
|
4825
|
+
}
|
|
4826
|
+
function parseRDate(rdateval, parms) {
|
|
4827
|
+
validateDateParm(parms);
|
|
4828
|
+
return rdateval.split(",").map(function(datestr) {
|
|
4829
|
+
return untilStringToDate(datestr);
|
|
4830
|
+
});
|
|
4831
|
+
}
|
|
4832
|
+
function createGetterSetter(fieldName) {
|
|
4833
|
+
var _this = this;
|
|
4834
|
+
return function(field) {
|
|
4835
|
+
if (field !== void 0) _this["_".concat(fieldName)] = field;
|
|
4836
|
+
if (_this["_".concat(fieldName)] !== void 0) return _this["_".concat(fieldName)];
|
|
4837
|
+
for (var i = 0; i < _this._rrule.length; i++) {
|
|
4838
|
+
var field_1 = _this._rrule[i].origOptions[fieldName];
|
|
4839
|
+
if (field_1) return field_1;
|
|
4840
|
+
}
|
|
4841
|
+
};
|
|
4842
|
+
}
|
|
4843
|
+
var RRuleSet = function(_super) {
|
|
4844
|
+
__extends(RRuleSet, _super);
|
|
4845
|
+
/**
|
|
4846
|
+
*
|
|
4847
|
+
* @param {Boolean?} noCache
|
|
4848
|
+
* The same stratagy as RRule on cache, default to false
|
|
4849
|
+
* @constructor
|
|
4850
|
+
*/
|
|
4851
|
+
function RRuleSet(noCache) {
|
|
4852
|
+
if (noCache === void 0) noCache = false;
|
|
4853
|
+
var _this = _super.call(this, {}, noCache) || this;
|
|
4854
|
+
_this.dtstart = createGetterSetter.apply(_this, ["dtstart"]);
|
|
4855
|
+
_this.tzid = createGetterSetter.apply(_this, ["tzid"]);
|
|
4856
|
+
_this._rrule = [];
|
|
4857
|
+
_this._rdate = [];
|
|
4858
|
+
_this._exrule = [];
|
|
4859
|
+
_this._exdate = [];
|
|
4860
|
+
return _this;
|
|
4861
|
+
}
|
|
4862
|
+
RRuleSet.prototype._iter = function(iterResult) {
|
|
4863
|
+
return iterSet(iterResult, this._rrule, this._exrule, this._rdate, this._exdate, this.tzid());
|
|
4864
|
+
};
|
|
4865
|
+
/**
|
|
4866
|
+
* Adds an RRule to the set
|
|
4867
|
+
*
|
|
4868
|
+
* @param {RRule}
|
|
4869
|
+
*/
|
|
4870
|
+
RRuleSet.prototype.rrule = function(rrule) {
|
|
4871
|
+
_addRule(rrule, this._rrule);
|
|
4872
|
+
};
|
|
4873
|
+
/**
|
|
4874
|
+
* Adds an EXRULE to the set
|
|
4875
|
+
*
|
|
4876
|
+
* @param {RRule}
|
|
4877
|
+
*/
|
|
4878
|
+
RRuleSet.prototype.exrule = function(rrule) {
|
|
4879
|
+
_addRule(rrule, this._exrule);
|
|
4880
|
+
};
|
|
4881
|
+
/**
|
|
4882
|
+
* Adds an RDate to the set
|
|
4883
|
+
*
|
|
4884
|
+
* @param {Date}
|
|
4885
|
+
*/
|
|
4886
|
+
RRuleSet.prototype.rdate = function(date) {
|
|
4887
|
+
_addDate(date, this._rdate);
|
|
4888
|
+
};
|
|
4889
|
+
/**
|
|
4890
|
+
* Adds an EXDATE to the set
|
|
4891
|
+
*
|
|
4892
|
+
* @param {Date}
|
|
4893
|
+
*/
|
|
4894
|
+
RRuleSet.prototype.exdate = function(date) {
|
|
4895
|
+
_addDate(date, this._exdate);
|
|
4896
|
+
};
|
|
4897
|
+
/**
|
|
4898
|
+
* Get list of included rrules in this recurrence set.
|
|
4899
|
+
*
|
|
4900
|
+
* @return List of rrules
|
|
4901
|
+
*/
|
|
4902
|
+
RRuleSet.prototype.rrules = function() {
|
|
4903
|
+
return this._rrule.map(function(e) {
|
|
4904
|
+
return rrulestr(e.toString());
|
|
4905
|
+
});
|
|
4906
|
+
};
|
|
4907
|
+
/**
|
|
4908
|
+
* Get list of excluded rrules in this recurrence set.
|
|
4909
|
+
*
|
|
4910
|
+
* @return List of exrules
|
|
4911
|
+
*/
|
|
4912
|
+
RRuleSet.prototype.exrules = function() {
|
|
4913
|
+
return this._exrule.map(function(e) {
|
|
4914
|
+
return rrulestr(e.toString());
|
|
4915
|
+
});
|
|
4916
|
+
};
|
|
4917
|
+
/**
|
|
4918
|
+
* Get list of included datetimes in this recurrence set.
|
|
4919
|
+
*
|
|
4920
|
+
* @return List of rdates
|
|
4921
|
+
*/
|
|
4922
|
+
RRuleSet.prototype.rdates = function() {
|
|
4923
|
+
return this._rdate.map(function(e) {
|
|
4924
|
+
return new Date(e.getTime());
|
|
4925
|
+
});
|
|
4926
|
+
};
|
|
4927
|
+
/**
|
|
4928
|
+
* Get list of included datetimes in this recurrence set.
|
|
4929
|
+
*
|
|
4930
|
+
* @return List of exdates
|
|
4931
|
+
*/
|
|
4932
|
+
RRuleSet.prototype.exdates = function() {
|
|
4933
|
+
return this._exdate.map(function(e) {
|
|
4934
|
+
return new Date(e.getTime());
|
|
4935
|
+
});
|
|
4936
|
+
};
|
|
4937
|
+
RRuleSet.prototype.valueOf = function() {
|
|
4938
|
+
var result = [];
|
|
4939
|
+
if (!this._rrule.length && this._dtstart) result = result.concat(optionsToString({ dtstart: this._dtstart }));
|
|
4940
|
+
this._rrule.forEach(function(rrule) {
|
|
4941
|
+
result = result.concat(rrule.toString().split("\n"));
|
|
4942
|
+
});
|
|
4943
|
+
this._exrule.forEach(function(exrule) {
|
|
4944
|
+
result = result.concat(exrule.toString().split("\n").map(function(line) {
|
|
4945
|
+
return line.replace(/^RRULE:/, "EXRULE:");
|
|
4946
|
+
}).filter(function(line) {
|
|
4947
|
+
return !/^DTSTART/.test(line);
|
|
4948
|
+
}));
|
|
4949
|
+
});
|
|
4950
|
+
if (this._rdate.length) result.push(rdatesToString("RDATE", this._rdate, this.tzid()));
|
|
4951
|
+
if (this._exdate.length) result.push(rdatesToString("EXDATE", this._exdate, this.tzid()));
|
|
4952
|
+
return result;
|
|
4953
|
+
};
|
|
4954
|
+
/**
|
|
4955
|
+
* to generate recurrence field such as:
|
|
4956
|
+
* DTSTART:19970902T010000Z
|
|
4957
|
+
* RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU
|
|
4958
|
+
* RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH
|
|
4959
|
+
*/
|
|
4960
|
+
RRuleSet.prototype.toString = function() {
|
|
4961
|
+
return this.valueOf().join("\n");
|
|
4962
|
+
};
|
|
4963
|
+
/**
|
|
4964
|
+
* Create a new RRuleSet Object completely base on current instance
|
|
4965
|
+
*/
|
|
4966
|
+
RRuleSet.prototype.clone = function() {
|
|
4967
|
+
var rrs = new RRuleSet(!!this._cache);
|
|
4968
|
+
this._rrule.forEach(function(rule) {
|
|
4969
|
+
return rrs.rrule(rule.clone());
|
|
4970
|
+
});
|
|
4971
|
+
this._exrule.forEach(function(rule) {
|
|
4972
|
+
return rrs.exrule(rule.clone());
|
|
4973
|
+
});
|
|
4974
|
+
this._rdate.forEach(function(date) {
|
|
4975
|
+
return rrs.rdate(new Date(date.getTime()));
|
|
4976
|
+
});
|
|
4977
|
+
this._exdate.forEach(function(date) {
|
|
4978
|
+
return rrs.exdate(new Date(date.getTime()));
|
|
4979
|
+
});
|
|
4980
|
+
return rrs;
|
|
4981
|
+
};
|
|
4982
|
+
return RRuleSet;
|
|
4983
|
+
}(RRule);
|
|
4984
|
+
function _addRule(rrule, collection) {
|
|
4985
|
+
if (!(rrule instanceof RRule)) throw new TypeError(String(rrule) + " is not RRule instance");
|
|
4986
|
+
if (!includes(collection.map(String), String(rrule))) collection.push(rrule);
|
|
4987
|
+
}
|
|
4988
|
+
function _addDate(date, collection) {
|
|
4989
|
+
if (!(date instanceof Date)) throw new TypeError(String(date) + " is not Date instance");
|
|
4990
|
+
if (!includes(collection.map(Number), Number(date))) {
|
|
4991
|
+
collection.push(date);
|
|
4992
|
+
sort(collection);
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4995
|
+
function rdatesToString(param, rdates, tzid) {
|
|
4996
|
+
var isUTC = !tzid || tzid.toUpperCase() === "UTC";
|
|
4997
|
+
var header = isUTC ? "".concat(param, ":") : "".concat(param, ";TZID=").concat(tzid, ":");
|
|
4998
|
+
var dateString = rdates.map(function(rdate) {
|
|
4999
|
+
return timeToUntilString(rdate.valueOf(), isUTC);
|
|
5000
|
+
}).join(",");
|
|
5001
|
+
return "".concat(header).concat(dateString);
|
|
5002
|
+
}
|
|
5003
|
+
return __webpack_exports__;
|
|
5004
|
+
})();
|
|
5005
|
+
});
|
|
5006
|
+
})))();
|
|
5007
|
+
const PACKED_DATE_MULTIPLIER = 128;
|
|
5008
|
+
const PACKED_DATE_DAY_MASK = 31;
|
|
5009
|
+
const PACKED_DATE_MONTH_MASK = 15;
|
|
5010
|
+
const PACKED_DATE_MONTH_SHIFT = 5;
|
|
5011
|
+
const PACKED_DATE_YEAR_SHIFT = 9;
|
|
5012
|
+
const THINGS_REMINDER_HOUR_SCALE = 67108864;
|
|
5013
|
+
const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
5014
|
+
const isValidPackedDate = (parts) => isValidDateOnlyParts(parts);
|
|
5015
|
+
const formatFloatingDate = (parts) => {
|
|
5016
|
+
const formatted = parts ? formatDateOnlyParts(parts) : null;
|
|
5017
|
+
return formatted ? `${formatted.replaceAll("-", "")}T000000` : null;
|
|
5018
|
+
};
|
|
5019
|
+
const dateOnlyEpochToLocalMidnightInstant = (epochMs) => {
|
|
5020
|
+
const parts = epochToDateOnlyParts(epochMs);
|
|
5021
|
+
if (!parts) return null;
|
|
5022
|
+
return new Date(parts.year, parts.month - 1, parts.day).getTime();
|
|
5023
|
+
};
|
|
5024
|
+
const decodeThingsPackedDateParts = (value) => {
|
|
5025
|
+
if (!isFiniteNumber(value)) return null;
|
|
5026
|
+
const integer = Math.trunc(value);
|
|
5027
|
+
if (integer <= 0 || integer % PACKED_DATE_MULTIPLIER !== 0) return null;
|
|
5028
|
+
const packed = integer / PACKED_DATE_MULTIPLIER;
|
|
5029
|
+
const parts = {
|
|
5030
|
+
day: packed % (PACKED_DATE_DAY_MASK + 1),
|
|
5031
|
+
month: Math.trunc(packed / 2 ** PACKED_DATE_MONTH_SHIFT) % (PACKED_DATE_MONTH_MASK + 1),
|
|
5032
|
+
year: Math.trunc(packed / 2 ** PACKED_DATE_YEAR_SHIFT)
|
|
5033
|
+
};
|
|
5034
|
+
return isValidPackedDate(parts) ? parts : null;
|
|
5035
|
+
};
|
|
5036
|
+
const decodeThingsPackedDate = (value) => {
|
|
2266
5037
|
const parts = decodeThingsPackedDateParts(value);
|
|
2267
5038
|
if (!parts) return null;
|
|
2268
5039
|
return dateOnlyPartsToEpoch(parts);
|
|
@@ -2380,7 +5151,6 @@ const THINGS_WEEKDAY_TO_RRULE = [
|
|
|
2380
5151
|
"FR",
|
|
2381
5152
|
"SA"
|
|
2382
5153
|
];
|
|
2383
|
-
const { RRule, rrulestr } = rrule;
|
|
2384
5154
|
const parseNumericPlistField = (xml, key) => {
|
|
2385
5155
|
const match = new RegExp(`<key>${key}</key>\\s*<(integer|real)>([^<]+)</\\1>`).exec(xml);
|
|
2386
5156
|
if (!match?.[2]) return null;
|
|
@@ -2406,8 +5176,8 @@ const parseOffsets = (xml) => {
|
|
|
2406
5176
|
};
|
|
2407
5177
|
const parseRRule = (rule) => {
|
|
2408
5178
|
try {
|
|
2409
|
-
const parsed = rrulestr(rule);
|
|
2410
|
-
return parsed instanceof RRule ? parsed : null;
|
|
5179
|
+
const parsed = (0, import_rrule.rrulestr)(rule);
|
|
5180
|
+
return parsed instanceof import_rrule.RRule ? parsed : null;
|
|
2411
5181
|
} catch {
|
|
2412
5182
|
return null;
|
|
2413
5183
|
}
|
|
@@ -2993,8 +5763,6 @@ const pushTaskMutation = (ctx, tasks, taskLabels, checklistItems, mutationOption
|
|
|
2993
5763
|
creatorId: ctx.creatorId,
|
|
2994
5764
|
deadlineAt: decodeThingsPackedDate(mutationOptions.task.deadline),
|
|
2995
5765
|
deadlineSuppressionAt: decodeThingsPackedDate(mutationOptions.task.deadlineSuppressionDate),
|
|
2996
|
-
delegateId: null,
|
|
2997
|
-
delegatedAt: null,
|
|
2998
5766
|
description: appendMetadataBlock(mutationOptions.task.notes, ctx.metadataMode, buildTaskMetadata(mutationOptions.task, contact, buildChecklistOverflowMetadata(mutationOptions.task, ctx.checklistByTaskId))),
|
|
2999
5767
|
headingId: mutationOptions.task.headingId === null ? null : ctx.headingIdBySourceId.get(mutationOptions.task.headingId) ?? null,
|
|
3000
5768
|
lastReminderInteractionAt: decodeThingsUnixSeconds(mutationOptions.task.lastReminderInteractionDate),
|
|
@@ -3867,12 +6635,173 @@ const runLabelShow = async (context, labelRef, options) => {
|
|
|
3867
6635
|
writeInfo(context, `createdAt: ${formatEpochDate(label.createdAt) ?? "(none)"}`);
|
|
3868
6636
|
writeInfo(context, `updatedAt: ${formatEpochDate(label.updatedAt) ?? "(none)"}`);
|
|
3869
6637
|
};
|
|
6638
|
+
const UUID_REGEX$1 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6639
|
+
const resolveTaskForLabel = async (context, options) => {
|
|
6640
|
+
const taskRef = options.taskRef.trim();
|
|
6641
|
+
if (!taskRef) throw new Error("Task id is required.");
|
|
6642
|
+
const exact = await loadTaskById(context, {
|
|
6643
|
+
baseUrl: options.commandContext.apiBaseUrl,
|
|
6644
|
+
taskId: taskRef,
|
|
6645
|
+
token: options.commandContext.token
|
|
6646
|
+
});
|
|
6647
|
+
if (exact) return exact;
|
|
6648
|
+
if (UUID_REGEX$1.test(taskRef)) throw new Error(`Task "${taskRef}" not found.`);
|
|
6649
|
+
if (taskRef.length < 4) throw new Error("Task id prefix must be at least 4 characters.");
|
|
6650
|
+
const { workspace } = await resolveWorkspace(context, {
|
|
6651
|
+
apiBaseUrl: options.commandContext.apiBaseUrl,
|
|
6652
|
+
storedWorkspaceId: options.commandContext.localContext.workspaceId,
|
|
6653
|
+
token: options.commandContext.token,
|
|
6654
|
+
workspaceRef: options.workspaceRef
|
|
6655
|
+
});
|
|
6656
|
+
const matches = (await loadTasksByWorkspace(context, {
|
|
6657
|
+
baseUrl: options.commandContext.apiBaseUrl,
|
|
6658
|
+
token: options.commandContext.token,
|
|
6659
|
+
workspaceId: workspace.id
|
|
6660
|
+
})).filter((task) => task.id.startsWith(taskRef));
|
|
6661
|
+
if (matches.length === 0) throw new Error(`Task "${taskRef}" not found.`);
|
|
6662
|
+
if (matches.length === 1) {
|
|
6663
|
+
const [match] = matches;
|
|
6664
|
+
if (!match) throw new Error(`Task "${taskRef}" not found.`);
|
|
6665
|
+
return match;
|
|
6666
|
+
}
|
|
6667
|
+
throw new Error(`Task prefix "${taskRef}" is ambiguous (${matches.length} matches). Use the full id.`);
|
|
6668
|
+
};
|
|
6669
|
+
const runLabelCreate = async (context, title, options) => {
|
|
6670
|
+
const commandContext = await resolveCommandContext(context);
|
|
6671
|
+
const { workspace } = await resolveWorkspace(context, {
|
|
6672
|
+
apiBaseUrl: commandContext.apiBaseUrl,
|
|
6673
|
+
storedWorkspaceId: commandContext.localContext.workspaceId,
|
|
6674
|
+
token: commandContext.token,
|
|
6675
|
+
workspaceRef: normalizeWorkspaceRef(options.workspace)
|
|
6676
|
+
});
|
|
6677
|
+
const labelId = randomUUID();
|
|
6678
|
+
const now = Date.now();
|
|
6679
|
+
await mutateModel(context, {
|
|
6680
|
+
baseUrl: commandContext.apiBaseUrl,
|
|
6681
|
+
request: {
|
|
6682
|
+
batchId: randomUUID(),
|
|
6683
|
+
transactions: [{
|
|
6684
|
+
action: "INSERT",
|
|
6685
|
+
clientId: commandContext.localContext.clientId,
|
|
6686
|
+
clientTxId: randomUUID(),
|
|
6687
|
+
modelId: labelId,
|
|
6688
|
+
modelName: "Label",
|
|
6689
|
+
payload: {
|
|
6690
|
+
createdAt: now,
|
|
6691
|
+
key: labelId.replaceAll("-", "").slice(0, 8),
|
|
6692
|
+
title: title.trim(),
|
|
6693
|
+
updatedAt: now,
|
|
6694
|
+
workspaceId: workspace.id
|
|
6695
|
+
}
|
|
6696
|
+
}]
|
|
6697
|
+
},
|
|
6698
|
+
token: commandContext.token
|
|
6699
|
+
});
|
|
6700
|
+
if (context.json) {
|
|
6701
|
+
writeOutput(context, {
|
|
6702
|
+
created: true,
|
|
6703
|
+
id: labelId,
|
|
6704
|
+
title: title.trim()
|
|
6705
|
+
});
|
|
6706
|
+
return;
|
|
6707
|
+
}
|
|
6708
|
+
writeSuccess(context, `Created label: ${title.trim()}`);
|
|
6709
|
+
};
|
|
6710
|
+
const runLabelAdd = async (context, taskRef, labelRef, options) => {
|
|
6711
|
+
const commandContext = await resolveCommandContext(context);
|
|
6712
|
+
const workspaceRef = normalizeWorkspaceRef(options.workspace);
|
|
6713
|
+
const task = await resolveTaskForLabel(context, {
|
|
6714
|
+
commandContext,
|
|
6715
|
+
taskRef,
|
|
6716
|
+
workspaceRef
|
|
6717
|
+
});
|
|
6718
|
+
const label = await resolveLabel(context, {
|
|
6719
|
+
commandContext,
|
|
6720
|
+
labelRef,
|
|
6721
|
+
workspaceRef
|
|
6722
|
+
});
|
|
6723
|
+
await mutateModel(context, {
|
|
6724
|
+
baseUrl: commandContext.apiBaseUrl,
|
|
6725
|
+
request: {
|
|
6726
|
+
batchId: randomUUID(),
|
|
6727
|
+
transactions: [{
|
|
6728
|
+
action: "INSERT",
|
|
6729
|
+
clientId: commandContext.localContext.clientId,
|
|
6730
|
+
clientTxId: randomUUID(),
|
|
6731
|
+
modelId: `${task.id}:${label.id}`,
|
|
6732
|
+
modelName: "TaskLabel",
|
|
6733
|
+
payload: {
|
|
6734
|
+
createdAt: Date.now(),
|
|
6735
|
+
labelId: label.id,
|
|
6736
|
+
taskId: task.id,
|
|
6737
|
+
workspaceId: task.workspaceId
|
|
6738
|
+
}
|
|
6739
|
+
}]
|
|
6740
|
+
},
|
|
6741
|
+
token: commandContext.token
|
|
6742
|
+
});
|
|
6743
|
+
if (context.json) {
|
|
6744
|
+
writeOutput(context, {
|
|
6745
|
+
added: true,
|
|
6746
|
+
labelId: label.id,
|
|
6747
|
+
labelTitle: label.title,
|
|
6748
|
+
taskId: task.id
|
|
6749
|
+
});
|
|
6750
|
+
return;
|
|
6751
|
+
}
|
|
6752
|
+
writeSuccess(context, `Added label "${label.title}" to task "${task.title}"`);
|
|
6753
|
+
};
|
|
6754
|
+
const runLabelRemove = async (context, taskRef, labelRef, options) => {
|
|
6755
|
+
const commandContext = await resolveCommandContext(context);
|
|
6756
|
+
const workspaceRef = normalizeWorkspaceRef(options.workspace);
|
|
6757
|
+
const task = await resolveTaskForLabel(context, {
|
|
6758
|
+
commandContext,
|
|
6759
|
+
taskRef,
|
|
6760
|
+
workspaceRef
|
|
6761
|
+
});
|
|
6762
|
+
const label = await resolveLabel(context, {
|
|
6763
|
+
commandContext,
|
|
6764
|
+
labelRef,
|
|
6765
|
+
workspaceRef
|
|
6766
|
+
});
|
|
6767
|
+
await mutateModel(context, {
|
|
6768
|
+
baseUrl: commandContext.apiBaseUrl,
|
|
6769
|
+
request: {
|
|
6770
|
+
batchId: randomUUID(),
|
|
6771
|
+
transactions: [{
|
|
6772
|
+
action: "DELETE",
|
|
6773
|
+
clientId: commandContext.localContext.clientId,
|
|
6774
|
+
clientTxId: randomUUID(),
|
|
6775
|
+
modelId: `${task.id}:${label.id}`,
|
|
6776
|
+
modelName: "TaskLabel",
|
|
6777
|
+
payload: {
|
|
6778
|
+
labelId: label.id,
|
|
6779
|
+
taskId: task.id
|
|
6780
|
+
}
|
|
6781
|
+
}]
|
|
6782
|
+
},
|
|
6783
|
+
token: commandContext.token
|
|
6784
|
+
});
|
|
6785
|
+
if (context.json) {
|
|
6786
|
+
writeOutput(context, {
|
|
6787
|
+
labelId: label.id,
|
|
6788
|
+
labelTitle: label.title,
|
|
6789
|
+
removed: true,
|
|
6790
|
+
taskId: task.id
|
|
6791
|
+
});
|
|
6792
|
+
return;
|
|
6793
|
+
}
|
|
6794
|
+
writeSuccess(context, `Removed label "${label.title}" from task "${task.title}"`);
|
|
6795
|
+
};
|
|
3870
6796
|
const registerLabelCommands = (program, workspaceOverride) => {
|
|
3871
6797
|
const label = program.command("label").alias("labels").description("Manage labels").addHelpText("after", `
|
|
3872
6798
|
Examples:
|
|
3873
6799
|
donebear label
|
|
3874
6800
|
donebear label list --sort alpha
|
|
3875
6801
|
donebear label show bug
|
|
6802
|
+
donebear label create "urgent"
|
|
6803
|
+
donebear label add <task-id> <label>
|
|
6804
|
+
donebear label remove <task-id> <label>
|
|
3876
6805
|
`).action(async (_options, command) => {
|
|
3877
6806
|
const context = contextFromCommand(command);
|
|
3878
6807
|
await runWithErrorHandling(context, async () => {
|
|
@@ -3894,6 +6823,24 @@ Examples:
|
|
|
3894
6823
|
await runLabelShow(context, labelRef, { workspace: workspaceOverride ?? normalizeWorkspaceRef(options.workspace) ?? void 0 });
|
|
3895
6824
|
});
|
|
3896
6825
|
});
|
|
6826
|
+
label.command("create").description("Create a new label").argument("<title>", "Label title").option("-w, --workspace <workspace>", "Workspace id, slug, or exact name").action(async (title, options, command) => {
|
|
6827
|
+
const context = contextFromCommand(command);
|
|
6828
|
+
await runWithErrorHandling(context, async () => {
|
|
6829
|
+
await runLabelCreate(context, title, { workspace: workspaceOverride ?? normalizeWorkspaceRef(options.workspace) ?? void 0 });
|
|
6830
|
+
});
|
|
6831
|
+
});
|
|
6832
|
+
label.command("add").description("Add a label to a task").argument("<task-id>", "Task id or prefix").argument("<label>", "Label id, title, or id prefix").option("-w, --workspace <workspace>", "Workspace id, slug, or exact name").action(async (taskRef, labelRef, options, command) => {
|
|
6833
|
+
const context = contextFromCommand(command);
|
|
6834
|
+
await runWithErrorHandling(context, async () => {
|
|
6835
|
+
await runLabelAdd(context, taskRef, labelRef, { workspace: workspaceOverride ?? normalizeWorkspaceRef(options.workspace) ?? void 0 });
|
|
6836
|
+
});
|
|
6837
|
+
});
|
|
6838
|
+
label.command("remove").alias("rm").description("Remove a label from a task").argument("<task-id>", "Task id or prefix").argument("<label>", "Label id, title, or id prefix").option("-w, --workspace <workspace>", "Workspace id, slug, or exact name").action(async (taskRef, labelRef, options, command) => {
|
|
6839
|
+
const context = contextFromCommand(command);
|
|
6840
|
+
await runWithErrorHandling(context, async () => {
|
|
6841
|
+
await runLabelRemove(context, taskRef, labelRef, { workspace: workspaceOverride ?? normalizeWorkspaceRef(options.workspace) ?? void 0 });
|
|
6842
|
+
});
|
|
6843
|
+
});
|
|
3897
6844
|
};
|
|
3898
6845
|
//#endregion
|
|
3899
6846
|
//#region src/confirm.ts
|
|
@@ -4510,6 +7457,7 @@ const runTaskAdd = async (context, title, options, workspaceOverride) => {
|
|
|
4510
7457
|
creatorId: userId,
|
|
4511
7458
|
deadlineAt: deadlineEpoch,
|
|
4512
7459
|
description: notes,
|
|
7460
|
+
key: taskId.replaceAll("-", "").slice(0, 8),
|
|
4513
7461
|
projectId,
|
|
4514
7462
|
sortOrder: 0,
|
|
4515
7463
|
teamId,
|