TheDate
TheDate is an immutable class extending Date to manipulate date-time values without accidental mutation. SerializedTheDate is its serialized format for transport and text storage.
Interactive example
Syntax
typescript
class TheDate extends Date
type SerializedTheDate = `date${number}${"-" | "+"}`Relation between TheDate and SerializedTheDate
TheDate: immutable object for application logic.SerializedTheDate: serialized representation for HTTP, JSON, or text storage.- Object -> serialized conversion:
D.serialize(theDate). - Serialized -> object conversion:
D.create(serialized)orD.createOrThrow(serialized).
Use cases
- Safely manipulate date values (
addDays,getYear,format) with an immutable object. - Explicitly serialize when leaving the app boundary (API, message bus, text cache).
See also
create- Builds aTheDatefrom multiple input formats.serialize- ConvertsTheDatetoSerializedTheDate.isSerializedTheDate- Validates the serialized format.
