diff --git a/src/content/changelog/workers/2026-12-01-temporal-api.mdx b/src/content/changelog/workers/2026-12-01-temporal-api.mdx new file mode 100644 index 00000000000..ff4f59264d2 --- /dev/null +++ b/src/content/changelog/workers/2026-12-01-temporal-api.mdx @@ -0,0 +1,46 @@ +--- +title: The Temporal API is now available in Workers +description: Workers now support Temporal, the modern JavaScript API for dates, times, and time zones. +products: + - workers +date: 2026-12-01 +--- + +import { TypeScriptExample, WranglerConfig } from "~/components"; + +Workers now support the [Temporal API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal), the modern JavaScript standard for dates and times. You can convert between time zones, do calendar-correct date arithmetic, and work with plain dates and times, without bundling a date library such as Moment.js, Luxon, or date-fns. + +Temporal will be turned on for Workers with a [compatibility date](/workers/configuration/compatibility-dates/) of `2026-12-01` or later. To use it with an earlier compatibility date, add the [`temporal`](/workers/configuration/compatibility-flags/#enable-the-temporal-api) compatibility flag: + + + +```toml +compatibility_flags = ["temporal"] +``` + + + +This example shows the time a meeting starts in the visitor's time zone, using the time zone Cloudflare detects for the request: + + + +```ts +export default { + async fetch(request): Promise { + const timeZone = request.cf?.timezone ?? "UTC"; + + const meeting = Temporal.ZonedDateTime.from( + "2026-12-15T09:30[America/New_York]", + ); + const local = meeting.withTimeZone(timeZone); + + return new Response( + `The meeting starts at ${local.toPlainTime()} on ${local.toPlainDate()} (${timeZone}).`, + ); + }, +} satisfies ExportedHandler; +``` + + + +For the full API, refer to the [Temporal documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal). diff --git a/src/content/compatibility-flags/temporal.md b/src/content/compatibility-flags/temporal.md new file mode 100644 index 00000000000..9c11c93cfec --- /dev/null +++ b/src/content/compatibility-flags/temporal.md @@ -0,0 +1,37 @@ +--- +_build: + publishResources: false + render: never + list: never + +name: "Enable the Temporal API" +sort_date: "2026-12-01" +enable_date: "2026-12-01" +enable_flag: "temporal" +disable_flag: "no_temporal" +--- + +Makes the [Temporal API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal) available in your Worker. Temporal is the modern JavaScript standard for working with dates and times, and replaces many of the uses of `Date` and of date libraries such as Moment.js, Luxon, or date-fns. + +With Temporal you can: + +- Convert between time zones, with daylight saving time handled for you. +- Work with plain dates and times, such as a birthday or an opening hour, without a time zone getting in the way. +- Add and subtract durations like "1 month and 3 days" and get calendar-correct results. +- Compare and sort dates and times, and format them for any locale. + +Temporal objects are immutable, so a value never changes after you create it. + +```js +const meeting = Temporal.ZonedDateTime.from( + "2026-12-15T09:30[America/New_York]", +); + +meeting.withTimeZone("Europe/London").toString(); +// "2026-12-15T14:30:00+00:00[Europe/London]" + +meeting.add({ months: 1 }).toPlainDate().toString(); +// "2027-01-15" +``` + +`Temporal.Now` returns the same time as `Date.now()`. For more information, refer to [Performance and timers](/workers/runtime-apis/performance/).