zf1-future icon indicating copy to clipboard operation
zf1-future copied to clipboard

new Zend_Date($zendDateInstance, null, 'zh_TW') causing exception

Open xqiu opened this issue 1 year ago • 1 comments

Add the following unit tests to tests/Zend/Date/DateObjectTest.php,

    public function testNewDateLocaleTW()
    {
        // a mimic of the way that openmage calls the code in zh_TW locale, from [app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php](https://github.com/OpenMage/magento-lts/blob/main/app/code/core/Mage/Adminhtml/Controller/Report/Abstract.php), function _showLastExecutionTime
        $date = new Zend_Date("2020-01-13 10:00:03", "yyyy-MM-dd HH:mm:ss", null);
        $this->assertTrue($date instanceof Zend_Date);
        $date2 = new Zend_Date($date, null, 'zh_TW');
        $this->assertTrue($date2 instanceof Zend_Date);
    }

    public function testNewDateLocaleTWDirect()
    {
        //minimal bug repo
        $dateString = '2020年1月13日 上午1:00:03';
        $format = 'y年M月d日 ah:mm:ss';
        $this->assertTrue(new Zend_Date($dateString, $format, 'zh_TW') instanceof Zend_Date);
    }

Run the unit test:

There were 2 errors:

1) Zend_Date_DateObjectTest::testNewDateLocale1
Zend_Date_Exception: Unable to parse date '2020年1月13日 上午1:00:03' using 'y年M月d日 ah:mm:ss' (M <> d)

/mnt/e/github/zf1-future/library/Zend/Date.php:2540
/mnt/e/github/zf1-future/library/Zend/Date.php:1002
/mnt/e/github/zf1-future/library/Zend/Date.php:197
/mnt/e/github/zf1-future/tests/Zend/Date/DateObjectTest.php:670

Caused by
Zend_Locale_Exception: Unable to parse date '2020年1月13日 上午1:00:03' using 'y年M月d日 ah:mm:ss' (M <> d)

/mnt/e/github/zf1-future/library/Zend/Locale/Format.php:1080
/mnt/e/github/zf1-future/library/Zend/Locale/Format.php:1175
/mnt/e/github/zf1-future/library/Zend/Date.php:2506
/mnt/e/github/zf1-future/library/Zend/Date.php:1002
/mnt/e/github/zf1-future/library/Zend/Date.php:197
/mnt/e/github/zf1-future/tests/Zend/Date/DateObjectTest.php:670

2) Zend_Date_DateObjectTest::testNewDateLocale2
Zend_Date_Exception: Unable to parse date '2020年1月13日 上午10:00:03' using 'y年M月d日 ah:mm:ss' (M <> d)

/mnt/e/github/zf1-future/library/Zend/Date.php:2540
/mnt/e/github/zf1-future/library/Zend/Date.php:1002
/mnt/e/github/zf1-future/library/Zend/Date.php:197
/mnt/e/github/zf1-future/tests/Zend/Date/DateObjectTest.php:677

Caused by
Zend_Locale_Exception: Unable to parse date '2020年1月13日 上午10:00:03' using 'y年M月d日 ah:mm:ss' (M <> d)

/mnt/e/github/zf1-future/library/Zend/Locale/Format.php:1080
/mnt/e/github/zf1-future/library/Zend/Locale/Format.php:1175
/mnt/e/github/zf1-future/library/Zend/Date.php:2506
/mnt/e/github/zf1-future/library/Zend/Date.php:1002
/mnt/e/github/zf1-future/library/Zend/Date.php:197
/mnt/e/github/zf1-future/tests/Zend/Date/DateObjectTest.php:677

I'm using PHP 8.1.2

xqiu avatar Sep 20 '24 21:09 xqiu

Nice.

sreichel avatar Sep 23 '24 00:09 sreichel