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
4 changes: 1 addition & 3 deletions src/DateTimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ final public static function from(
}
}

throw new InvalidTypeException(
'Value ' . $value . ' must be string in ' . DateTimeFormat::DATETIME . ' format'
);
throw InvalidTypeException::typeError(DateTimeFormat::DATETIME . ' format', $value);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ final public static function from(
}
}

throw new InvalidTypeException(
'Value ' . $value . ' must be string in ' . DateTimeFormat::DATE . ' format'
);
throw InvalidTypeException::typeError(DateTimeFormat::DATE . ' format', $value);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/DateTimesTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ final class DateTimesTest extends TestCase
InvalidTypeException::class
);

Assert::throws(
static function (): void {
DateTimes::from(
[
'date' => '1979-02-23 00:00:00.000000',
'timezone' => 'Europe/Prague',
'timezone_type' => 3,
]
);
},
InvalidTypeException::class
);

$d = DateTimes::from('2000-01-01 00:00:00.123456');
Assert::equal('2000-01-01 00:00:00', DateTimeFormatter::format($d));

Expand Down
13 changes: 13 additions & 0 deletions tests/DatesTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ final class DatesTest extends TestCase
},
InvalidTypeException::class
);

Assert::throws(
static function (): void {
Dates::from(
[
'date' => '1979-02-23 00:00:00.000000',
'timezone' => 'Europe/Prague',
'timezone_type' => 3,
]
);
},
InvalidTypeException::class
);
}

public function testExtract(): void
Expand Down