Skip to content

Date locale #567

Closed
Closed

Description

@flaviotordini

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.

Activity

  1. harttle commented on Dec 11, 2022

    @harttle
    Owner

    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

  2. pdehaan commented on Dec 11, 2022

    @pdehaan
    Contributor

    JavaScript does have an Intl.DateTimeFormat, which "enables language-sensitive date and time formatting."

  3. flaviotordini commented on Dec 11, 2022

    @flaviotordini
    Author

    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.

  4. harttle commented on Dec 12, 2022

    @harttle
    Owner

    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.

  5. prassie commented on Feb 2, 2023

    @prassie
    Contributor

    @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.

  6. harttle commented on Feb 4, 2023

    @harttle
    Owner

    Makes sense. Thank you @prassie for the clarification.

  7. harttle commented on Jul 21, 2024

    @harttle
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions