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

strtotime returns false when string includes narrow non breaking space character #11600

Closed
myleshyson opened this issue Jul 5, 2023 · 4 comments

Comments

@myleshyson
Copy link

Description

This is kind of related to #9799

With the ICU 72.1 update, it replaces a ascii space character with a narrow non-breaking space unicode character for intl space So something like

(new IntlDateFormatter('en_US', -1, 3))->getPattern();

will return h:mm\u202fa instead of h:mm a.

When creating date strings based off that pattern with the NNBS character, and then passing into strtotime, strtotime returns false.

With the ICU update, I think functions like strtotime should support parsing the NNBS character.

The following code:

<?php
$pattern = (new IntlDateFormatter('en_US', -1, 3))->getPattern();
$timeString = date($pattern, date('now'));
$timestamp = strtotime($timeString);

Resulted in this output:

false

But I expected this output instead:

a unix timestamp

PHP Version

8.2.8

Operating System

Redhat Enterprise 8.8

@nielsdos
Copy link
Member

nielsdos commented Jul 6, 2023

Looks like it calls into timelib_strtotime() so this needs changes in timelib, if this change is wanted.

@derickr derickr self-assigned this Jul 6, 2023
@hormus
Copy link

hormus commented Jul 10, 2023

For date or DateTime https://www.php.net/manual/en/datetime.formats.time.php
fornat ICU h:mm a or h:mm\u202fa missing for date or DateTime.
change date('now') to strtotime('now')

@derickr
Copy link
Member

derickr commented Jul 11, 2023

Fixed for PHP 8.2.9 — thanks for your report, but please note that your example is not correct. The pattern that comes back from getPattern() is h:mm&nnbsp;a — which when formatting does the m (the minutes) twice, resulting in something like 04:3232 PM that can not be parsed.

Instead, I had to modify the test to: https://github.com/php/php-src/blob/master/ext/date/tests/bug-gh11600.phpt

@derickr derickr closed this as completed Jul 11, 2023
@myleshyson
Copy link
Author

Sweet thanks! Got so focused onthe \u202f character breaking strtotime I missed the extra m breaking it as well. Either way happy it's fixed.

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

4 participants