Cms: The formatDateTime directive cannot output unix timestamps

Created on 21 Aug 2020  路  7Comments  路  Source: craftcms/cms

Description

It鈥檚 currently not possible to format dates into unix timestamps. The following outputs something else entirely.

dateCreated@formatDateTime(format: "U")

Additional info

  • Craft version: 3.5.1
  • PHP version: 7.4.2
bug

All 7 comments

Under the hood, the date format U (or php:U) appears to be converted to an empty string before being formatted.

https://github.com/craftcms/cms/blob/5016c32dc12e04e6a738c804481e97187b667223/src/i18n/Formatter.php#L162

A possible solution would be to reuse this code from asDate before the PHP to ICU reformat that I mention above in asDatetime.

Thanks, @brandonkelly. 馃憤

Would definitely be worthwhile amending the docs for this too, if you鈥檝e not already.

Which docs?

https://craftcms.com/docs/3.x/graphql.html#list-of-available-directives

The format description should probably mention the php: prefix and reference the expected value format(s).

Ah, right. Just updated that for the next release: e8e8cadd02cf391d2c0b32f18040cbbd4539ef3d

Craft 3.5.6 is out now with that fix.

Was this page helpful?
0 / 5 - 0 ratings