I18n nice function does not work as it is described in the docs

i have a problem with formatting FrozenTime values. I want to use the following code snippet
$startTime = $this->start->nice($timezoneString, $localeString);

The start atrribute is from type FrozenTime. nice is the function call from the cakephp docs. I have uploaded a picture of the docs.

I know that FrozenTime is immutable but my example from above should work i think. I am using the nice format as it is shown in the doc.
But the function always gives back the following date format: “Oct 28, 2023, 11:54 AM”
even if I change the locale string for example to german. I tried to debug this problem but i can’t find an answer to the problem.

Would be pretty nice if someone can help me.

I have the php Version 8.1.8 and cakephp Version 4.4.16.

Thanks a lot in advance.

If I do

$time = new \Cake\I18n\FrozenTime();
var_dump($time->nice('Europe/Vienna', 'en-US'));

I get

Oct 28, 2023, 12:41 PM

and with

$time = new \Cake\I18n\FrozenTime();
var_dump($time->nice('Europe/Vienna', 'de-DE'));

I get

28.10.2023, 12:42

which is both what I would expect.

I’d recommend you check your PHP modules via php -m and make sure the intl extension is enabled.

Also you can check the installed ICU version via php -i | grep ICU which for me shows these versions:

ICU version => 73.2
ICU Data version => 73.2
ICU TZData version => 2023c
ICU Unicode version => 15.0

Hello Kevin,

thanks for your answer. Your output is exactly that for what i am looking for. I have checked my php modules. intl is listed if i type in php -m. That fits. I checked also my installed ICU Version. It gives back other version than yours.

ICU version => 71.1
ICU Data version => 71.1
ICU Unicode version => 14.0

I have no ICU TZData version like you. Could that be the problem?

At least in my server I have a package called tzdata installed

root•~» dpkg --list | grep tzdata                                                                                                                                  [12:31:21]
ii  tzdata                            2023c-5                                          all          time zone and daylight-saving time data

Maybe you don’t have that installed?
But usually it comes as a dependency if PHP intl needs it which it doesn’t seem to…

root•~» apt depends tzdata                                                                                                                                         [12:31:51]
 |Depends: debconf (>= 0.5)
  Depends: <debconf-2.0>

root•~» apt depends php8.2-intl                                                                                                                                    [12:32:47]
  Depends: php-common (>= 1:81~)
  Depends: ucf
  Depends: php8.2-common (= 8.2.12-1+0~20231027.35+debian12~1.gbp517c79)
  Depends: libc6 (>= 2.14)
  Depends: libgcc-s1 (>= 3.0)
  Depends: libicu72 (>= 72.1~rc-1~)

Can you chain method calls on an immutable like this?

there is no chain method call happening in

$this->start->nice($timezoneString, $localeString);

$this->start is just the property inside the entity I would assume just like $this->created or $this->modified

Thanks, my eyes deceived me

Also, yes, you can very much chain calls on immutables. Each call returns a new object, which the next call then acts on. $this->start->addMonth()->firstOfMonth()->nice(...) will give you the nice format for the first day of the month after the start date of the thing.