php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72649 A specific date is unparsable: 1978-05-28
Submitted: 2016-07-22 15:14 UTC Modified: 2016-07-23 10:56 UTC
From: alessandro dot lai85 at gmail dot com Assigned:
Status: Not a bug Package: intl (PECL)
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
 [2016-07-22 15:14 UTC] alessandro dot lai85 at gmail dot com
Description:
------------
I stumbled over a strange bug. A specific date (1978-05-28) gives a parsing error, even with different patterns. I will append a test script, but you can see it in action here: https://3v4l.org/NDnbm

I used a common italian pattern ("dd/MM/yyyy"), but the issue arise even with the one used by default by Symfony: "yyyy-MM-dd".

Test script:
---------------
<?php

$formatter = new \IntlDateFormatter('it', 2, -1, "Europe/Rome", 1, "dd/MM/yyyy");
$formatter->setLenient(false);

echo 'Pattern 1: dd/MM/yyyy';
echo "\n";
echo "27/05/1978: ";
echo $formatter->parse('27/05/1978');
echo "\n";
echo "28/05/1978: ";
echo $formatter->parse('28/05/1978');
echo "ERROR: ";
echo intl_get_error_message();
echo "\n";
echo "29/05/1978: ";
echo $formatter->parse('29/05/1978');

echo "\n\n";
echo 'Pattern 2: yyyy-MM-dd (Symfony\'s default)';
$formatter = new \IntlDateFormatter('it', 2, -1, "Europe/Rome", 1, "yyyy-MM-dd");
$formatter->setLenient(false);

echo "\n";
echo "28/05/1978: ";
echo $formatter->parse('1978-05-28');
echo "ERROR: ";
echo intl_get_error_message();

Expected result:
----------------
Pattern 1: dd/MM/yyyy
27/05/1978: 265071600
28/05/1978: 265156200
29/05/1978: 265240800

Pattern 2: yyyy-MM-dd (Symfony's default)
28/05/1978: 265156200

Actual result:
--------------
Pattern 1: dd/MM/yyyy
27/05/1978: 265071600
28/05/1978: ERROR: Date parsing failed: U_PARSE_ERROR
29/05/1978: 265240800

Pattern 2: yyyy-MM-dd (Symfony's default)
28/05/1978: ERROR: Date parsing failed: U_PARSE_ERROR

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-22 15:54 UTC] mbeccati@php.net
-Status: Open +Status: Not a bug
 [2016-07-22 15:54 UTC] mbeccati@php.net
On 1978-05-28 00:00:00 Europe/Rome transitioned from standard to daylight saving time. Midnight simply didn't exist ;)
 [2016-07-23 10:56 UTC] alessandro dot lai85 at gmail dot com
Ok, but I disagree, it's still a bug! I did not specify hour, minutes and seconds, so midnight it's an assumption of the library. 

I would expect that the parsed result would be the first second of the day, which normally is midnight, but in this (and similar) special case should be 1 AM.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jul 06 21:01:04 2020 UTC