Correct Date Handler

Hi, what is the correct Date Handler config code?

Like showed here https://getkirby.com/docs/reference/system/options/date

return [
    'date'  => [
        'handler' => 'strftime'
    ]
];

Or here https://getkirby.com/docs/cookbook/text/dates#custom-date-handler

return [
    'date.handler' => 'strftime'
];

On my server, both of them work, but it is better to check. The second one is maybe leftover from earlier versions.

And one more thing.

I saw that on some servers srtftime date is displayed like this %09.%05.%2019 on the front-end.
With %. Could that be some locale related issue?

Both options should work.

How do you output the date?

Like this

<?= $article->date()->toDate('%d.%m.%Y') ?>

Use
<?= $article->date()->toDate('d.m.Y') ?>

Nope, with the date handler set to strftime, we have to use the strftime date format syntax: https://www.php.net/manual/de/function.strftime.php

2 Likes

In the meantime, I figured out that it is locale issue, and I am just wondering is there some relatively quick solution, without the need to check what locales are installed on a server.

On the server I have control of it is ok, but now is an issue on the server I do not have control of.

I know the easiest thing would be to turn of strftime and output as ‘d.m.Y’, in this case strftime is used for nothing special. But I have/had intent to use for something special.

Did you have a locale set in Kirby in those cases where you got the % output?

No, I didn’t set any locale setup in config.

Client is from Scotland, and I told him to add
'locale' => 'en_GB.utf-8',

To see does it make some difference.

Problem solved.
It is a reminder to always triple check stupid things first, and make sure they are ok.

The client’s config was set to config.website.com.php and he checked www.website.com all the time.
In addition, he didn’t set non-www to www redirect and sent me website.com. From my point, everything looked ok, but he constantly sent me screenshots with faulted dates with %. Which puzzled me.
Until I figured it out.

At least, maybe this thread help someone with the same issue. Thanks!