Bug #67127 [NEW]: setlocale LC_NUMERIC breaks DateTime microseconds
From: honzap at gmail dot com
Operating system: Linux (Debian Wheezy)
PHP version: 5.4.27
Package: Date/time related
Bug Type: Bug
Bug description:setlocale LC_NUMERIC breaks DateTime microseconds
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 bug report at https://bugs.php.net/bug.php?id=67127&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67127&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67127&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67127&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67127&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67127&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67127&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67127&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67127&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67127&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67127&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67127&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67127&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67127&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67127&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67127&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67127&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67127&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67127&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67127&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67127&r=mysqlcfg
Thread (7 messages)
- honzap at gmail dot com