A lightweight polyfill for Temporal, successor to the JavaScript Date object
Overall
score
96%
Evaluation — 96%
↑ 1.19xAgent success when using this tile
Create a small formatting helper that turns the time-based objects produced by the dependency into consistent strings for storage, JSON transport, and locale-aware display. Inputs are the dependency's own time objects created from ISO strings or property bags (points in time with offsets, date-only values, and time-of-day values). The helper should avoid manual string assembly and instead rely on the dependency's built-in string and locale formatting behaviors.
2024-11-19T10:15:30Z and display options { dateStyle: "medium", timeStyle: "long", timeZone: "UTC" }, it returns iso and json fields that exactly match the dependency's default stringification of that value, and a localized field that matches Intl.DateTimeFormat("en-GB", options).format(value) @test2025-05-06 and a fallback time zone of America/New_York, the helper keeps the date-only ISO/JSON outputs unchanged while producing a localized string whose zone-aware components align with Intl.DateTimeFormat("en-US", { dateStyle: "full", timeStyle: "short", timeZone: fallback }) applied to that value @test14:45:00 with display options { timeStyle: "short", timeZone: "Europe/London" }, the helper emits ISO/JSON strings that mirror the dependency defaults and a localized string aligned with the provided locale/timeZone options @test2024-11-19T07:00:00-05:00[America/New_York], an end value parsed from 2024-11-19T09:30:00-05:00[America/New_York], and locale en-US, the helper returns a localizedRange string that matches Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short", timeZone: "America/New_York" }).formatRange(start, end) and preserves the input ordering (start before end) @test@generates
export type TemporalValue = unknown;
export interface FormatOptions {
locale?: string;
timeZone?: string;
display?: Intl.DateTimeFormatOptions;
}
export interface SingleFormatInput extends FormatOptions {
label: string;
value: TemporalValue;
}
export interface RangeFormatInput extends FormatOptions {
label: string;
start: TemporalValue;
end: TemporalValue;
}
export interface SingleFormatResult {
label: string;
iso: string;
json: string;
localized: string;
}
export interface RangeFormatResult {
label: string;
localizedRange: string;
}
export function formatValue(input: SingleFormatInput, fallbackTimeZone?: string): SingleFormatResult;
export function formatRange(input: RangeFormatInput): RangeFormatResult;
export function formatTimeline(
values: SingleFormatInput[],
ranges?: RangeFormatInput[],
fallbackTimeZone?: string
): { values: SingleFormatResult[]; ranges: RangeFormatResult[] };Provides the date/time objects and locale-aware formatting behavior used in this helper.
Install with Tessl CLI
npx tessl i tessl/npm-temporal-polyfilldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10