Edit report at http://bugs.php.net/bug.php?id=53939&edit=1
ID: 53939
Comment by: igor at wiedler dot ch
Reported by: igor at wiedler dot ch
Summary: [intl] IntlDateFormatter::format fails to escape M
in "'y-'M"
Status: Open
Type: Bug
Package: *Languages/Translation
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
I discovered this in the ICU documentation:
> Any characters in the pattern that are not in the ranges of ['a'..'z']
and
['A'..'Z'] will be treated as quoted text. For instance, characters like
':',
'.', ' ', '#' and '@' will appear in the resulting time text even they
are not
enclosed within single quotes.The single quote is used to 'escape'
letters. Two
single quotes in a row, whether inside or outside a quoted sequence,
represent a
'real' single quote.
Example:
> yyyy.MM.dd G 'at' HH:mm:ss zzz
> 1996.07.10 AD at 15:08:56 PDT
http://userguide.icu-project.org/formatparse/datetime
So the escaping is always between two quote characters, and not an
escape
character before each escaped character (like with date).
Thus, this report is invalid and may be closed.
Previous Comments:
------------------------------------------------------------------------
[2011-02-06 18:02:45] igor at wiedler dot ch
Oops, the last expected is of course:
string(1) "n-M"
------------------------------------------------------------------------
[2011-02-06 17:52:33] igor at wiedler dot ch
Perhaps also worth noting:
Script:
$fmt = new IntlDateFormatter('en' ,IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'UTC', IntlDateFormatter::GREGORIAN ,"WTF 'y-'M");
var_dump($fmt->format(0));
$fmt = new IntlDateFormatter('en' ,IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'UTC', IntlDateFormatter::GREGORIAN ,"n-'M");
var_dump($fmt->format(0));
Actual:
string(1) "0"
string(1) "-"
Expected:
string(1) "0T1 1970-1"
string(1) "n-1"
------------------------------------------------------------------------
[2011-02-06 17:42:28] igor at wiedler dot ch
Description:
------------
When calling IntlDateFormatter::format with the format "'y-'M-'d", it
fails to
escape the M properly. ' is the escape character of ICU's dateformat.
Test script:
---------------
<?php
$fmt = new IntlDateFormatter('en' ,IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'UTC', IntlDateFormatter::GREGORIAN ,"M");
var_dump($fmt->format(0));
$fmt = new IntlDateFormatter('en' ,IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'UTC', IntlDateFormatter::GREGORIAN ,"'M");
var_dump($fmt->format(0));
$fmt = new IntlDateFormatter('en' ,IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'UTC', IntlDateFormatter::GREGORIAN ,"'y-'M");
var_dump($fmt->format(0));
Expected result:
----------------
string(1) "1"
string(1) "M"
string(3) "y-M"
Actual result:
--------------
string(1) "1"
string(1) "M"
string(3) "y-1"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53939&edit=1