Home » Date and Time » Date » Bug #5494
%s formatter fails with locales that have a , as a decimal separator
Details
| Submitted | 2005-09-22 13:54 UTC |
|---|---|
| From | torben-spam-pear at nehmer dot net |
| Assigned | pajoye |
| Status | Closed |
| Package | Date |
| PHP Version | 4.3.10 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-09-22 13:54 UTC] torben-spam-pear at nehmer dot net
Description:
------------
Simply put, PHP has the strange behavoir of formatting floats to the current locale unconditionally, but reading them in English one. Check this:
$double = 4.4;
$string = (string) $double;
On a German system, where we have the comma as a decimal separator, $string is now "4,4" *not* "4.4".
This is ok, but the real crap starts when converting back:
$newdouble = (double) $string;
$newdouble is now 4, *not* 4.4, as the string-to-double conversion requires a decimal point, not comma.
This breaks your neck in the %s formatter, which uses %02f in sprintf, which is subject to the same limitation.
This becomes appearant when using the following format call:
$date->format('%Y-%m-%dT%H:%M:%s%O');
It yields:
1946-02-10T15:30:0,000000+00:00
Date then fails to reread that string.
Suggested solution: str_replace(',', '.', $value) or accepting both comma and dot as a separator. Enforcing the same decimal seaparator seams wiser to me though.