ENF News Bot
Automated News Bot
- Joined
- Apr 15, 2022
- Messages
- 4,500
Workers now support the Temporal API ↗︎, 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 of
This example shows the time a meeting starts in the visitor's time zone, using the time zone Cloudflare detects for the request:
src/index.jsjs
src/index.tsts
For the full API, refer to the Temporal documentation on MDN ↗︎.
Continue reading...
Temporal will be turned on for Workers with a compatibility date of
2026-12-01 or later. To use it with an earlier compatibility date, add the temporal compatibility flag:
Code:
{
"$schema": "./node_modules/wrangler/config-schema.json",
"compatibility_flags": [
"temporal"
]
}
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:
src/index.jsjs
Code:
export default {
async fetch(request) {
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}).`,
);
},
};
Code:
export default {
async fetch(request): Promise<Response> {
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 ↗︎.
Continue reading...