{"version":3,"file":"_randomFormatTime.mjs","names":[],"sources":["../../src/internal/_randomFormatTime.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {\n  _ILengthProps,\n  _RANDOM_LENGTH_ERROR,\n  _randomLengthPick,\n  _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomDigits } from \"./private/__randomComposition\";\n\n/**\n * Generate an RFC 3339 time with an offset at a length the bounds allow.\n *\n * Constrained output lengths are nine or at least 11 characters; ten is\n * unreachable because a fractional part needs a dot and a digit. An allowed\n * window containing no such length throws. Samples use ordinary seconds from a\n * UTC clock, with either Z or a numeric offset, rather than leap seconds.\n *\n * @evidence contracts/common.md#principled-implementation An unconstrained draw is the clock part of a random instant, and a constrained one writes `HH:MM:SS` with either a `Z` offset or a numeric offset and a fraction, choosing the form that fits the window, with the single unreachable length of ten excluded and an empty window throwing.\n * @evidence contracts/common.md#clear-and-simple-design One function with small offset helpers.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The length arithmetic follows RFC 3339 and is explained inline.\n * @evidence contracts/common.md#meaningful-documentation Native prose states the length gap, impossible-window failure and ordinary-second sample policy; inline comments justify the fraction/offset arithmetic.\n */\nexport const _randomFormatTime = (props?: _ILengthProps): string => {\n  const clock = (): string =>\n    new Date(\n      _randomInteger({ type: \"integer\", minimum: 0, maximum: DAY }),\n    ).toISOString();\n  if (props?.minLength === undefined && props?.maxLength === undefined)\n    return clock().substring(11);\n  // `HH:MM:SS` carries a mandatory offset — one character as `Z`, six as\n  // `+HH:MM` — and an optional fraction between them that RFC 3339 leaves\n  // open above. Together they express 9 and every length from 11 upward; 10 is\n  // the one gap, because a fraction needs both a dot and a digit.\n  const window = _randomLengthWindow(props, {\n    minimum: CLOCK + 1,\n    spread: 6,\n  });\n  let length: number = _randomLengthPick(window);\n  if (length === CLOCK + 2)\n    length = window.high >= CLOCK + 3 ? CLOCK + 3 : CLOCK + 1;\n  if (length < window.low || length > window.high)\n    throw new Error(_RANDOM_LENGTH_ERROR);\n  const base: string = clock().substring(11, 11 + CLOCK);\n  if (length === CLOCK + 1) return `${base}Z`;\n  // The `Z` form reaches every remaining length by itself, so the numeric\n  // offset is a choice rather than a fallback: it spends six characters, which\n  // leaves either nothing (14, `HH:MM:SS+HH:MM`) or a whole fraction (16 and\n  // up). At 15 only the `Z` form fits, since the offset would demand a dot\n  // with no digit after it.\n  const fraction: number = length - CLOCK - OFFSET - 1;\n  return (fraction === -1 || fraction >= 1) &&\n    _randomInteger({ type: \"integer\", minimum: 0, maximum: 1 }) === 1\n    ? fraction === -1\n      ? `${base}${offset()}`\n      : `${base}.${__randomDigits(fraction)}${offset()}`\n    : `${base}.${__randomDigits(length - CLOCK - 2)}Z`;\n};\n\nconst DAY = 86_400_000;\nconst CLOCK = \"00:00:00\".length;\nconst OFFSET = \"+00:00\".length;\n\nconst offset = (): string =>\n  `${_randomInteger({ type: \"integer\", minimum: 0, maximum: 1 }) === 0 ? \"+\" : \"-\"}${pad(\n    _randomInteger({ type: \"integer\", minimum: 0, maximum: 23 }),\n  )}:${pad(_randomInteger({ type: \"integer\", minimum: 0, maximum: 59 }))}`;\n\nconst pad = (value: number): string => String(value).padStart(2, \"0\");\n"],"mappings":";;;;;;;;;;;;;;;;;AAsBA,MAAa,qBAAqB,UAAkC;CAClE,MAAM,cACJ,IAAI,KACF,eAAe;EAAE,MAAM;EAAW,SAAS;EAAG,SAAS;CAAI,CAAC,CAC9D,CAAC,CAAC,YAAY;CAChB,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,MAAM,CAAC,CAAC,UAAU,EAAE;CAK7B,MAAM,SAAS,oBAAoB,OAAO;EACxC,SAAS,QAAQ;EACjB,QAAQ;CACV,CAAC;CACD,IAAI,SAAiB,kBAAkB,MAAM;CAC7C,IAAI,WAAW,QAAQ,GACrB,SAAS,OAAO,QAAQ,QAAQ,IAAI,QAAQ,IAAI,QAAQ;CAC1D,IAAI,SAAS,OAAO,OAAO,SAAS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