# Structured Clone Algorithm vs Temporal API and Timezone-Safe Dates

- **Canonical URL:** https://frontend.rocks/vs/structured-clone-algorithm-vs-temporal-api-dates/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** structuredClone() clones legacy Date internal slots natively, whereas Temporal objects require explicit ISO string serialization.

## Comparison Matrix

| Dimension | Structured Clone Algorithm | Temporal API and Timezone-Safe Dates |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Experimental |
| **Domain** | JS Runtime | JS Runtime |
| **Mental Model** | Deep-copy cyclic JS graphs, Maps, Sets, and Date objects without JSON.stringify data loss—and transfer ArrayBuffers to workers with zero-copy overhead. | Eliminate mutable Date bugs, 0-indexed month traps, and DST off-by-one-hour errors—Temporal separates physical Instants from wall-clock PlainDate and ZonedDateTime. |
| **Prerequisites** | Prototype Chain Lookup and Delegation (Structured clone copies own enumerable properties and discards custom [[Prototype]] chains.) | Prototype Chain Lookup and Delegation (Temporal types expose immutable value methods on dedicated prototypes without mutating receivers.) |
| **When Not to Use** | When not to use structuredClone(): Never use structuredClone() to clone class instances when you need their methods or prototype chain intact, or for Temporal API objects (serialize them as ISO strings instead). | When not to use Temporal.Instant: Never use Instant for future birthdays or recurring 9 AM meetings, if a country changes its DST law, an Instant shifts on the local clock; store PlainDate or ZonedDateTime instead. |

## Structured Clone Algorithm — Under the Hood
The HTML `StructuredSerializeInternal` algorithm walks object graphs in C++ while maintaining a visited-object memory map to preserve cycles and shared references. Built-in internal slots serialize natively, custom `[[Prototype]]` chains are stripped to plain `Object` shells, and functions or DOM nodes throw `DataCloneError`.

1. **Memory Map Deduplication**: The engine tracks visited objects in an internal map so circular references and shared sub-objects clone once.
2. **Type-Tagged Serialization**: Built-in internal slots (`[[DateValue]]`, `[[MapData]]`, `[[ArrayBufferData]]`) serialize natively in C++.
3. **Prototype Stripping**: Cloned class instances become plain `Object` shells without methods.
4. **Transfer Semantics**: Passing `[buffer]` in `{ transfer }` detaches the buffer in the sender realm for zero-copy [Garbage Collection](/concepts/js-garbage-collection) cleanup.

```js
const payload = { created: new Date(), items: new Set([1, 2]) };
payload.self = payload; // Cyclic reference

const clone = structuredClone(payload);
console.log(clone.self === clone); // true
console.log(clone.items instanceof Set); // true
```

## Temporal API and Timezone-Safe Dates — Under the Hood
`Temporal` replaces `Date`'s single mutable epoch-millisecond slot with distinct immutable types: `Instant` for physical time, `PlainDate` for calendar dates, and `ZonedDateTime` backed by ICU4X IANA timezone tables. Engines enforce explicit conversions across these boundaries, eliminating silent UTC-offset and DST arithmetic bugs.

1. **Strict Type Boundaries**: Engines enforce explicit conversions between `PlainDate` and `ZonedDateTime`, exposing immutable methods via dedicated [Prototype Chains](/concepts/prototype-chain-lookup).
2. **ICU4X Timezone Rules**: `ZonedDateTime.add({ days: 1 })` consults IANA transition tables so 23-hour and 25-hour DST days keep the same wall-clock hour.
3. **Serialization**: Unlike `Date` in [Structured Clone](/concepts/structured-clone-algorithm), `Temporal` values serialize cleanly via `.toString()` (RFC 9557) across workers and JSON.

```js
const nyMeeting = Temporal.ZonedDateTime.from(
  '2026-03-08T09:00:00[America/New_York]'
);
// Crosses spring-forward DST cleanly at 09:00 local time
const nextDay = nyMeeting.add({ days: 1 });
console.log(nextDay.toString());
```

## Interactive Labs & Dissections
- [Structured Clone Algorithm Lab](https://frontend.rocks/concepts/structured-clone-algorithm/#lab) ([Markdown](https://frontend.rocks/concepts/structured-clone-algorithm.md))
- [Temporal API and Timezone-Safe Dates Lab](https://frontend.rocks/concepts/temporal-api-dates/#lab) ([Markdown](https://frontend.rocks/concepts/temporal-api-dates.md))

## Primary Sources
- https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal
- https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
- https://tc39.es/proposal-temporal/docs/
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal
