SSR

Timestamp is designed to work in SSR, SSG, browser, and backend contexts.

The package does not touch window, document, storage APIs, or framework-specific globals. That keeps imports safe during server rendering and static builds.

Server and client timezones

The expected reality is simple: helpers that use the host clock use the timezone of the runtime where they execute.

That means a server in UTC and a browser in America/Edmonton can produce different values if both call today() during render.

For deterministic SSR output:

  • Prefer passing explicit timestamps into helpers.
  • Use caller-provided now values for relative comparisons.
  • Use todayUTC() or nowUTC() when the application wants server and client to agree on UTC calendar fields.
  • Use parseDateUTC() when converting native Date instances that represent instants.
  • Pass a CalendarSystem to todayUTC(), nowUTC(), parseDateUTC(), or updateRelative() when the rendered date fields should be native to an adapter.
import { function nowUTC(date?: Date, calendar?: CalendarSystem): Timestamp
Returns the current date-time as an immutable Timestamp using UTC fields. Use this when server and client output should agree on UTC calendar and time values. For fully deterministic SSR output, pass a Date captured by the caller instead of allowing each runtime to create its own current Date.
@paramdate Date source to read. Defaults to the current Date.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsImmutable Timestamp built from UTC fields.@categorystate
nowUTC
, function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
, function updateRelative(timestamp: Timestamp, now: Timestamp, time?: boolean, calendar?: CalendarSystem): Timestamp
Returns a Timestamp with relative flags compared to a supplied `now` value. The returned object includes `past`, `current`, `future`, and `currentWeekday` flags. Pass `true` for `time` when both values should be compared at time-of-day precision.
@paramtimestamp Timestamp object to update.@paramnow Timestamp representing the comparison point.@paramtime Include time-of-day in the comparison when true.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsNew Timestamp object with relative flags.@categorystate
updateRelative
} from '@timestamp-js/core'
const const now: Timestampnow = function nowUTC(date?: Date, calendar?: CalendarSystem): Timestamp
Returns the current date-time as an immutable Timestamp using UTC fields. Use this when server and client output should agree on UTC calendar and time values. For fully deterministic SSR output, pass a Date captured by the caller instead of allowing each runtime to create its own current Date.
@paramdate Date source to read. Defaults to the current Date.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsImmutable Timestamp built from UTC fields.@categorystate
nowUTC
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+4 overloads)
Date
('2036-06-08T12:00:00.000Z'))
const const target: Timestamptarget = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
('2036-06-09')!
const const stable: Timestampstable = function updateRelative(timestamp: Timestamp, now: Timestamp, time?: boolean, calendar?: CalendarSystem): Timestamp
Returns a Timestamp with relative flags compared to a supplied `now` value. The returned object includes `past`, `current`, `future`, and `currentWeekday` flags. Pass `true` for `time` when both values should be compared at time-of-day precision.
@paramtimestamp Timestamp object to update.@paramnow Timestamp representing the comparison point.@paramtime Include time-of-day in the comparison when true.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsNew Timestamp object with relative flags.@categorystate
updateRelative
(const target: Timestamptarget, const now: Timestampnow)

If the render needs to be stable even when time passes between server render and client hydration, capture the date once in app code and pass it to nowUTC(date) or todayUTC(date). Adapter code can pass the calendar as the second argument.

Date objects

parseDateUTC(date, calendar) reads a native Date using UTC fields and returns fields for the requested calendar. parseDate(date, calendar) reads host-local fields.

import { function nowUTC(date?: Date, calendar?: CalendarSystem): Timestamp
Returns the current date-time as an immutable Timestamp using UTC fields. Use this when server and client output should agree on UTC calendar and time values. For fully deterministic SSR output, pass a Date captured by the caller instead of allowing each runtime to create its own current Date.
@paramdate Date source to read. Defaults to the current Date.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsImmutable Timestamp built from UTC fields.@categorystate
nowUTC
, function parseDate(date: Date, calendar?: CalendarSystem): Timestamp | null
Converts a JavaScript Date into a formatted Timestamp using host-local fields. Use parseDateUTC() when the Date represents an instant that should be read with UTC getters instead of host-local getters.
@paramdate JavaScript Date to convert.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsFormatted Timestamp object, or `null` for invalid input.@categoryparsing
parseDate
, function parseDateUTC(date: Date, calendar?: CalendarSystem): Timestamp | null
Converts a JavaScript Date into a formatted Timestamp using UTC fields. Use this when server and client output should agree on the same UTC calendar and time fields for a native Date instant.
@paramdate JavaScript Date to convert.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsFormatted Timestamp object, or `null` for invalid input.@categoryparsing
parseDateUTC
, function todayUTC(date?: Date, calendar?: CalendarSystem): string
Returns today's date using UTC calendar fields. Pass a Date fixture to make SSR, tests, and hydration-sensitive render paths deterministic. This helper reads UTC fields only; it does not convert an existing Timestamp or timezone-suffixed string. Pass a calendar system to return today's UTC date in that calendar's native `YYYY-MM-DD` fields.
@paramdate Date source to read. Defaults to the current Date.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsUTC date string in the form `YYYY-MM-DD`@categorystate
todayUTC
} from '@timestamp-js/core'
const const instant: Dateinstant = new
var Date: DateConstructor
new (value: number | string | Date) => Date (+4 overloads)
Date
('2036-06-08T09:30:00Z')
const const localTimestamp: Timestamp | nulllocalTimestamp = function parseDate(date: Date, calendar?: CalendarSystem): Timestamp | null
Converts a JavaScript Date into a formatted Timestamp using host-local fields. Use parseDateUTC() when the Date represents an instant that should be read with UTC getters instead of host-local getters.
@paramdate JavaScript Date to convert.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsFormatted Timestamp object, or `null` for invalid input.@categoryparsing
parseDate
(const instant: Dateinstant)
const const utcTimestamp: Timestamp | nullutcTimestamp = function parseDateUTC(date: Date, calendar?: CalendarSystem): Timestamp | null
Converts a JavaScript Date into a formatted Timestamp using UTC fields. Use this when server and client output should agree on the same UTC calendar and time fields for a native Date instant.
@paramdate JavaScript Date to convert.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsFormatted Timestamp object, or `null` for invalid input.@categoryparsing
parseDateUTC
(const instant: Dateinstant)
const const dateOnly: stringdateOnly = function todayUTC(date?: Date, calendar?: CalendarSystem): string
Returns today's date using UTC calendar fields. Pass a Date fixture to make SSR, tests, and hydration-sensitive render paths deterministic. This helper reads UTC fields only; it does not convert an existing Timestamp or timezone-suffixed string. Pass a calendar system to return today's UTC date in that calendar's native `YYYY-MM-DD` fields.
@paramdate Date source to read. Defaults to the current Date.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsUTC date string in the form `YYYY-MM-DD`@categorystate
todayUTC
(const instant: Dateinstant)
const const dateTime: TimestampdateTime = function nowUTC(date?: Date, calendar?: CalendarSystem): Timestamp
Returns the current date-time as an immutable Timestamp using UTC fields. Use this when server and client output should agree on UTC calendar and time values. For fully deterministic SSR output, pass a Date captured by the caller instead of allowing each runtime to create its own current Date.
@paramdate Date source to read. Defaults to the current Date.@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsImmutable Timestamp built from UTC fields.@categorystate
nowUTC
(const instant: Dateinstant)