{"record":{"id":"570e20009c6a361d","repo":"clockworklabs/SpacetimeDB","slug":"timestamp-is-outside-of-the-representable-range-fo","errorCode":null,"errorMessage":"Timestamp is outside of the representable range for ISO string formatting","messagePattern":"Timestamp is outside of the representable range for ISO string formatting","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/lib/timestamp.ts","lineNumber":133,"sourceCode":"  }\n\n  /**\n   * Get an ISO 8601 / RFC 3339 formatted string representation of this timestamp with microsecond precision.\n   *\n   * This method preserves the full microsecond precision of the timestamp,\n   * and throws `RangeError` if the `Timestamp` is outside the range representable in ISO format.\n   *\n   * @returns ISO 8601 formatted string with microsecond precision (e.g., '2025-02-17T10:30:45.123456Z')\n   */\n  toISOString(): string {\n    const micros = this.__timestamp_micros_since_unix_epoch__;\n    const millis = micros / Timestamp.MICROS_PER_MILLIS;\n\n    if (\n      millis > BigInt(Number.MAX_SAFE_INTEGER) ||\n      millis < BigInt(Number.MIN_SAFE_INTEGER)\n    ) {\n      throw new RangeError(\n        'Timestamp is outside of the representable range for ISO string formatting'\n      );\n    }\n\n    const date = new Date(Number(millis));\n    const isoBase = date.toISOString(); // Format: '2025-02-17T10:30:45.123Z'\n\n    // Extract the full 6 decimal places of microseconds\n    const microsRemainder = Math.abs(Number(micros % 1000000n));\n    const fractionalPart = String(microsRemainder).padStart(6, '0');\n\n    // Replace the 3-digit millisecond part with the full 6-digit microsecond part\n    return isoBase.replace(/\\.\\d{3}Z$/, `.${fractionalPart}Z`);\n  }\n\n  since(other: Timestamp): TimeDuration {\n    return new TimeDuration(\n      this.__timestamp_micros_since_unix_epoch__ -","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-typescript/src/lib/timestamp.ts#L115-L151","documentation":"The SpacetimeType/table derive machinery maps Rust items onto SATS types: structs become product types and enums become sum types. syn::Data::Union has no SATS representation, so deriving on a union is rejected with a span on the union token.","triggerScenarios":"Applying #[derive(SpacetimeType)] / #[spacetimedb::spacetimedb_type] (or the table attribute, which routes through the same code) to a union item.","commonSituations":"Porting FFI-style code that uses unions for memory layouts; expecting a union to serialize like an untagged variant.","solutions":["Convert the union to an enum whose variants carry each alternative's payload — enums are fully supported sum types.","If the union is only a local layout trick, remove the derive and keep it out of the schema; store a representable type in tables instead."],"exampleFix":"// before\n#[derive(SpacetimeType)]\nunion Value { i: i64, f: f64 }\n\n// after\n#[derive(SpacetimeType)]\nenum Value { Int(i64), Float(f64) }","handlingStrategy":"validation","validationCode":"# CI check: no derives on unions\nrg -nU '#\\[(derive\\([^)]*SpacetimeType|spacetimedb::table[^\\]]*\\)\\]\\s*(pub\\s+)?union' src/ && exit 1 || true","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model alternatives as enums (sum types), never unions, in schema types.","Keep unions confined to non-schema code; do not attach SpacetimeDB derives to them."],"tags":["spacetimedb","proc-macro","derive","union","schema","compile-time"],"backgroundTag":"unsupported-derive-target","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}