mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUG Fix don't treat zero-date as invalid
This commit is contained in:
parent
e78fe401e6
commit
2bc7edbf47
@ -67,6 +67,9 @@ class DBDate extends DBField
|
|||||||
} else {
|
} else {
|
||||||
// Convert US date -> iso, fix y2k, etc
|
// Convert US date -> iso, fix y2k, etc
|
||||||
$value = $this->fixInputDate($value);
|
$value = $this->fixInputDate($value);
|
||||||
|
if (is_null($value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
$source = strtotime($value); // convert string to timestamp
|
$source = strtotime($value); // convert string to timestamp
|
||||||
}
|
}
|
||||||
if ($value === false) {
|
if ($value === false) {
|
||||||
@ -529,6 +532,9 @@ class DBDate extends DBField
|
|||||||
// split
|
// split
|
||||||
list($year, $month, $day, $time) = $this->explodeDateString($value);
|
list($year, $month, $day, $time) = $this->explodeDateString($value);
|
||||||
|
|
||||||
|
if ((int)$year === 0 && (int)$month === 0 && (int)$day === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// Validate date
|
// Validate date
|
||||||
if (!checkdate($month, $day, $year)) {
|
if (!checkdate($month, $day, $year)) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
@ -568,7 +574,7 @@ class DBDate extends DBField
|
|||||||
if ($parts[0] < 1000 && $parts[2] > 1000) {
|
if ($parts[0] < 1000 && $parts[2] > 1000) {
|
||||||
$parts = array_reverse($parts);
|
$parts = array_reverse($parts);
|
||||||
}
|
}
|
||||||
if ($parts[0] < 1000) {
|
if ($parts[0] < 1000 && (int)$parts[0] !== 0) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
"Invalid date: '$value'. Use " . self::ISO_DATE . " to prevent this error."
|
"Invalid date: '$value'. Use " . self::ISO_DATE . " to prevent this error."
|
||||||
);
|
);
|
||||||
|
@ -218,6 +218,12 @@ class DBDateTest extends SapphireTest
|
|||||||
|
|
||||||
$date = DBField::create_field('Date', 0);
|
$date = DBField::create_field('Date', 0);
|
||||||
$this->assertEquals('1970-01-01', $date->getValue(), 'Zero is UNIX epoch date');
|
$this->assertEquals('1970-01-01', $date->getValue(), 'Zero is UNIX epoch date');
|
||||||
|
|
||||||
|
$date = DBField::create_field('Date', '0000-00-00 00:00:00');
|
||||||
|
$this->assertNull($date->getValue(), '0000-00-00 00:00:00 is set as NULL');
|
||||||
|
|
||||||
|
$date = DBField::create_field('Date', '00/00/0000');
|
||||||
|
$this->assertNull($date->getValue(), '00/00/0000 is set as NULL');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDayOfMonth()
|
public function testDayOfMonth()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user