php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71790 Wrong Year formatting for 3rd Jan 2016 (returned 2015) on some locales.
Submitted: 2016-03-11 09:27 UTC Modified: 2016-03-11 12:43 UTC
From: ignasi35 at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.19 OS: Debian/CentOS/Mac
Private report: No CVE-ID: None
 [2016-03-11 09:27 UTC] ignasi35 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/book.intl
---

When requesting IntlDateFormatter to format '2016-01-03' using a specific set of locales with pattern 'YYYY' it returns 2015.

Steps to reproduce:
 - See attached code.

Details:
 - only some locales fail
 - we reproduce the error for dates 2016-01-01, 2016-01-02 and 2016-01-03. It looks like 2016-01-04 triggers the correct output
 - So far, for '2016-01-03' these values fail/pass:
$locale = 'en_UK' ; // UK -> passes
$locale = 'en_US' ; // US -> passes
$locale = 'ru_RU'; // Russian -> passes
$locale = 'es_ES'; // Spanish -> fails
$locale = 'de_DE'; // German -> fails
$locale = 'el_GR'; // Greek -> fails
 - we use the date '2016-01-03' to rule out a TZ-offset issue
 - we tested successfully Russia (ahead of UTC), UK (in UTC) and US (behind UTC)
 - we found Germany and Spain to fail (both in CET), But also Greece (not in CET)

This could be a side effect of https://bugs.php.net/bug.php?id=65694. 

Test script:
---------------
<?php
$locale = 'en_US' ; // US -> passes
$locale = 'ru_RU'; // Russian -> passes
$locale = 'es_ES'; // Spanish -> fails
$locale = 'de_DE'; // German -> fails
$locale = 'el_GR'; // Greek -> fails
setlocale(LC_ALL,  $locale  );
echo "$locale \n" ;

$DEFAULT_ZONE = 'Europe/Madrid';
$humantime = "2016-01-03" ;
$time = strtotime($humantime) ;
echo "humantime: $humantime \n" ;
echo "time: $time \n" ;

$pattern = ' YYYY';
$fmt = new IntlDateFormatter( $locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE, $DEFAULT_ZONE, IntlDateFormatter::GREGORIAN, $pattern);
echo $fmt->format($time);

Expected result:
----------------
We expected the result to be '2016'

Actual result:
--------------
The output is 2015



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-11 11:10 UTC] ignasi35 at gmail dot com
This is not a bug. The week in year ('YYYY') depends no the locale, I should have used 'yyyy'
 [2016-03-11 11:10 UTC] ignasi35 at gmail dot com
-Status: Open +Status: Closed
 [2016-03-11 11:10 UTC] ignasi35 at gmail dot com
closing
 [2016-03-11 12:43 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 09 20:01:32 2024 UTC