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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: curt1996 at o2 dot pl
New email:
PHP Version: OS:

 

 [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: Fri Apr 19 16:01:27 2024 UTC