Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intl Extension: MessageFormatter prepends date with space #7779

Closed
frederikbosch opened this issue Dec 15, 2021 · 1 comment
Closed

Intl Extension: MessageFormatter prepends date with space #7779

frederikbosch opened this issue Dec 15, 2021 · 1 comment

Comments

@frederikbosch
Copy link
Contributor

frederikbosch commented Dec 15, 2021

Description

The following code:

<?php

$formatter = new \MessageFormatter('en_US', '{0, date, YYYY-ww}');
var_dump($formatter->format([new \DateTimeImmutable]));

$formatter = new \MessageFormatter('en_US', '{0}');
var_dump($formatter->format(['test']));

Resulted in this output:

string(8) " 2021-51"
string(4) "test"

But I expected this output instead:

string(8) "2021-51"
string(4) "test"

See this 3v4l online page. This applies to all messages using date.

PHP Version

7.3.13 - 7.3.33, 7.4.0 - 7.4.27, 8.0.0 - 8.0.13, 8.1.0

Operating System

Any

@damianwadley
Copy link
Member

Unfortunately the ICU documentation doesn't go into these kinds of specifics, but given that PHP is not the one deciding to insert the extra space, I'm going to assume that it's deliberate behavior by the libicu library to respect the leading whitespace used by your custom date style. Change it to '{0,date,YYYY-ww}' to match how they write their formatting patterns.
https://3v4l.org/OlhBU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants