Bug #67127 [Ana->Asn]: setlocale LC_NUMERIC breaks DateTime microseconds
| From: | kalle@php.net | Date: | Tue, 24 Oct 2017 05:24:55 +0000 |
| Subject: | Bug #67127 [Ana->Asn]: setlocale LC_NUMERIC breaks DateTime microseconds | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211948@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67127&edit=1
ID: 67127
Updated by: kalle@php.net
Reported by: honzap at gmail dot com
Summary: setlocale LC_NUMERIC breaks DateTime microseconds
-Status: Analyzed
+Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Linux (Debian Wheezy)
PHP Version: 5.4.27
Assigned To: derick
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2016-08-07 10:09:11] cmb@php.net
Related To: Bug #48225
------------------------------------------------------------------------
[2016-08-07 09:52:22] cmb@php.net
Related To: Bug #47312
------------------------------------------------------------------------
[2016-08-06 18:16:30] cmb@php.net
I can confirm this issue. The culprit is in timelib_get_frac_nr()
where strtod() is used[1], which is locale dependend. Using
zend_strtod() instead would solve the issue, but that would make
timelib depending on the Zend engine, what is certainly not
desired.
Derick, what do you think about including some locale independent
strtod() replacement[2].
@wilfrid Your issue is unrelated to this bug report, and actually,
it is not a bug, but rather being caused by setlocale() not being
thread safe[3]. Consider to use the intl extension[4] instead.
[1] <https://github.com/derickr/timelib/blob/master/parse_date.re#L514>
[2] fe. <http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/missing/strtod.c>
[3] <http://php.net/manual/en/function.setlocale.php#refsect1-function.setlocale-notes>
[4] <http://php.net/manual/en/intro.intl.php>
------------------------------------------------------------------------
[2014-06-03 22:16:06] wilfrid at digifactory dot fr
We have a problem link to this LC_NUMERIC issue : float numbers suddently get coma rather than point
for decimal separator.
It's extremely problematic as it's in several ecommerce websites.
Also, is rare and really random (kind of 1 per 10 000 entries). As it's the LC_NUMERIC,
str_replace(",", ".", $str) doesn't work.
we are using PHP 5.4.26 on a debian.
On the same server, we noticed a similar problem with LC_TIME :
setlocale(LC_TIME, 'fr_FR'); // fixed in the top of the php script.
and randomly, an average of 1 on 20 reload, we have a date displayed in english.
We noticed that putting the setlocale(LC_TIME, 'fr_FR'); just before the strftime('%A
%d %B') seems to work arround the bug, for now.
Voilà , hope it can help !
------------------------------------------------------------------------
[2014-04-24 09:47:19] honzap at gmail dot com
Description:
------------
I need using DateTime with microseconds. I've found some examples like at this page:
http://stackoverflow.com/questions/169428/php-datetime-microseconds-always-returns-0
I've used my own class extending \DateTime. Formatting still doesn't work in my
application so I've looking for something bad and found setting setlocale(LC_ALL, ...) calling.
I've found, setting LC_NUMERIC breaks down the function of microseconds. Testing script is at
the attachment. It's probably caused because in my chosen locale the decimal point is comma
(",") not point (".").
Test script:
---------------
date_default_timezone_set('Europe/Prague');
$time = microtime(true);
$micro_time = sprintf("%06d", ($time - floor($time)) * 1000000);
$date = new DateTime(date('Y-m-d H:i:s.' . $micro_time, $time));
echo $date->format("Y-m-d H:i:s.u") . " - OK\n";
setlocale(LC_NUMERIC, 'cs_CZ.utf8');
$date = new DateTime(date('Y-m-d H:i:s.' . $micro_time, $time));
echo $date->format("Y-m-d H:i:s.u") . " - BAD!\n";
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67127&edit=1