Skip to content

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) or D.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

Released under the MIT license.