tods-competition-factory 1.8.4 → 1.8.6

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/dist/index.mjs CHANGED
@@ -11,9 +11,7 @@ const setTypes$1 = {
11
11
  function stringify(matchUpFormatObject, preserveRedundant) {
12
12
  if (typeof matchUpFormatObject !== "object")
13
13
  return;
14
- if (matchUpFormatObject.timed && !isNaN(matchUpFormatObject.minutes))
15
- return timedSetFormat(matchUpFormatObject);
16
- if (matchUpFormatObject.bestOf && matchUpFormatObject.setFormat)
14
+ if ((matchUpFormatObject.bestOf || matchUpFormatObject.exactly) && matchUpFormatObject.setFormat)
17
15
  return getSetFormat(matchUpFormatObject, preserveRedundant);
18
16
  return void 0;
19
17
  }
@@ -29,11 +27,13 @@ function timedSetFormat(matchUpFormatObject) {
29
27
  return value;
30
28
  }
31
29
  function getSetFormat(matchUpFormatObject, preserveRedundant) {
32
- const bestOfValue = getNumber$1(matchUpFormatObject.bestOf);
33
- if (matchUpFormatObject.setFormat?.timed && matchUpFormatObject.simplified && bestOfValue === 1) {
30
+ const bestOfValue = getNumber$1(matchUpFormatObject.bestOf) || void 0;
31
+ const exactly = getNumber$1(matchUpFormatObject.exactly) || void 0;
32
+ const setLimit = bestOfValue || exactly;
33
+ if (matchUpFormatObject.setFormat?.timed && matchUpFormatObject.simplified && setLimit === 1) {
34
34
  return timedSetFormat(matchUpFormatObject.setFormat);
35
35
  }
36
- const bestOfCode = bestOfValue && `${SET}${bestOfValue}` || "";
36
+ const setLimitCode = setLimit && `${SET}${setLimit}` || "";
37
37
  const setCountValue = stringifySet(
38
38
  matchUpFormatObject.setFormat,
39
39
  preserveRedundant
@@ -43,11 +43,11 @@ function getSetFormat(matchUpFormatObject, preserveRedundant) {
43
43
  matchUpFormatObject.finalSetFormat,
44
44
  preserveRedundant
45
45
  );
46
- const finalSetCode = bestOfValue && bestOfValue > 1 && finalSetCountValue && setCountValue !== finalSetCountValue && // don't include final set code if equivalent to other sets
46
+ const finalSetCode = setLimit && setLimit > 1 && finalSetCountValue && setCountValue !== finalSetCountValue && // don't include final set code if equivalent to other sets
47
47
  `F:${finalSetCountValue}` || "";
48
- const valid = bestOfCode && setCountValue;
48
+ const valid = setLimitCode && setCountValue;
49
49
  if (valid) {
50
- return [bestOfCode, setCode, finalSetCode].filter((f) => f).join("-");
50
+ return [setLimitCode, setCode, finalSetCode].filter((f) => f).join("-");
51
51
  }
52
52
  return void 0;
53
53
  }
@@ -171,231 +171,6 @@ function skewedDistribution(min, max, skew, step, significantDecimals = 2) {
171
171
  return parseFloat(num.toFixed(significantDecimals));
172
172
  }
173
173
 
174
- function parse(matchUpFormatCode) {
175
- if (typeof matchUpFormatCode === "string") {
176
- const type = matchUpFormatCode.startsWith("T") && TIMED || matchUpFormatCode.startsWith(SET) && SET || "";
177
- if (type === TIMED) {
178
- const setFormat = parseTimedSet(matchUpFormatCode);
179
- const parsedFormat = {
180
- simplified: true,
181
- setFormat,
182
- bestOf: 1
183
- };
184
- if (parsedFormat.setFormat)
185
- return parsedFormat;
186
- }
187
- if (type === SET)
188
- return setsMatch(matchUpFormatCode);
189
- }
190
- return void 0;
191
- }
192
- function setsMatch(formatstring) {
193
- const parts = formatstring.split("-");
194
- const bestOf = getNumber(parts[0].slice(3));
195
- const setFormat = parts && parseSetFormat(parts[1]);
196
- const finalSetFormat = parts && parseSetFormat(parts[2]);
197
- const validBestOf = bestOf && bestOf < 6;
198
- const validFinalSet = !parts[2] || finalSetFormat;
199
- const validSetsFormat = setFormat;
200
- const result = { bestOf, setFormat };
201
- if (finalSetFormat)
202
- result.finalSetFormat = finalSetFormat;
203
- if (validBestOf && validSetsFormat && validFinalSet)
204
- return result;
205
- }
206
- function parseSetFormat(formatstring) {
207
- if (formatstring?.[1] === ":") {
208
- const parts = formatstring.split(":");
209
- const setType = setTypes$1[parts[0]];
210
- const setFormatString = parts[1];
211
- if (setType && setFormatString) {
212
- const isTiebreakSet = setFormatString.indexOf("TB") === 0;
213
- if (isTiebreakSet) {
214
- const tiebreakSet = parseTiebreakFormat(setFormatString);
215
- if (tiebreakSet === false)
216
- return false;
217
- return typeof tiebreakSet === "object" ? { tiebreakSet } : void 0;
218
- }
219
- const timedSet = setFormatString.indexOf("T") === 0;
220
- if (timedSet)
221
- return parseTimedSet(setFormatString);
222
- const parts2 = formatstring.match(/^[FS]:(\d+)([A-Za-z]*)/);
223
- const NoAD = parts2 && isNoAD(parts2[2]) || false;
224
- const validNoAD = !parts2?.[2] || NoAD;
225
- const setTo = parts2 ? getNumber(parts2[1]) : void 0;
226
- const tiebreakAtValue = parseTiebreakAt(setFormatString);
227
- const validTiebreakAt = tiebreakAtValue !== false;
228
- const tiebreakAt = validTiebreakAt && tiebreakAtValue || setTo;
229
- const tiebreakFormat = parseTiebreakFormat(setFormatString.split("/")[1]);
230
- const validTiebreak = tiebreakFormat !== false;
231
- const result = { setTo };
232
- if (NoAD)
233
- result.NoAD = true;
234
- if (tiebreakFormat) {
235
- result.tiebreakFormat = tiebreakFormat;
236
- result.tiebreakAt = tiebreakAt;
237
- } else {
238
- result.noTiebreak = true;
239
- }
240
- return setTo && validNoAD && validTiebreak && validTiebreakAt && result || false;
241
- }
242
- }
243
- return void 0;
244
- }
245
- function parseTiebreakAt(setFormatString, expectNumber = true) {
246
- const tiebreakAtValue = setFormatString?.indexOf("@") > 0 && setFormatString.split("@");
247
- if (tiebreakAtValue) {
248
- const tiebreakAt = expectNumber ? getNumber(tiebreakAtValue[1]) : tiebreakAtValue[1];
249
- return tiebreakAt || false;
250
- }
251
- return void 0;
252
- }
253
- function parseTiebreakFormat(formatstring) {
254
- if (formatstring) {
255
- if (formatstring.startsWith("TB")) {
256
- const modifier = parseTiebreakAt(formatstring, false);
257
- const parts = formatstring.match(/^TB(\d+)([A-Za-z]*)/);
258
- const tiebreakToString = parts?.[1];
259
- const NoAD = parts && isNoAD(parts[2]);
260
- const validNoAD = !parts?.[2] || NoAD;
261
- const tiebreakTo = getNumber(tiebreakToString);
262
- if (tiebreakTo && validNoAD) {
263
- const result = { tiebreakTo };
264
- if (modifier && typeof modifier === "string" && !isConvertableInteger(modifier)) {
265
- result.modifier = modifier;
266
- }
267
- if (NoAD)
268
- result.NoAD = true;
269
- return result;
270
- } else {
271
- return false;
272
- }
273
- } else {
274
- return false;
275
- }
276
- }
277
- return void 0;
278
- }
279
- function parseTimedSet(formatstring) {
280
- const timestring = formatstring.slice(1);
281
- const parts = timestring.match(/^(\d+)(@?[A-Za-z]*)/);
282
- const minutes = getNumber(parts?.[1]);
283
- if (!minutes)
284
- return;
285
- const setFormat = { timed: true, minutes };
286
- const based = parts?.[2];
287
- const validModifier = [void 0, "P", "G"].includes(based);
288
- if (based && !validModifier) {
289
- const modifier = timestring.match(/^(\d+)(@)([A-Za-z]+)$/)?.[3];
290
- if (modifier) {
291
- setFormat.modifier = modifier;
292
- return setFormat;
293
- }
294
- return;
295
- }
296
- if (based)
297
- setFormat.based = parts[2];
298
- return setFormat;
299
- }
300
- function isNoAD(formatstring) {
301
- return formatstring && formatstring.indexOf(NOAD) >= 0;
302
- }
303
- function getNumber(formatstring) {
304
- return !isNaN(Number(formatstring)) ? Number(formatstring) : 0;
305
- }
306
-
307
- function isValid(matchUpFormat) {
308
- if (typeof matchUpFormat !== "string")
309
- return false;
310
- const parsedFormat = parse(matchUpFormat);
311
- const setParts = matchUpFormat.match(
312
- /-S:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/
313
- );
314
- const setsTo = setParts?.[1];
315
- const tiebreakTo = setParts?.[2];
316
- const tiebreakAt = setParts?.[3];
317
- const finalSetParts = matchUpFormat.match(
318
- /-F:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/
319
- );
320
- const finalSetTo = finalSetParts?.[1];
321
- const finalSetTiebreakTo = finalSetParts?.[2];
322
- const finalTiebreakAt = finalSetParts?.[3];
323
- const preserveRedundant = !!(setParts && tiebreakTo && setsTo === tiebreakAt || finalSetParts && finalSetTiebreakTo && finalSetTo === finalTiebreakAt);
324
- const stringified = stringify(parsedFormat, preserveRedundant);
325
- return stringified === matchUpFormat;
326
- }
327
-
328
- const matchUpFormatCode = {
329
- isValidMatchUpFormat: isValid,
330
- stringify,
331
- isValid,
332
- parse
333
- };
334
-
335
- function factoryVersion() {
336
- return "1.8.4";
337
- }
338
-
339
- function getObjectTieFormat(obj) {
340
- if (!obj)
341
- return;
342
- const { tieFormatId, tieFormats } = obj;
343
- if (obj.tieFormat) {
344
- return obj.tieFormat;
345
- } else if (tieFormatId && Array.isArray(tieFormats)) {
346
- return tieFormats.find((tf) => tf.tieFormatId === tieFormatId);
347
- }
348
- }
349
-
350
- function getItemTieFormat({ item, drawDefinition, structure, event }) {
351
- if (!item)
352
- return;
353
- if (item.tieFormat)
354
- return item.tieFormat;
355
- if (item.tieFormatId) {
356
- if (drawDefinition.tieFormat)
357
- return drawDefinition.tieFormat;
358
- const tieFormat = drawDefinition.tieFormats?.find(
359
- (tf) => item.tieFormatId === tf.tieFormatId
360
- );
361
- if (tieFormat)
362
- return tieFormat;
363
- if (event.tieFormat)
364
- return event.tieFormat;
365
- return event.tieFormats?.find((tf) => item.tieFormatId === tf.tieFormatId);
366
- }
367
- if (structure.tieFormat)
368
- return structure.tieFormat;
369
- if (structure.tieFormatId) {
370
- const structureTieFormat = drawDefinition.tieFormats?.find(
371
- (tf) => structure.tieFormatId === tf.tieFormatId
372
- );
373
- if (structureTieFormat)
374
- return structureTieFormat;
375
- }
376
- }
377
-
378
- function resolveTieFormat({
379
- drawDefinition,
380
- structure,
381
- matchUp,
382
- event
383
- }) {
384
- return {
385
- tieFormat: getItemTieFormat({
386
- item: matchUp,
387
- drawDefinition,
388
- structure,
389
- event
390
- }) || getItemTieFormat({
391
- item: structure,
392
- drawDefinition,
393
- structure,
394
- event
395
- }) || getObjectTieFormat(drawDefinition) || getObjectTieFormat(event)
396
- };
397
- }
398
-
399
174
  function unique(arr) {
400
175
  return arr.filter((item, i, s) => s.lastIndexOf(item) === i);
401
176
  }
@@ -2230,177 +2005,6 @@ function generateHashCode(o) {
2230
2005
  return [str.length, keyCount, charSum].map((e) => e.toString(36)).join("");
2231
2006
  }
2232
2007
 
2233
- const typeMatch = (arr, type) => arr.filter(Boolean).every((i) => typeof i === type);
2234
- const allNumeric = (arr) => arr.filter(Boolean).every(isNumeric);
2235
- function getCategoryAgeDetails(params) {
2236
- const category = params.category;
2237
- if (typeof category !== "object")
2238
- return { error: INVALID_CATEGORY };
2239
- let { ageCategoryCode, ageMaxDate, ageMinDate, ageMax, ageMin } = category;
2240
- const categoryName = category.categoryName;
2241
- let combinedAge;
2242
- if (!typeMatch(
2243
- [ageCategoryCode, ageMaxDate, ageMinDate, categoryName],
2244
- "string"
2245
- ) || !allNumeric(
2246
- [ageMax, ageMin]
2247
- ))
2248
- return { error: INVALID_CATEGORY };
2249
- const consideredDate = params.consideredDate ?? extractDate((/* @__PURE__ */ new Date()).toLocaleDateString("sv"));
2250
- if (!isValidDateString(consideredDate))
2251
- return { error: INVALID_DATE };
2252
- const [consideredYear] = consideredDate.split("-").slice(0, 3).map((n) => parseInt(n));
2253
- const previousDayDate = dateStringDaysChange(consideredDate, -1);
2254
- const [previousDayMonth, previousDay] = previousDayDate.split("-").slice(1, 3).map((n) => parseInt(n));
2255
- const previousMonthDay = `${zeroPad(previousDayMonth)}-${zeroPad(
2256
- previousDay
2257
- )}`;
2258
- const nextDayDate = dateStringDaysChange(consideredDate, 1);
2259
- const [nextDayMonth, nextDay] = nextDayDate.split("-").slice(1, 3).map((n) => parseInt(n));
2260
- const nextMonthDay = `${zeroPad(nextDayMonth)}-${zeroPad(nextDay)}`;
2261
- let calculatedAgeMaxDate = ageMin && dateStringDaysChange(consideredDate, -1 * 365 * ageMin);
2262
- let calculatedAgeMinDate = ageMax && dateStringDaysChange(consideredDate, -1 * 365 * ageMax);
2263
- const errors = [];
2264
- const addError = (errorString) => !errors.includes(errorString) && errors.push(errorString);
2265
- ageCategoryCode = ageCategoryCode ?? categoryName;
2266
- const prePost = /^([UO]?)(\d{1,2})([UO]?)$/;
2267
- const extractCombined = /^C(\d{1,2})-(\d{1,2})$/;
2268
- const isBetween = ageCategoryCode?.includes("-");
2269
- const isCombined = isBetween && ageCategoryCode?.match(extractCombined);
2270
- const isCoded = ageCategoryCode?.match(prePost);
2271
- const constructedDate = (y, df) => `${y}-${df}`;
2272
- const uPre = (ageInt) => {
2273
- const ageMinYear = consideredYear - ageInt;
2274
- const newMinDate = constructedDate(ageMinYear, nextMonthDay);
2275
- if (category.ageMinDate && category.ageMinDate !== newMinDate)
2276
- addError(`Invalid submitted ageMinDate: ${ageMinDate}`);
2277
- ageMinDate = newMinDate;
2278
- if (ageCategoryCode) {
2279
- if (category.ageMax && category.ageMax !== ageInt - 1) {
2280
- addError(`Invalid submitted ageMax: ${ageMax}`);
2281
- calculatedAgeMinDate = void 0;
2282
- }
2283
- ageMax = ageInt - 1;
2284
- }
2285
- };
2286
- const uPost = (ageInt) => {
2287
- const ageMinYear = consideredYear - ageInt - 1;
2288
- const newMinDate = constructedDate(ageMinYear, nextMonthDay);
2289
- if (category.ageMin && category.ageMin > ageInt) {
2290
- addError(`Invalid submitted ageMin: ${ageMin}`);
2291
- }
2292
- if (category.ageMax && category.ageMax > ageInt) {
2293
- addError(`Invalid submitted ageMax: ${ageMax}`);
2294
- }
2295
- if (category.ageMinDate && category.ageMinDate !== newMinDate)
2296
- addError(`Invalid submitted ageMinDate: ${ageMinDate}`);
2297
- ageMinDate = newMinDate;
2298
- if (ageCategoryCode) {
2299
- if (category.ageMax && category.ageMax !== ageInt) {
2300
- addError(`Invalid submitted ageMax: ${ageMax}`);
2301
- calculatedAgeMaxDate = void 0;
2302
- }
2303
- ageMax = ageInt;
2304
- }
2305
- };
2306
- const oPre = (ageInt) => {
2307
- const ageMaxYear = consideredYear - ageInt;
2308
- const newMaxDate = constructedDate(ageMaxYear, previousMonthDay);
2309
- if (category.ageMaxDate && category.ageMaxDate !== newMaxDate)
2310
- addError(`Invalid submitted ageMaxDate: ${ageMaxDate}`);
2311
- ageMaxDate = newMaxDate;
2312
- if (ageCategoryCode) {
2313
- if (category.ageMin && category.ageMin !== ageInt + 1) {
2314
- addError(`Invalid submitted ageMin: ${ageMin}`);
2315
- calculatedAgeMaxDate = void 0;
2316
- }
2317
- ageMin = ageInt + 1;
2318
- }
2319
- };
2320
- const oPost = (ageInt) => {
2321
- const ageMaxYear = consideredYear - ageInt - 1;
2322
- const newMaxDate = constructedDate(ageMaxYear, previousMonthDay);
2323
- if (category.ageMaxDate && category.ageMaxDate !== newMaxDate)
2324
- addError(`Invalid submitted ageMaxDate: ${ageMaxDate}`);
2325
- ageMaxDate = newMaxDate;
2326
- if (ageCategoryCode) {
2327
- if (category.ageMin && category.ageMin !== ageInt) {
2328
- addError(`Invalid submitted ageMin: ${ageMin}`);
2329
- calculatedAgeMaxDate = void 0;
2330
- }
2331
- ageMin = ageInt;
2332
- }
2333
- };
2334
- const processCode = (code) => {
2335
- const [pre, age, post] = (code.match(prePost) || []).slice(1);
2336
- const ageInt = parseInt(age);
2337
- if (pre === "U") {
2338
- if (category.ageMaxDate && category.ageMaxDate !== ageMaxDate) {
2339
- addError(`Invalid submitted ageMaxDate: ${category.ageMaxDate}`);
2340
- }
2341
- uPre(ageInt);
2342
- } else if (pre === "O") {
2343
- oPre(ageInt);
2344
- }
2345
- if (post === "U") {
2346
- if (category.ageMaxDate && category.ageMaxDate !== ageMaxDate) {
2347
- addError(`Invalid submitted ageMaxDate: ${category.ageMaxDate}`);
2348
- }
2349
- uPost(ageInt);
2350
- } else if (post === "O") {
2351
- oPost(ageInt);
2352
- }
2353
- ageMaxDate = ageMaxDate ?? calculatedAgeMaxDate;
2354
- ageMinDate = ageMinDate ?? calculatedAgeMinDate;
2355
- };
2356
- if (isCombined) {
2357
- ageMaxDate = void 0;
2358
- ageMinDate = void 0;
2359
- ageMax = void 0;
2360
- ageMin = void 0;
2361
- if (category.ageMin) {
2362
- const ageMaxYear = consideredYear - category.ageMin;
2363
- ageMaxDate = constructedDate(ageMaxYear, previousMonthDay);
2364
- }
2365
- if (category.ageMax) {
2366
- const ageMinYear = consideredYear - category.ageMax - 1;
2367
- ageMinDate = constructedDate(ageMinYear, nextMonthDay);
2368
- }
2369
- const [lowAge, highAge] = (ageCategoryCode?.match(extractCombined) ?? []).slice(1).map((n) => parseInt(n));
2370
- if (lowAge <= highAge) {
2371
- ageMin = lowAge;
2372
- ageMax = highAge;
2373
- combinedAge = true;
2374
- } else {
2375
- addError(`Invalid combined age range ${ageCategoryCode}`);
2376
- }
2377
- } else if (isBetween) {
2378
- ageCategoryCode?.split("-").forEach(processCode);
2379
- } else if (isCoded) {
2380
- processCode(ageCategoryCode);
2381
- } else {
2382
- if (ageMin)
2383
- oPre(ageMin);
2384
- if (ageMax)
2385
- uPost(ageMax);
2386
- }
2387
- if (ageMax && category.ageMin && category.ageMin > ageMax) {
2388
- addError(`Invalid submitted ageMin: ${category.ageMin}`);
2389
- ageMin = void 0;
2390
- }
2391
- const result = definedAttributes({
2392
- consideredDate,
2393
- combinedAge,
2394
- ageMaxDate,
2395
- ageMinDate,
2396
- ageMax,
2397
- ageMin
2398
- });
2399
- if (errors.length)
2400
- result.errors = errors;
2401
- return result;
2402
- }
2403
-
2404
2008
  function attributeFilter(params) {
2405
2009
  if (params === null)
2406
2010
  return {};
@@ -2602,6 +2206,409 @@ function UUID() {
2602
2206
  lut[d3 & 255] + lut[d3 >> 8 & 255] + lut[d3 >> 16 & 255] + lut[d3 >> 24 & 255];
2603
2207
  }
2604
2208
 
2209
+ function parse(matchUpFormatCode) {
2210
+ if (typeof matchUpFormatCode === "string") {
2211
+ const type = matchUpFormatCode.startsWith("T") && TIMED || matchUpFormatCode.startsWith(SET) && SET || "";
2212
+ if (type === TIMED) {
2213
+ const setFormat = parseTimedSet(matchUpFormatCode);
2214
+ const parsedFormat = {
2215
+ simplified: true,
2216
+ setFormat,
2217
+ bestOf: 1
2218
+ };
2219
+ if (setFormat)
2220
+ return parsedFormat;
2221
+ }
2222
+ if (type === SET)
2223
+ return setsMatch(matchUpFormatCode);
2224
+ }
2225
+ return void 0;
2226
+ }
2227
+ function setsMatch(formatstring) {
2228
+ const parts = formatstring.split("-");
2229
+ const setsCount = getNumber(parts[0].slice(3));
2230
+ const bestOf = setsCount === 1 || setsCount % 2 !== 0 ? setsCount : void 0;
2231
+ const exactly = setsCount !== 1 && setsCount % 2 === 0 ? setsCount : void 0;
2232
+ const setFormat = parts && parseSetFormat(parts[1]);
2233
+ const finalSetFormat = parts && parseSetFormat(parts[2]);
2234
+ const timed = setFormat && setFormat.timed || finalSetFormat && finalSetFormat.timed;
2235
+ const validSetsCount = bestOf && bestOf < 6 || timed && exactly;
2236
+ const validFinalSet = !parts[2] || finalSetFormat;
2237
+ const validSetsFormat = setFormat;
2238
+ const result = definedAttributes({
2239
+ setFormat,
2240
+ exactly,
2241
+ bestOf
2242
+ });
2243
+ if (finalSetFormat)
2244
+ result.finalSetFormat = finalSetFormat;
2245
+ if (validSetsCount && validSetsFormat && validFinalSet)
2246
+ return result;
2247
+ }
2248
+ function parseSetFormat(formatstring) {
2249
+ if (formatstring?.[1] === ":") {
2250
+ const parts = formatstring.split(":");
2251
+ const setType = setTypes$1[parts[0]];
2252
+ const setFormatString = parts[1];
2253
+ if (setType && setFormatString) {
2254
+ const isTiebreakSet = setFormatString.indexOf("TB") === 0;
2255
+ if (isTiebreakSet) {
2256
+ const tiebreakSet = parseTiebreakFormat(setFormatString);
2257
+ if (tiebreakSet === false)
2258
+ return false;
2259
+ return typeof tiebreakSet === "object" ? { tiebreakSet } : void 0;
2260
+ }
2261
+ const timedSet = setFormatString.indexOf("T") === 0;
2262
+ if (timedSet)
2263
+ return parseTimedSet(setFormatString);
2264
+ const parts2 = formatstring.match(/^[FS]:(\d+)([A-Za-z]*)/);
2265
+ const NoAD = parts2 && isNoAD(parts2[2]) || false;
2266
+ const validNoAD = !parts2?.[2] || NoAD;
2267
+ const setTo = parts2 ? getNumber(parts2[1]) : void 0;
2268
+ const tiebreakAtValue = parseTiebreakAt(setFormatString);
2269
+ const validTiebreakAt = tiebreakAtValue !== false;
2270
+ const tiebreakAt = validTiebreakAt && tiebreakAtValue || setTo;
2271
+ const tiebreakFormat = parseTiebreakFormat(setFormatString.split("/")[1]);
2272
+ const validTiebreak = tiebreakFormat !== false;
2273
+ const result = { setTo };
2274
+ if (NoAD)
2275
+ result.NoAD = true;
2276
+ if (tiebreakFormat) {
2277
+ result.tiebreakFormat = tiebreakFormat;
2278
+ result.tiebreakAt = tiebreakAt;
2279
+ } else {
2280
+ result.noTiebreak = true;
2281
+ }
2282
+ return setTo && validNoAD && validTiebreak && validTiebreakAt && result || false;
2283
+ }
2284
+ }
2285
+ return void 0;
2286
+ }
2287
+ function parseTiebreakAt(setFormatString, expectNumber = true) {
2288
+ const tiebreakAtValue = setFormatString?.indexOf("@") > 0 && setFormatString.split("@");
2289
+ if (tiebreakAtValue) {
2290
+ const tiebreakAt = expectNumber ? getNumber(tiebreakAtValue[1]) : tiebreakAtValue[1];
2291
+ return tiebreakAt || false;
2292
+ }
2293
+ return void 0;
2294
+ }
2295
+ function parseTiebreakFormat(formatstring) {
2296
+ if (formatstring) {
2297
+ if (formatstring.startsWith("TB")) {
2298
+ const modifier = parseTiebreakAt(formatstring, false);
2299
+ const parts = formatstring.match(/^TB(\d+)([A-Za-z]*)/);
2300
+ const tiebreakToString = parts?.[1];
2301
+ const NoAD = parts && isNoAD(parts[2]);
2302
+ const validNoAD = !parts?.[2] || NoAD;
2303
+ const tiebreakTo = getNumber(tiebreakToString);
2304
+ if (tiebreakTo && validNoAD) {
2305
+ const result = { tiebreakTo };
2306
+ if (modifier && typeof modifier === "string" && !isConvertableInteger(modifier)) {
2307
+ result.modifier = modifier;
2308
+ }
2309
+ if (NoAD)
2310
+ result.NoAD = true;
2311
+ return result;
2312
+ } else {
2313
+ return false;
2314
+ }
2315
+ } else {
2316
+ return false;
2317
+ }
2318
+ }
2319
+ return void 0;
2320
+ }
2321
+ function parseTimedSet(formatstring) {
2322
+ const timestring = formatstring.slice(1);
2323
+ const parts = timestring.match(/^(\d+)(@?[A-Za-z]*)/);
2324
+ const minutes = getNumber(parts?.[1]);
2325
+ if (!minutes)
2326
+ return;
2327
+ const setFormat = { timed: true, minutes };
2328
+ const based = parts?.[2];
2329
+ const validModifier = [void 0, "P", "G"].includes(based);
2330
+ if (based && !validModifier) {
2331
+ const modifier = timestring.match(/^(\d+)(@)([A-Za-z]+)$/)?.[3];
2332
+ if (modifier) {
2333
+ setFormat.modifier = modifier;
2334
+ return setFormat;
2335
+ }
2336
+ return;
2337
+ }
2338
+ if (based)
2339
+ setFormat.based = parts[2];
2340
+ return setFormat;
2341
+ }
2342
+ function isNoAD(formatstring) {
2343
+ return formatstring && formatstring.indexOf(NOAD) >= 0;
2344
+ }
2345
+ function getNumber(formatstring) {
2346
+ return !isNaN(Number(formatstring)) ? Number(formatstring) : 0;
2347
+ }
2348
+
2349
+ function isValid(matchUpFormat) {
2350
+ if (typeof matchUpFormat !== "string")
2351
+ return false;
2352
+ const parsedFormat = parse(matchUpFormat);
2353
+ const setParts = matchUpFormat.match(
2354
+ /-S:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/
2355
+ );
2356
+ const setsTo = setParts?.[1];
2357
+ const tiebreakTo = setParts?.[2];
2358
+ const tiebreakAt = setParts?.[3];
2359
+ const finalSetParts = matchUpFormat.match(
2360
+ /-F:([1-9])+\/TB([0-9]{1,2})@?([1-9]?)*/
2361
+ );
2362
+ const finalSetTo = finalSetParts?.[1];
2363
+ const finalSetTiebreakTo = finalSetParts?.[2];
2364
+ const finalTiebreakAt = finalSetParts?.[3];
2365
+ const preserveRedundant = !!(setParts && tiebreakTo && setsTo === tiebreakAt || finalSetParts && finalSetTiebreakTo && finalSetTo === finalTiebreakAt);
2366
+ const stringified = stringify(parsedFormat, preserveRedundant);
2367
+ return stringified === matchUpFormat;
2368
+ }
2369
+
2370
+ const matchUpFormatCode = {
2371
+ isValidMatchUpFormat: isValid,
2372
+ stringify,
2373
+ isValid,
2374
+ parse
2375
+ };
2376
+
2377
+ function factoryVersion() {
2378
+ return "1.8.6";
2379
+ }
2380
+
2381
+ function getObjectTieFormat(obj) {
2382
+ if (!obj)
2383
+ return;
2384
+ const { tieFormatId, tieFormats } = obj;
2385
+ if (obj.tieFormat) {
2386
+ return obj.tieFormat;
2387
+ } else if (tieFormatId && Array.isArray(tieFormats)) {
2388
+ return tieFormats.find((tf) => tf.tieFormatId === tieFormatId);
2389
+ }
2390
+ }
2391
+
2392
+ function getItemTieFormat({ item, drawDefinition, structure, event }) {
2393
+ if (!item)
2394
+ return;
2395
+ if (item.tieFormat)
2396
+ return item.tieFormat;
2397
+ if (item.tieFormatId) {
2398
+ if (drawDefinition.tieFormat)
2399
+ return drawDefinition.tieFormat;
2400
+ const tieFormat = drawDefinition.tieFormats?.find(
2401
+ (tf) => item.tieFormatId === tf.tieFormatId
2402
+ );
2403
+ if (tieFormat)
2404
+ return tieFormat;
2405
+ if (event.tieFormat)
2406
+ return event.tieFormat;
2407
+ return event.tieFormats?.find((tf) => item.tieFormatId === tf.tieFormatId);
2408
+ }
2409
+ if (structure.tieFormat)
2410
+ return structure.tieFormat;
2411
+ if (structure.tieFormatId) {
2412
+ const structureTieFormat = drawDefinition.tieFormats?.find(
2413
+ (tf) => structure.tieFormatId === tf.tieFormatId
2414
+ );
2415
+ if (structureTieFormat)
2416
+ return structureTieFormat;
2417
+ }
2418
+ }
2419
+
2420
+ function resolveTieFormat({
2421
+ drawDefinition,
2422
+ structure,
2423
+ matchUp,
2424
+ event
2425
+ }) {
2426
+ return {
2427
+ tieFormat: getItemTieFormat({
2428
+ item: matchUp,
2429
+ drawDefinition,
2430
+ structure,
2431
+ event
2432
+ }) || getItemTieFormat({
2433
+ item: structure,
2434
+ drawDefinition,
2435
+ structure,
2436
+ event
2437
+ }) || getObjectTieFormat(drawDefinition) || getObjectTieFormat(event)
2438
+ };
2439
+ }
2440
+
2441
+ const typeMatch = (arr, type) => arr.filter(Boolean).every((i) => typeof i === type);
2442
+ const allNumeric = (arr) => arr.filter(Boolean).every(isNumeric);
2443
+ function getCategoryAgeDetails(params) {
2444
+ const category = params.category;
2445
+ if (typeof category !== "object")
2446
+ return { error: INVALID_CATEGORY };
2447
+ let { ageCategoryCode, ageMaxDate, ageMinDate, ageMax, ageMin } = category;
2448
+ const categoryName = category.categoryName;
2449
+ let combinedAge;
2450
+ if (!typeMatch(
2451
+ [ageCategoryCode, ageMaxDate, ageMinDate, categoryName],
2452
+ "string"
2453
+ ) || !allNumeric(
2454
+ [ageMax, ageMin]
2455
+ ))
2456
+ return { error: INVALID_CATEGORY };
2457
+ const consideredDate = params.consideredDate ?? extractDate((/* @__PURE__ */ new Date()).toLocaleDateString("sv"));
2458
+ if (!isValidDateString(consideredDate))
2459
+ return { error: INVALID_DATE };
2460
+ const [consideredYear] = consideredDate.split("-").slice(0, 3).map((n) => parseInt(n));
2461
+ const previousDayDate = dateStringDaysChange(consideredDate, -1);
2462
+ const [previousDayMonth, previousDay] = previousDayDate.split("-").slice(1, 3).map((n) => parseInt(n));
2463
+ const previousMonthDay = `${zeroPad(previousDayMonth)}-${zeroPad(
2464
+ previousDay
2465
+ )}`;
2466
+ const nextDayDate = dateStringDaysChange(consideredDate, 1);
2467
+ const [nextDayMonth, nextDay] = nextDayDate.split("-").slice(1, 3).map((n) => parseInt(n));
2468
+ const nextMonthDay = `${zeroPad(nextDayMonth)}-${zeroPad(nextDay)}`;
2469
+ let calculatedAgeMaxDate = ageMin && dateStringDaysChange(consideredDate, -1 * 365 * ageMin);
2470
+ let calculatedAgeMinDate = ageMax && dateStringDaysChange(consideredDate, -1 * 365 * ageMax);
2471
+ const errors = [];
2472
+ const addError = (errorString) => !errors.includes(errorString) && errors.push(errorString);
2473
+ ageCategoryCode = ageCategoryCode ?? categoryName;
2474
+ const prePost = /^([UO]?)(\d{1,2})([UO]?)$/;
2475
+ const extractCombined = /^C(\d{1,2})-(\d{1,2})$/;
2476
+ const isBetween = ageCategoryCode?.includes("-");
2477
+ const isCombined = isBetween && ageCategoryCode?.match(extractCombined);
2478
+ const isCoded = ageCategoryCode?.match(prePost);
2479
+ const constructedDate = (y, df) => `${y}-${df}`;
2480
+ const uPre = (ageInt) => {
2481
+ const ageMinYear = consideredYear - ageInt;
2482
+ const newMinDate = constructedDate(ageMinYear, nextMonthDay);
2483
+ if (category.ageMinDate && category.ageMinDate !== newMinDate)
2484
+ addError(`Invalid submitted ageMinDate: ${ageMinDate}`);
2485
+ ageMinDate = newMinDate;
2486
+ if (ageCategoryCode) {
2487
+ if (category.ageMax && category.ageMax !== ageInt - 1) {
2488
+ addError(`Invalid submitted ageMax: ${ageMax}`);
2489
+ calculatedAgeMinDate = void 0;
2490
+ }
2491
+ ageMax = ageInt - 1;
2492
+ }
2493
+ };
2494
+ const uPost = (ageInt) => {
2495
+ const ageMinYear = consideredYear - ageInt - 1;
2496
+ const newMinDate = constructedDate(ageMinYear, nextMonthDay);
2497
+ if (category.ageMin && category.ageMin > ageInt) {
2498
+ addError(`Invalid submitted ageMin: ${ageMin}`);
2499
+ }
2500
+ if (category.ageMax && category.ageMax > ageInt) {
2501
+ addError(`Invalid submitted ageMax: ${ageMax}`);
2502
+ }
2503
+ if (category.ageMinDate && category.ageMinDate !== newMinDate)
2504
+ addError(`Invalid submitted ageMinDate: ${ageMinDate}`);
2505
+ ageMinDate = newMinDate;
2506
+ if (ageCategoryCode) {
2507
+ if (category.ageMax && category.ageMax !== ageInt) {
2508
+ addError(`Invalid submitted ageMax: ${ageMax}`);
2509
+ calculatedAgeMaxDate = void 0;
2510
+ }
2511
+ ageMax = ageInt;
2512
+ }
2513
+ };
2514
+ const oPre = (ageInt) => {
2515
+ const ageMaxYear = consideredYear - ageInt;
2516
+ const newMaxDate = constructedDate(ageMaxYear, previousMonthDay);
2517
+ if (category.ageMaxDate && category.ageMaxDate !== newMaxDate)
2518
+ addError(`Invalid submitted ageMaxDate: ${ageMaxDate}`);
2519
+ ageMaxDate = newMaxDate;
2520
+ if (ageCategoryCode) {
2521
+ if (category.ageMin && category.ageMin !== ageInt + 1) {
2522
+ addError(`Invalid submitted ageMin: ${ageMin}`);
2523
+ calculatedAgeMaxDate = void 0;
2524
+ }
2525
+ ageMin = ageInt + 1;
2526
+ }
2527
+ };
2528
+ const oPost = (ageInt) => {
2529
+ const ageMaxYear = consideredYear - ageInt - 1;
2530
+ const newMaxDate = constructedDate(ageMaxYear, previousMonthDay);
2531
+ if (category.ageMaxDate && category.ageMaxDate !== newMaxDate)
2532
+ addError(`Invalid submitted ageMaxDate: ${ageMaxDate}`);
2533
+ ageMaxDate = newMaxDate;
2534
+ if (ageCategoryCode) {
2535
+ if (category.ageMin && category.ageMin !== ageInt) {
2536
+ addError(`Invalid submitted ageMin: ${ageMin}`);
2537
+ calculatedAgeMaxDate = void 0;
2538
+ }
2539
+ ageMin = ageInt;
2540
+ }
2541
+ };
2542
+ const processCode = (code) => {
2543
+ const [pre, age, post] = (code.match(prePost) || []).slice(1);
2544
+ const ageInt = parseInt(age);
2545
+ if (pre === "U") {
2546
+ if (category.ageMaxDate && category.ageMaxDate !== ageMaxDate) {
2547
+ addError(`Invalid submitted ageMaxDate: ${category.ageMaxDate}`);
2548
+ }
2549
+ uPre(ageInt);
2550
+ } else if (pre === "O") {
2551
+ oPre(ageInt);
2552
+ }
2553
+ if (post === "U") {
2554
+ if (category.ageMaxDate && category.ageMaxDate !== ageMaxDate) {
2555
+ addError(`Invalid submitted ageMaxDate: ${category.ageMaxDate}`);
2556
+ }
2557
+ uPost(ageInt);
2558
+ } else if (post === "O") {
2559
+ oPost(ageInt);
2560
+ }
2561
+ ageMaxDate = ageMaxDate ?? calculatedAgeMaxDate;
2562
+ ageMinDate = ageMinDate ?? calculatedAgeMinDate;
2563
+ };
2564
+ if (isCombined) {
2565
+ ageMaxDate = void 0;
2566
+ ageMinDate = void 0;
2567
+ ageMax = void 0;
2568
+ ageMin = void 0;
2569
+ if (category.ageMin) {
2570
+ const ageMaxYear = consideredYear - category.ageMin;
2571
+ ageMaxDate = constructedDate(ageMaxYear, previousMonthDay);
2572
+ }
2573
+ if (category.ageMax) {
2574
+ const ageMinYear = consideredYear - category.ageMax - 1;
2575
+ ageMinDate = constructedDate(ageMinYear, nextMonthDay);
2576
+ }
2577
+ const [lowAge, highAge] = (ageCategoryCode?.match(extractCombined) ?? []).slice(1).map((n) => parseInt(n));
2578
+ if (lowAge <= highAge) {
2579
+ ageMin = lowAge;
2580
+ ageMax = highAge;
2581
+ combinedAge = true;
2582
+ } else {
2583
+ addError(`Invalid combined age range ${ageCategoryCode}`);
2584
+ }
2585
+ } else if (isBetween) {
2586
+ ageCategoryCode?.split("-").forEach(processCode);
2587
+ } else if (isCoded) {
2588
+ processCode(ageCategoryCode);
2589
+ } else {
2590
+ if (ageMin)
2591
+ oPre(ageMin);
2592
+ if (ageMax)
2593
+ uPost(ageMax);
2594
+ }
2595
+ if (ageMax && category.ageMin && category.ageMin > ageMax) {
2596
+ addError(`Invalid submitted ageMin: ${category.ageMin}`);
2597
+ ageMin = void 0;
2598
+ }
2599
+ const result = definedAttributes({
2600
+ consideredDate,
2601
+ combinedAge,
2602
+ ageMaxDate,
2603
+ ageMinDate,
2604
+ ageMax,
2605
+ ageMin
2606
+ });
2607
+ if (errors.length)
2608
+ result.errors = errors;
2609
+ return result;
2610
+ }
2611
+
2605
2612
  function categoryCanContain({
2606
2613
  childCategory,
2607
2614
  withDetails,
@@ -7531,10 +7538,10 @@ function getOrderedDrawPositions({
7531
7538
  const pairedDrawPositions = targetRoundProfile?.pairedDrawPositions;
7532
7539
  const displayOrder = pairedDrawPositions?.find(
7533
7540
  (pair) => overlap(pair || [], drawPositions.filter(Boolean))
7534
- ) || unassignedDrawPositions;
7541
+ ) ?? unassignedDrawPositions;
7535
7542
  const isFeedRound = targetRoundProfile?.feedRound;
7536
7543
  if (allNumeric$1(drawPositions)) {
7537
- const orderedDrawPositions = drawPositions.sort(numericSort);
7544
+ const orderedDrawPositions = [...drawPositions].sort(numericSort);
7538
7545
  return {
7539
7546
  orderedDrawPositions: orderedDrawPositions.length === 2 ? orderedDrawPositions : displayOrder,
7540
7547
  displayOrder: isFeedRound ? orderedDrawPositions : displayOrder
@@ -8268,7 +8275,7 @@ function getAllStructureMatchUps({
8268
8275
  matchUp,
8269
8276
  event: event2
8270
8277
  }) {
8271
- additionalContext = additionalContext || {};
8278
+ additionalContext = additionalContext ?? {};
8272
8279
  const tieFormat = resolveTieFormat({
8273
8280
  drawDefinition,
8274
8281
  structure,
@@ -8279,7 +8286,7 @@ function getAllStructureMatchUps({
8279
8286
  const collectionDefinition = matchUp.collectionId && collectionDefinitions?.find(
8280
8287
  (definition) => definition.collectionId === matchUp.collectionId
8281
8288
  );
8282
- const matchUpFormat = matchUp.collectionId ? collectionDefinition?.matchUpFormat : matchUp.matchUpFormat || structure?.matchUpFormat || drawDefinition?.matchUpFormat || event2?.matchUpFormat;
8289
+ const matchUpFormat = matchUp.collectionId ? collectionDefinition?.matchUpFormat : matchUp.matchUpFormat ?? structure?.matchUpFormat ?? drawDefinition?.matchUpFormat ?? event2?.matchUpFormat;
8283
8290
  const matchUpType = matchUp.matchUpType || collectionDefinition?.matchUpType || structure?.matchUpType || drawDefinition?.matchUpType || event2?.eventType !== TEAM$1 && event2?.eventType;
8284
8291
  const matchUpStatus = isCollectionBye ? BYE : matchUp.matchUpStatus;
8285
8292
  const { schedule, endDate } = getMatchUpScheduleDetails({
@@ -8294,7 +8301,7 @@ function getAllStructureMatchUps({
8294
8301
  });
8295
8302
  const drawPositions = tieDrawPositions ?? matchUp.drawPositions ?? [];
8296
8303
  const { collectionPosition, collectionId, roundPosition } = matchUp;
8297
- const roundNumber = matchUp.roundNumber || additionalContext.roundNumber;
8304
+ const roundNumber = matchUp.roundNumber ?? additionalContext.roundNumber;
8298
8305
  const drawPositionCollectionAssignment = collectionId ? getDrawPositionCollectionAssignment({
8299
8306
  tournamentParticipants,
8300
8307
  positionAssignments,
@@ -8320,7 +8327,7 @@ function getAllStructureMatchUps({
8320
8327
  } : context?.category;
8321
8328
  const processCodes = matchUp.processCodes?.length && matchUp.processCodes || collectionDefinition?.processCodes?.length && collectionDefinition?.processCodes || structure?.processCodes?.length && structure?.processCodes || drawDefinition?.processCodes?.length && drawDefinition?.processCodes || event2?.processCodes?.length && event2?.processCodes || tournamentRecord?.processCodes;
8322
8329
  const competitiveProfile = contextProfile?.withCompetitiveness && getMatchUpCompetitiveProfile({ ...contextContent, matchUp });
8323
- const finishingPositionRange = matchUp.finishingPositionRange || additionalContext.finishingPositionRange;
8330
+ const finishingPositionRange = matchUp.finishingPositionRange ?? additionalContext.finishingPositionRange;
8324
8331
  const onlyDefined = (obj) => definedAttributes(obj, void 0, true);
8325
8332
  const matchUpWithContext = {
8326
8333
  ...onlyDefined(context),
@@ -8328,7 +8335,7 @@ function getAllStructureMatchUps({
8328
8335
  matchUpFormat: matchUp.matchUpType === TEAM$1 ? void 0 : matchUpFormat,
8329
8336
  tieFormat: matchUp.matchUpType !== TEAM$1 ? void 0 : tieFormat,
8330
8337
  roundOfPlay: stage !== QUALIFYING && isConvertableInteger(initialRoundOfPlay2) && initialRoundOfPlay2 + (roundNumber || 0),
8331
- endDate: matchUp.endDate || endDate,
8338
+ endDate: matchUp.endDate ?? endDate,
8332
8339
  gender: collectionDefinition?.gender,
8333
8340
  discipline: event2?.discipline,
8334
8341
  category: matchUpCategory,
@@ -9535,10 +9542,10 @@ function addUpcomingMatchUps({ drawDefinition, inContextDrawMatchUps }) {
9535
9542
  if (structure?.finishingPosition === WIN_RATIO) {
9536
9543
  const { roundNumber } = inContextMatchUp;
9537
9544
  const nextRoundNumber = roundNumber && ensureInt(roundNumber) + 1;
9538
- const matchUps = structure.matchUps || [];
9545
+ const matchUps = structure.matchUps ?? [];
9539
9546
  const { roundMatchUps } = getRoundMatchUps$1({ matchUps });
9540
9547
  if (nextRoundNumber && roundMatchUps?.[nextRoundNumber]) {
9541
- const sidesTo = drawPositions.sort().map((drawPosition, index) => {
9548
+ const sidesTo = [...drawPositions].sort(numericSort).map((drawPosition, index) => {
9542
9549
  const nextRoundMatchUp = roundMatchUps[nextRoundNumber].find(
9543
9550
  (matchUp) => matchUp.drawPositions?.includes(drawPosition)
9544
9551
  );
@@ -11205,7 +11212,7 @@ function getScoreAnalysis({
11205
11212
  const matchUpScoringFormat = parse(matchUpFormat);
11206
11213
  const isDecidingSet = setNumber === matchUpScoringFormat?.bestOf;
11207
11214
  const setFormat = isDecidingSet && matchUpScoringFormat?.finalSetFormat || matchUpScoringFormat?.setFormat || {};
11208
- const isTimedSet = setFormat?.timed || matchUpScoringFormat?.timed;
11215
+ const isTimedSet = setFormat?.timed;
11209
11216
  const finalSet = isDecidingSet && sets[matchUpScoringFormat?.bestOf - 1];
11210
11217
  const finalSetIsComplete = finalSet?.winningSide;
11211
11218
  const { isTiebreakEntry: isSetTiebreakEntry } = testTiebreakEntry({
@@ -17712,7 +17719,7 @@ function getRoundRobinGroupMatchUps({ drawPositions }) {
17712
17719
  return { groupMatchUps, uniqueMatchUpGroupings };
17713
17720
  }
17714
17721
  function drawPositionsHash(drawPositions) {
17715
- return drawPositions.sort(numericSort).join("|");
17722
+ return [...drawPositions].sort(numericSort).join("|");
17716
17723
  }
17717
17724
  function groupRounds({ groupSize, drawPositionOffset }) {
17718
17725
  const numArr = (count) => [...Array(count)].map((_, i) => i);
@@ -17738,7 +17745,7 @@ function groupRounds({ groupSize, drawPositionOffset }) {
17738
17745
  aRow = [aHead, bUp, ...aRow].filter(Boolean);
17739
17746
  bRow = [...bRow, aDown].filter(Boolean);
17740
17747
  const sum = (x) => x[0].reduce((a, b) => a + b);
17741
- return rounds.reverse().sort((a, b) => sum(a) - sum(b)).map(
17748
+ return [...rounds].reverse().sort((a, b) => sum(a) - sum(b)).map(
17742
17749
  (round) => round.filter(
17743
17750
  (groupPositions2) => groupPositions2.every((position) => position <= groupSize)
17744
17751
  ).map((groupPositions2) => {
@@ -19788,6 +19795,7 @@ function getMatchUpContextIds({ matchUps, matchUpId }) {
19788
19795
  }
19789
19796
 
19790
19797
  function addMatchUpScheduledTime$2(params) {
19798
+ const stack = "addMatchUpScheduledTime";
19791
19799
  let matchUp = params.matchUp;
19792
19800
  const {
19793
19801
  removePriorValues,
@@ -19798,27 +19806,18 @@ function addMatchUpScheduledTime$2(params) {
19798
19806
  matchUpId
19799
19807
  } = params;
19800
19808
  if (!matchUpId)
19801
- return { error: MISSING_MATCHUP_ID };
19809
+ return decorateResult({ result: { error: MISSING_MATCHUP_ID }, stack });
19802
19810
  if (!validTimeValue(scheduledTime))
19803
- return { error: INVALID_TIME };
19811
+ return decorateResult({ result: { error: INVALID_TIME }, stack });
19804
19812
  if (!matchUp) {
19805
19813
  const result = findMatchUp$1({ drawDefinition, matchUpId });
19806
19814
  if (result.error)
19807
- return result;
19815
+ return decorateResult({ result, stack });
19808
19816
  matchUp = result.matchUp;
19809
19817
  }
19810
19818
  const timeDate = extractDate(scheduledTime);
19811
- const stack = "addMatchUpScheduledTime";
19812
- if (timeDate) {
19813
- const scheduledDate = scheduledMatchUpDate({ matchUp }).scheduledDate;
19814
- if (scheduledDate && scheduledDate !== timeDate) {
19815
- return decorateResult({
19816
- info: `date in time: ${timeDate} does not corresponde to scheduledDate: ${scheduledDate}`,
19817
- result: { error: INVALID_TIME },
19818
- stack
19819
- });
19820
- }
19821
- }
19819
+ const scheduledDate = scheduledMatchUpDate({ matchUp }).scheduledDate;
19820
+ const keepDate = timeDate && !scheduledDate;
19822
19821
  const existingTimeModifiers = matchUpTimeModifiers({ matchUp }).timeModifiers || [];
19823
19822
  if (existingTimeModifiers?.length) {
19824
19823
  const result = addMatchUpTimeModifiers({
@@ -19831,9 +19830,9 @@ function addMatchUpScheduledTime$2(params) {
19831
19830
  matchUp
19832
19831
  });
19833
19832
  if (result?.error)
19834
- return result;
19833
+ return decorateResult({ result, stack });
19835
19834
  }
19836
- const militaryTime = convertTime(scheduledTime, true, true);
19835
+ const militaryTime = convertTime(scheduledTime, true, keepDate);
19837
19836
  const itemValue = militaryTime;
19838
19837
  const timeItem = {
19839
19838
  itemType: SCHEDULED_TIME,
@@ -19858,14 +19857,19 @@ function addMatchUpTimeModifiers({
19858
19857
  matchUpId,
19859
19858
  matchUp
19860
19859
  }) {
19860
+ const stack = "addMatchUpTimeModifiers";
19861
19861
  if (!matchUpId)
19862
- return { error: MISSING_MATCHUP_ID };
19862
+ return decorateResult({ result: { error: MISSING_MATCHUP_ID }, stack });
19863
19863
  if (timeModifiers !== void 0 && !Array.isArray(timeModifiers))
19864
- return { error: INVALID_VALUES, info: mustBeAnArray("timeModifiers") };
19864
+ return decorateResult({
19865
+ info: mustBeAnArray("timeModifiers"),
19866
+ result: { error: INVALID_VALUES },
19867
+ stack
19868
+ });
19865
19869
  if (!matchUp) {
19866
19870
  const result = findMatchUp$1({ drawDefinition, matchUpId });
19867
19871
  if (result.error)
19868
- return result;
19872
+ return decorateResult({ result, stack });
19869
19873
  matchUp = result.matchUp;
19870
19874
  }
19871
19875
  let existingTimeModifiers = matchUpTimeModifiers({ matchUp }).timeModifiers || [];
@@ -19890,7 +19894,7 @@ function addMatchUpTimeModifiers({
19890
19894
  matchUpId
19891
19895
  });
19892
19896
  if (result.error)
19893
- return result;
19897
+ return decorateResult({ result, stack });
19894
19898
  }
19895
19899
  const itemValue = !timeModifiers?.length ? void 0 : [...toBeAdded, ...existingTimeModifiers];
19896
19900
  const timeItem = {
@@ -36109,7 +36113,8 @@ function bulkRescheduleMatchUps$1({
36109
36113
  scheduledTime,
36110
36114
  minutesChange
36111
36115
  );
36112
- newScheduledTime = scheduledTimeDate && newScheduledDate ? `${newScheduledDate}T${timeString}` : timeString;
36116
+ const timeStringDate = scheduledTimeDate && newScheduledDate || scheduledDate === scheduledTimeDate && scheduledTimeDate;
36117
+ newScheduledTime = timeStringDate ? `${timeStringDate}T${timeString}` : timeString;
36113
36118
  }
36114
36119
  }
36115
36120
  if (doNotReschedule) {