8.4.2 How to set 24 hour format for datetime picker?

Permalink
I use a datetime picker as
$dt = date('Y-m-d H:i:s', strtotime('tomorrow 09:00:00'));
echo $app->make('helper/form/date_time')->datetime('pickup_dt', $dt, false, true, null, 1800, array());

It shows a 24 h format in Russian locale but it's only a 12 h format in English.

How can I force it to 24 h regardless of the language?

linuxoid
 
shahroq replied on at Permalink Reply
shahroq
Hi,
As I once have investigated, it seems there is no perfect way to change the time format by sending a parameter to the method. The time format, 24 or 12, is directly fetched by "Punic" library and their respective files, which in your case should be:
- for default language (en): \concrete\vendor\punic\punic\src\data\en\calendar.php: ['timeFormats']['short']
- for Russian language (ru): \concrete\vendor\punic\punic\src\data\ru\calendar.php: ['timeFormats']['short']

The easiest way seems to edit this core file: \concrete\src\Form\Service\Widget\DateTime.php > datetime() method and set $timeFormat= 24 manually, so it always displays 24h format short of considering current locale the user is browsing. Since it is not a good practice to edit a core file, you might want to investigate whether this file is overridable before directly editing it.

P.S: It might be a good idea to add an extra parameter to datetime() method, so the format can be altered in these cases.
linuxoid replied on at Permalink Reply
linuxoid
Thanks for the pointer. But it's not the $dateTime, it's the $timeFormat = 24.

I'd like to know if the core can be overridden somehow.
omars786 replied on at Permalink Reply
omars786
Hi There,

Thanks for the info, but unfortunately it didn't work for me.. I changed:

$timeFormat = $dh->getTimeFormat();

TO:
$timeFormat = 24;


but I'm still seeing AM/PM on the dateform pickers - did you find another way to force 24hours?

Many thanks
tommyh replied on at Permalink Reply
tommyh
Hi,

I was looking through the logs (reports>logs) and see a ton of errors similar to:

public_html/concrete/vendor/punic/punic/code/Data.php:70 'en_US UNION ALL SELECT NULL,NULL,NULL-- CbQR' is not a valid locale identifier (10001)

Ideas as to what could be causing these?