php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52283 IntlDateFormatter invalid parsing with YYYY
Submitted: 2010-07-08 09:29 UTC Modified: 2010-09-01 23:52 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: danikas2k2 at gmail dot com Assigned: stas (profile)
Status: Not a bug Package: I18N and L10N related
PHP Version: 5.3.2 OS: WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
27 + 30 = ?
Subscribe to this entry?

 
 [2010-07-08 09:29 UTC] danikas2k2 at gmail dot com
Description:
------------
Parsing a value with YYYY in the pattern returns unexpected results. Formatting 
the value using the YYYY in the pattern works perfect.

Test script:
---------------
$fmt = new IntlDateFormatter('lt_LT', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Europe/Vilnius', IntlDateFormatter::GREGORIAN);

$value = '2007-10-01'; // notice, that 2007-01-01 equals to 2007-W01-1
$variants = array();

$fmt->setPattern('yyyy');
$pts = $fmt->parse($value);
$variants[] = array($pts, $fmt->format($pts));

$fmt->setPattern('yyyy-MM');
$pts = $fmt->parse($value);
$variants[] = array($pts, $fmt->format($pts));

$fmt->setPattern('yyyy-MM-dd');
$pts = $fmt->parse($value);
$variants[] = array($pts, $fmt->format($pts));

$fmt->setPattern('YYYY');
$pts = $fmt->parse($value);
$variants[] = array($pts, $fmt->format($pts));

$fmt->setPattern('YYYY-MM');
$pts = $fmt->parse($value);
$variants[] = array($pts, $fmt->format($pts));

$fmt->setPattern('YYYY-MM-dd');
$pts = $fmt->parse($value);
$variants[] = array($pts, $fmt->format($pts));

print_r($variants);


Expected result:
----------------
array (
  0 =>
  array (
    0 => 1167602400,
    1 => '2007',
  ),
  1 =>
  array (
    0 => 1191186000,
    1 => '2007-10',
  ),
  2 =>
  array (
    0 => 1191186000,
    1 => '2007-10-01',
  ),
  3 =>
  array (
    0 => 1167602400,
    1 => '2007',
  ),
  4 =>
  array (
    0 => 1191186000,
    1 => '2007-10',
  ),
  5 =>
  array (
    0 => 1191186000,
    1 => '2007-10-01',
  ),
)

Actual result:
--------------
array (
  0 =>
  array (
    0 => 1167602400,
    1 => '2007',
  ),
  1 =>
  array (
    0 => 1191186000,
    1 => '2007-10',
  ),
  2 =>
  array (
    0 => 1191186000,
    1 => '2007-10-01',
  ),
  3 =>
  array (
    0 => 1166997600,
    1 => '2006',
  ),
  4 =>
  array (
    0 => 1166997600,
    1 => '2006-12',
  ),
  5 =>
  array (
    0 => 23576400,
    1 => '1970-10-01',
  ),
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-08 13:05 UTC] johannes@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: stas
 [2010-07-08 13:05 UTC] johannes@php.net
Stas, please look into this. Thanks. I don't know whether that might be expected or is an icu issue or ...
 [2010-09-01 23:52 UTC] stas@php.net
-Status: Assigned +Status: Bogus
 [2010-09-01 23:52 UTC] stas@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

YYYY is not a regular year (that's yyyy). It's a year from "week date" format, see here: http://en.wikipedia.org/wiki/ISO_8601#Week_dates
it's kind of funny format, since it speaks in whole weeks, so if part of week was in 2006 and part of 2007, giving just year number actually can send you to a last week of previous year. As an example goes in wiki, 2008-12-29 is written "2009-W01-1". YYYY and MM thus won't mix that well. Use yyyy.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC