SSR And Runtime

Timestamp is framework-agnostic and does not read browser globals. That makes it safe to import in browser apps, Node.js, SSR builds, serverless functions, workers, and tests.

The SSR detail to watch is not the import itself. It is whether your code asks the runtime for the current date or locale-dependent labels during render.

Prefer explicit inputs during render

If server and client run in different timezones, today() can produce different values.

import { 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 renderedNow: TimestamprenderedNow = 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-08')!
const const event: Timestampevent = 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-10')!
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 event: Timestampevent, const renderedNow: TimestamprenderedNow)
const stable: Timestampstable.Timestamp.future?: boolean | undefined
True when the timestamp is after a comparison timestamp.
future
// true

Use today checks outside hydration-sensitive render paths

today(calendar) and isToday(date, calendar) are convenient for client-only actions, tests with mocked time, and server logic that owns its timezone. They use the host runtime’s local timezone and return/compare date fields for the requested calendar.

import { function isToday(date: string, calendar?: CalendarSystem): boolean
Takes a date string ('YYYY-MM-DD') and validates if it is today's date
@paramdate Date string in the form 'YYYY-MM-DD'@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsTrue if the date is today's date@categorycomparison
isToday
, function today(calendar?: CalendarSystem): string
Returns today's date using the host runtime timezone. For SSR or static rendering, server and client runtimes can produce different values when they run in different timezones. Use todayUTC() when the app wants a stable UTC calendar date instead. Pass a calendar system to return today's date in that calendar's native `YYYY-MM-DD` fields.
@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsDate string in the form `YYYY-MM-DD`@categorystate
today
} from '@timestamp-js/core'
const const currentDate: stringcurrentDate = function today(calendar?: CalendarSystem): string
Returns today's date using the host runtime timezone. For SSR or static rendering, server and client runtimes can produce different values when they run in different timezones. Use todayUTC() when the app wants a stable UTC calendar date instead. Pass a calendar system to return today's date in that calendar's native `YYYY-MM-DD` fields.
@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsDate string in the form `YYYY-MM-DD`@categorystate
today
()
function isToday(date: string, calendar?: CalendarSystem): boolean
Takes a date string ('YYYY-MM-DD') and validates if it is today's date
@paramdate Date string in the form 'YYYY-MM-DD'@paramcalendar Calendar system to use. Defaults to Gregorian; pass an adapter such as islamicCivilCalendar for native calendar fields.@returnsTrue if the date is today's date@categorycomparison
isToday
(const currentDate: stringcurrentDate) // true

Use UTC helpers when the app wants UTC calendar fields

todayUTC(date, calendar) returns a UTC date string. nowUTC(date, calendar) returns an immutable Timestamp built from UTC date-time fields. Pass a Date fixture when SSR output must be deterministic across server render and client hydration. Pass a calendar adapter when the date fields should be native to that calendar.

import { function isTodayUTC(date: string, now?: Date, calendar?: CalendarSystem): boolean
Checks whether a date string matches today's UTC date. Pass a Date fixture when SSR, tests, or hydration-sensitive render paths need deterministic behavior.
@paramdate Date string in the form `YYYY-MM-DD`.@paramnow 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.@returnsTrue when the date matches the UTC date.@categorycomparison
isTodayUTC
, 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 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 renderedAt: DaterenderedAt = new
var Date: DateConstructor
new (value: number | string | Date) => Date (+4 overloads)
Date
('2036-06-08T23:59:15.250Z')
const const date: stringdate = 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 renderedAt: DaterenderedAt)
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
(const renderedAt: DaterenderedAt)
const const matches: booleanmatches = function isTodayUTC(date: string, now?: Date, calendar?: CalendarSystem): boolean
Checks whether a date string matches today's UTC date. Pass a Date fixture when SSR, tests, or hydration-sensitive render paths need deterministic behavior.
@paramdate Date string in the form `YYYY-MM-DD`.@paramnow 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.@returnsTrue when the date matches the UTC date.@categorycomparison
isTodayUTC
('2036-06-08', const renderedAt: DaterenderedAt)
const date: stringdate // "2036-06-08" const now: Timestampnow.Timestamp.time?: string | undefined
Formatted time string. Minute precision is formatted as `HH:mm`; second precision as `HH:mm:ss`; millisecond precision as `HH:mm:ss.SSS`.
time
// "23:59:15.250"
const matches: booleanmatches // true

Use UTC conversion when the source is an instant

When your input is a native Date, use parseDateUTC(date, calendar) to read UTC fields. Use parseDate(date, calendar) when you want host-local fields.

import { function getDateTime(timestamp: Timestamp): string
Formats a Timestamp as date plus time.
@paramtimestamp Timestamp object to format.@returnsDate-time string such as `YYYY-MM-DD HH:mm`.@categoryconversion
getDateTime
, 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
} from '@timestamp-js/core'
const const instant: Dateinstant = new
var Date: DateConstructor
new (value: number | string | Date) => Date (+4 overloads)
Date
('2026-06-08T09:30:00.000Z')
const const timestamp: Timestamp | nulltimestamp = 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)
function getDateTime(timestamp: Timestamp): string
Formats a Timestamp as date plus time.
@paramtimestamp Timestamp object to format.@returnsDate-time string such as `YYYY-MM-DD HH:mm`.@categoryconversion
getDateTime
(const timestamp: Timestamp | nulltimestamp!) // "2026-06-08 09:30"

Pass locales explicitly

Intl.DateTimeFormat can use the host default locale. Pass a locale when labels are rendered on both server and client.

import { function getMonthNames(type: string, locale: string): string[]
Retrieves localized month names.
@paramtype Format type: `narrow`, `short`, or `long`.@paramlocale Locale to use for formatting, such as `en-US`.@returnsLocalized month names in January-first order.@categorylocale
getMonthNames
, function getWeekdayNames(type: string, locale: string): string[]
Retrieves localized weekday names.
@paramtype Format type: `narrow`, `short`, or `long`.@paramlocale Locale to use for formatting, such as `en-US`.@returnsLocalized weekday names in Sunday-first order.@categorylocale
getWeekdayNames
} from '@timestamp-js/core'
const const weekdays: string[]weekdays = function getWeekdayNames(type: string, locale: string): string[]
Retrieves localized weekday names.
@paramtype Format type: `narrow`, `short`, or `long`.@paramlocale Locale to use for formatting, such as `en-US`.@returnsLocalized weekday names in Sunday-first order.@categorylocale
getWeekdayNames
('long', 'en-US')
const const months: string[]months = function getMonthNames(type: string, locale: string): string[]
Retrieves localized month names.
@paramtype Format type: `narrow`, `short`, or `long`.@paramlocale Locale to use for formatting, such as `en-US`.@returnsLocalized month names in January-first order.@categorylocale
getMonthNames
('long', 'en-US')
const weekdays: string[]weekdays[0] // "Sunday" const months: string[]months[0] // "January"

Test with injected dates

Tests are more stable when the current date is an explicit fixture.

import { 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 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
('2026-06-08')!
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
('2026-06-07')!
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).Timestamp.past?: boolean | undefined
True when the timestamp is before a comparison timestamp.
past
// true