0

Is there a simple way to opt out of the translation that occurs when you format a date like this:

{{ expiry | date('D, d M Y H:i:s', 'GMT') }}

The problem is that I need this in english to create a valid date for my HTTP headers. But the site is in norwegian so days and months are translated, resulting in an invalid date.

2

Not currently - we should probably add a new 'translate' argument to that function which would let you opt out of it.

However Craft’s DateTime variables have a rfc1123() function which can be used instead of the Twig |date filter, and its output won’t get automatically translated.

For reference, RFC 1123 defines the date/time specification recommended by RFC 2616 (HTTP 1.1) (which is the same as the one defined by RFC 822, just with 4-digit years).

{{ expiry.rfc1123() }}
  • Great. The date string doesn't look exactly like the date-header, but maybe both is allowed? "Date:Sun, 28 Sep 2014 15:14:58 GMT" vs "Expires:Monday, 29-Sep-14 15:14:58 UTC". Actually .rfc822() looks more like it, but doesn't output the name of the timezone, just the time diff. – André Elvan Sep 28 '14 at 15:19
  • @AndréElvan Sorry, while the RFC 850 specification should work, apparently it’s obsolete, and RFC 1123 is recommended. Just updated the answer. – Brandon Kelly Sep 28 '14 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.