仅针对特定日期的DateTime验证错误


DateTime validation error only for a specific date

我有一个简单的用户配置文件表单,其中包含生日字段

实体:

/**
 * @var string
 *
 * @ORM'Column(name="bdate", type="date")
 */
private $bdate;


表单类型:

$builder->add('bdate', 'birthday', array(
    'input'  => 'datetime',
    'widget' => 'single_text'
));


控制器:

if ($request->getMethod() == 'POST') {
    $form->handleRequest($request);
    if ($form->isValid()) {
        ...
    } else {
        // always here when 28 May 1972 
    }
}


它总是有效的,但当日期是1972-05-28时,我有验证错误此值无效

1972年5月28日时

使用MySql可以工作,但我的数据库是Oracle。我正在使用监听器OracleSessionInit,其他人对此没有意见。

你能帮帮我吗?我疯了

夏令时更改发生在午夜的每个日期都会确认该问题,1966年至1979年欧洲/罗马的情况就是这样:

https://www.timeanddate.com/time/change/italy/rome

Fedora Linux 15中的这个错误可能与有关

https://bugzilla.redhat.com/show_bug.cgi?id=1057104

这似乎也发生在当前的ubuntu和windows上。

PHP代码再现问题:

<?php
$argh = "1972-05-28";
$timezone = "Europe/Rome";
$fmt = new IntlDateFormatter(
    'it',
    IntlDateFormatter::MEDIUM,
    IntlDateFormatter::NONE,
    $timezone,
    IntlDateFormatter::GREGORIAN,
    'yyyy-MM-dd'
);
echo 'lenient of the formatter is : ';
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
$fmt->parse($argh);
echo "'n Trying to do parse($argh).'nResult is : " . $fmt->parse($argh);
if (intl_get_error_code() != 0) {
    echo "'nError_msg is : " . intl_get_error_message();
    echo "'nError_code is : " . intl_get_error_code();
}
$fmt->setLenient(FALSE);
echo "'nNow lenient of the formatter is : ";
if ($fmt->isLenient()) {
    echo 'TRUE';
} else {
    echo 'FALSE';
}
$fmt->parse($argh);
echo "'n Trying to do parse($argh).'nResult is : " . $fmt->parse($argh);
if (intl_get_error_code() != 0) {
    echo "'nError_msg is : " . intl_get_error_message();
    echo "'nError_code is : " . intl_get_error_code();
}
?>

一种可能的变通办法是将时区设置为不同的时区,即"欧洲/巴黎"。

不仅代码不是Oracle,错误消息也不是。但是,由于您引用了一个"好"值和一个"坏"值作为"日期",我认为无效值是用于日期的。您可能混淆了字符串数据和实际的DATE数据类型。您显示的"日期"实际上只不过是一个可以识别为日期的字符串,但当它归结为数据库处理的sql语句时,必须有一条规则来解释该字符串。在oracle中,这是通过设置NLS_DATE_FORMATE或(在我看来更好)使用TO_DATE函数来完成的。