Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ext-mbstring": "*",
"ext-json": "*",
"justinrainbow/json-schema": "^5.2.10",
"nesbot/carbon": "^2.63.0",
"nesbot/carbon": "^2.63.0 || ^3.0",
"jmikola/geojson": "^1.0"
},
"require-dev": {
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/DateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class DateField extends BaseField

protected function validateCastValue($val)
{
if (!is_string($val) && !$val instanceof \DateTimeInterface) {
throw $this->getValidationException('must be string or datetime', $val);
}

if ('any' === $this->format()) {
try {
$date = new Carbon($val);
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/DatetimeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class DatetimeField extends BaseField
{
protected function validateCastValue($val)
{
if (!is_string($val) && !$val instanceof \DateTimeInterface) {
throw $this->getValidationException('must be string or datetime', $val);
}

$val = trim($val);
switch ($this->format()) {
case 'default':
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/TimeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class TimeField extends BaseField
{
protected function validateCastValue($val)
{
if (!is_string($val) && !$val instanceof \DateTimeInterface) {
throw $this->getValidationException('must be string or datetime', $val);
}

switch ($this->format()) {
case 'default':
$time = explode(':', $val);
Expand Down
9 changes: 8 additions & 1 deletion tests/FieldTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,14 @@ protected function assertFieldTestData($fieldType, $testData): void
if (self::ERROR === $expectedCastValue) {
$this->assertNotEmpty($field->validateValue($inputValue), $assertMessage);
} elseif (is_object($expectedCastValue)) {
$this->assertEquals($expectedCastValue, $field->castValue($inputValue), $assertMessage);
$castValue = $field->castValue($inputValue);
if ($expectedCastValue instanceof CarbonInterval && $castValue instanceof CarbonInterval) {
// Carbon 3.x changed internal CarbonInterval properties (e.g. originalInput),
// breaking whole-object comparison. Compare the ISO 8601 spec instead.
$this->assertEquals($expectedCastValue->spec(), $castValue->spec(), $assertMessage);
} else {
$this->assertEquals($expectedCastValue, $castValue, $assertMessage);
}
} else {
$this->assertSame($expectedCastValue, $field->castValue($inputValue), $assertMessage);
}
Expand Down
Loading