clone
Clone a Chronos instance maintaining its value and metadata.
clone()
Clones the Chronos instance, creating a new independent instance with the same date value and internal metadata. This is useful for preserving the original's origin tracking and metadata history, even though Chronos instances are immutable.
Signature
clone(): ChronosReturn Type
Chronos - New independent instance with identical date value
Behavior & Notes
- Creates a new instance with the same timestamp as the original
- Preserves the original's internal metadata (origin tracking)
- While
Chronosis immutable, cloning is still useful for:- Maintaining separate metadata histories
- Explicitly creating new instances for semantic clarity
- Working with libraries/frameworks that check object identity
Example
playground.ts
Key Use Cases
- Metadata Preservation
playground.ts
Comparison with Alternatives
| Approach | Instance Identity | Preserves Metadata | Performance |
|---|---|---|---|
clone() | New instance | ✅ Yes | ⚠️ Slight overhead |
new Chronos() | New instance | ❌ No | ⚠️ Slight overhead |
| Direct reference | Same instance | ✅ Yes | ✅ Best |
Tips
Use clone() when you need:
- Explicit control over instance creation
- To preserve metadata history
- Clear code semantics around date derivation
Note
While Chronos's immutability makes cloning less critical for safety, it remains valuable for:
- Tracking different origin points in complex date pipelines
- Integration with systems that care about object identity
- Making derivation operations more explicit in code
Last updated: Thu, May 21, 2026 02:09:18PM (UTC)
