Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date filter outputs am / pm as a.m. / p.m. #4558

Closed
lewisjenkins opened this issue Jul 14, 2019 · 4 comments
Closed

date filter outputs am / pm as a.m. / p.m. #4558

lewisjenkins opened this issue Jul 14, 2019 · 4 comments

Comments

@lewisjenkins
Copy link

{{ entry.postDate|date('a') }} is outputting a.m. but according to PHP Date it should be am (without the added periods). Same goes for {{ entry.postDate|date('A') }}.

@lewisjenkins
Copy link
Author

Just to add, if I do <?php echo date('a'); ?> outside of Craft (but on the same server) then it outputs am which is the expected behaviour. So this appears to be something within Craft / Twig.

@brandonkelly
Copy link
Member

Guessing this is happening for a site set to nb or nl? In those cases this is expected.

Craft overrides Twig’s |date filter with a custom one that adds support for ICU-based format strings short, medium, long, and full, plus ICU date formats (e.g. icu:y-MM-dd). And PHP date formats get converted to an ICU format first, and then output, so that the resulting format will take the current locale into account (month/weekday/AM/PM names all use the locale-specific words).

@lewisjenkins
Copy link
Author

The site is set to en-GB. Following your comment I tried {{ entry.postDate|date('a', locale='en-US') }} and the result was am. So it looks like a.m. is the expected behaviour for en-GB which I never knew despite being British! Thanks for clarifying :)

@brandonkelly
Copy link
Member

Ah ok, perhaps that too :) I was going off our locale data exports in src/config/locales/, but if you have the Intl extension installed it’s really just up to whatever your installed ICU database has.

It might be worth us adding a parameter to the date filter to disable the ICU conversion, if you definitely just want to go with whatever PHP’s date() method returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants