Skip to content

Commit 443871f

Browse files
committed
Improve formatDateTime filter performance
1 parent a93663d commit 443871f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

.eleventy.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ const {
88
version: eleventyVersion,
99
} = require('./node_modules/@11ty/eleventy/package.json');
1010

11+
const dateFormatter = Intl.DateTimeFormat('en-US', {
12+
year: 'numeric',
13+
month: 'long',
14+
day: 'numeric',
15+
weekday: 'long',
16+
hour: 'numeric',
17+
minute: 'numeric',
18+
timeZoneName: 'short',
19+
});
20+
1121
module.exports = function (eleventyConfig) {
1222
eleventyConfig.addPassthroughCopy('./src/css/tailwind.include.css');
1323
eleventyConfig.addPassthroughCopy({ public: './' });
@@ -21,15 +31,7 @@ module.exports = function (eleventyConfig) {
2131
});
2232

2333
eleventyConfig.addFilter('formatDateTime', function (date) {
24-
return date.toLocaleDateString('en-US', {
25-
year: 'numeric',
26-
month: 'long',
27-
day: 'numeric',
28-
weekday: 'long',
29-
hour: 'numeric',
30-
minute: 'numeric',
31-
timeZoneName: 'short',
32-
});
34+
return dateFormatter.format(date);
3335
});
3436

3537
eleventyConfig.addPlugin(inclusiveLangPlugin);

0 commit comments

Comments
 (0)