Closed flaviotordini closed 3 months ago
We have problem in JavaScript that Date
doesn't support format string. We'll need localizations for this purpose, I'm thinking that we can create a separate project to port a strftime lib to Liquid date
filter. like this one: https://github.com/samsonjs/strftime#locales
JavaScript does have an Intl.DateTimeFormat
, which "enables language-sensitive date and time formatting."
In the meantime I used this:
eleventyConfig.addFilter("localizedDate", (dateString, locale) => {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return new Date(dateString).toLocaleDateString(locale, options);
});
The downside is that it does not support string patterns.
Yes, you're right. We can customize locale date/time string in JavaScript, but not as flexible as in strftime.
Intl.DateTimeFormat
and .toLocaleDateString()
both support a format options parameter which contains something like dateStyle
, timeStyle
, year
, month
. While I can't find a way to implement strftime with it.
@harttle would an option for global/default date format help, similar to timezoneOffset? In current code, the default format is hard coded. With such an option, engine users will be free to set whatever format they need, however they got it (Intl, user configured, ...).
I use the similar timezoneOffset option, to get all dates in the templates converted to the required tz.
Of course, this is for the developers who setup/init the Liquid engine, and not for the template designers.
Makes sense. Thank you @prassie for the clarification.
weekday and months are now locale specific, details please check: https://liquidjs.com/filters/date.html
Is it possibile to format dates with the date filter in a specific language? If not, it sounds like a good feature for a templating engine.