{"version":3,"file":"_randomFormatDatetime.mjs","names":[],"sources":["../../src/internal/_randomFormatDatetime.ts"],"sourcesContent":["import {\n  _ILengthProps,\n  _RANDOM_LENGTH_ERROR,\n  _randomLengthPick,\n  _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomDigits } from \"./private/__randomComposition\";\nimport { __IEpochProps, __randomEpoch } from \"./private/__randomEpoch\";\n\n/**\n * Generate an RFC 3339 date-time with a `Z` offset at a length the bounds\n * allow. Custom epoch bounds must stay within valid Date instants with\n * four-digit ISO years, which the fixed-width second-precision prefix assumes.\n *\n * @evidence contracts/common.md#principled-implementation Within valid Date bounds with four-digit ISO years, an unconstrained draw is a random instant in ISO text; a constrained one keeps the fixed-width second-precision prefix and chooses either a `Z` suffix or a fraction of the digits needed, avoiding length21 and throwing when the window holds no valid length. Custom expanded-year bounds are outside this fixed-width contract.\n * @evidence contracts/common.md#clear-and-simple-design One function over the length window and digit helpers.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The length rules are those of RFC 3339 timestamps with a `Z` offset.\n * @evidence contracts/common.md#meaningful-documentation The inline comments explain the length arithmetic.\n */\nexport const _randomFormatDatetime = (\n  props?: __IEpochProps & _ILengthProps,\n) => {\n  const instant = (): string => new Date(__randomEpoch(props)).toISOString();\n  if (props?.minLength === undefined && props?.maxLength === undefined)\n    return instant();\n  // `YYYY-MM-DDTHH:MM:SS` plus `Z` is the shortest instant, and a fractional\n  // second grows it one digit at a time. Because that fraction needs both a dot\n  // and at least one digit, 21 is the single length between the two forms that\n  // no instant can have.\n  const window = _randomLengthWindow(props, {\n    minimum: SECONDS + 1,\n    spread: 8,\n  });\n  let length: number = _randomLengthPick(window);\n  if (length === SECONDS + 2)\n    length = window.high >= SECONDS + 3 ? SECONDS + 3 : SECONDS + 1;\n  if (length < window.low || length > window.high)\n    throw new Error(_RANDOM_LENGTH_ERROR);\n  const base: string = instant().substring(0, SECONDS);\n  return length === SECONDS + 1\n    ? `${base}Z`\n    : `${base}.${__randomDigits(length - SECONDS - 2)}Z`;\n};\n\nconst SECONDS = \"0000-00-00T00:00:00\".length;\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAa,yBACX,UACG;CACH,MAAM,gBAAwB,IAAI,KAAK,cAAc,KAAK,CAAC,CAAC,CAAC,YAAY;CACzE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,QAAQ;CAKjB,MAAM,SAAS,oBAAoB,OAAO;EACxC,SAAS,UAAU;EACnB,QAAQ;CACV,CAAC;CACD,IAAI,SAAiB,kBAAkB,MAAM;CAC7C,IAAI,WAAW,UAAU,GACvB,SAAS,OAAO,QAAQ,UAAU,IAAI,UAAU,IAAI,UAAU;CAChE,IAAI,SAAS,OAAO,OAAO,SAAS,OAAO,MACzC,MAAM,IAAI,MAAM,oBAAoB;CACtC,MAAM,OAAe,QAAQ,CAAC,CAAC,UAAU,GAAG,OAAO;CACnD,OAAO,WAAW,UAAU,IACxB,GAAG,KAAK,KACR,GAAG,KAAK,GAAG,eAAe,SAAS,UAAU,CAAC,EAAE;AACtD;AAEA,MAAM,UAAU"}