Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule/date time diff #1463

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 library/Rules/DateTimeDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function evaluate(mixed $input): Result
return (new Result($nextSibling->isValid, $input, $this, $parameters))->withNextSibling($nextSibling);
}

private function comparisonValue(DateTimeInterface $now, DateTimeInterface $compareTo)
private function comparisonValue(DateTimeInterface $now, DateTimeInterface $compareTo): int|float
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that's correct, because days can return false

{
return $compareTo->diff($now)->{$this->type};
}
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/Rules/DateTimeDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public static function providerForInvalidInput(): array
new DateTimeDiff(Stub::fail(1), 'y'),
new DateTimeImmutable(),
],
'invalid date, with passing rule' => [
new DateTimeDiff(Stub::pass(1), 'y', "Y-m-d"),
'invalid date',
],
'invalid date, with failing rule' => [
new DateTimeDiff(Stub::fail(1), 'y', "Y-m-d"),
new DateTimeImmutable(),
],
] + array_map(
static fn (array $args): array => [new DateTimeDiff(Stub::fail(1)), new DateTimeImmutable()],
iterator_to_array(self::providerForNonScalarValues())
Expand Down