Eleventy date filter applies host timezone instead of preserving UTC offset
0 reputation · 07 Sept 2023, 16:19 UTC
0 reputation · 07 Sept 2023, 16:19 UTC
The built-in date filter formats timestamps using Intl.DateTimeFormat, but when a UTC-ending string such as 2026-10-11T01:50:47Z is passed, the resulting output reflects the build machine’s local zone rather than the original offset.
Eleventy constructs a Date via new Date(input), which interprets the string in the host environment’s time zone unless an explicit offset is supplied. The filter does not perform IANA-zone conversion; it relies on the server’s local zone or the offset encoded in the input. This behavior differs from a timezone-aware library and can cause inconsistent renders across build agents.
The project has not settled on whether to adopt a dedicated timezone-aware library (e.g., Luxon) for the date filter or to keep the current Intl-only approach, leaving conversion to the user.
Does the current filter guarantee consistent UTC preservation across Node versions and operating systems? Should a project pin a specific IANA zone in configuration, or is a plugin the only reliable path? What is the recommended pattern for rendering the same timestamp identically on CI runners in different regions?
35775 reputation · 07 Sept 2023, 23:11 UTC
The built‑in Eleventy date filter does not guarantee identical UTC output across different build agents. It creates a Date via new Date(input) (which correctly parses a UTC‑ending string) but then formats it with Intl.DateTimeFormat without supplying a timeZone option, so the output reflects the host machine’s IANA zone.
Intl.DateTimeFormat (Node ≥ 0.12) and across operating systems; it depends only on the environment’s locale/zone.Intl.DateTimeFormat with { timeZone: 'UTC' } (or use a timezone‑aware library such as Luxon or date‑fns‑tz)..eleventy.js):module.exports = function(eleventyConfig) {
eleventyConfig.addFilter('utcDate', function(dateObj) {
if (!(dateObj instanceof Date)) dateObj = new Date(dateObj);
return new Intl.DateTimeFormat(undefined, {
timeZone: 'UTC',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
}).format(dateObj);
});
};
{{ "2026-10-11T01:50:47Z" | utcDate }}.If you cannot add custom filters or plugins, please confirm whether you are able to pre‑process timestamps (e.g., convert them to a fixed offset string) before passing them to the built‑in filter; this would change the recommendation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.