php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76152 Result alters randomly
Submitted: 2018-03-27 09:35 UTC Modified: 2018-03-28 16:09 UTC
From: curt1996 at o2 dot pl Assigned:
Status: Not a bug Package: intl (PECL)
PHP Version: 5.6.34 OS: Win 10
Private report: No CVE-ID: None
 [2018-03-27 09:35 UTC] curt1996 at o2 dot pl
Description:
------------
---
From manual page: http://www.php.net/intldateformatter.create
---
Passing dates to given function, depending on locale, gives different result

As you can see from few examples below, it returns completely different results depending on locale, which is totally unexpected. I tried finding the cause of it but nothing worked.

Test script:
---------------
    public function reformatDate(\DateTime $date, $format = 'LLLL Y'){
        //make sure the given format exists
        if(!function_exists('datefmt_create')){
            return $date->format('d.m.Y');
        }

        $fmt = datefmt_create(
            'pl_PL', //locale altered in Expected/Actual result part of bug report
            \IntlDateFormatter::FULL,
            \IntlDateFormatter::FULL,
            'Europe/Warsaw',
            \IntlDateFormatter::GREGORIAN,
            $format
        );

        return $fmt->format($date);
    }

Expected result:
----------------
Date | pl_PL | en_EN | pl_PL correct
2015-01-01 | styczen 2015 | january 2015
2015-12-01 | grudzien 2015 | december 2015
2016-01-01 | styczen 2016 | january 2016
2017-01-01 | styczen 2017 | january 2017

Actual result:
--------------
Date | pl_PL | en_EN
2015-01-01 | styczen 2015 | january 2015
2015-12-01 | grudzien 2015 | december 2015
2016-01-01 | styczen 2015 | january 2016
2017-01-01 | styczen 2016 | january 2017

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-27 09:48 UTC] curt1996 at o2 dot pl
-Status: Open +Status: Closed
 [2018-03-27 09:48 UTC] curt1996 at o2 dot pl
It actually was issue with wrong format used... should be `y` instead of `Y` which is reserved for year of week of year
 [2018-03-28 16:09 UTC] ab@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 18:02:40 2024 UTC