php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53939 [intl] IntlDateFormatter::format fails to escape M in "'y-'M"
Submitted: 2011-02-06 17:42 UTC Modified: 2011-02-14 12:43 UTC
From: igor at wiedler dot ch Assigned:
Status: Not a bug Package: *Languages/Translation
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
 [2011-02-06 17:42 UTC] 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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-06 17:52 UTC] 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 18:02 UTC] igor at wiedler dot ch
Oops, the last expected is of course:

string(1) "n-M"
 [2011-02-08 11:18 UTC] igor at wiedler dot ch
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.
 [2011-02-08 11:19 UTC] igor at wiedler dot ch
-Status: Open +Status: Closed
 [2011-02-08 11:19 UTC] igor at wiedler dot ch
Invalid, closing.
 [2011-02-14 12:43 UTC] cataphract@php.net
-Status: Closed +Status: Bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 11:01:28 2024 UTC