Skip to content

Commit

Permalink
Consider client timezone for deadline validation prooph#40
Browse files Browse the repository at this point in the history
  • Loading branch information
sbacelic committed Dec 15, 2017
1 parent 6fba4a7 commit a5cc346
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Model/Todo/TodoDeadline.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public static function fromString(string $deadline): TodoDeadline

private function __construct(string $deadline)
{
$this->deadline = new \DateTimeImmutable($deadline, new \DateTimeZone('UTC'));
$this->createdOn = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
$this->deadline = new \DateTimeImmutable($deadline);
$this->createdOn = new \DateTimeImmutable('now', $this->deadline->getTimezone());
}

public function isInThePast(): bool
Expand All @@ -54,7 +54,7 @@ public function createdOn(): string

public function isMet(): bool
{
return $this->deadline > new \DateTimeImmutable();
return $this->deadline > new \DateTimeImmutable('now', $this->deadline->getTimezone());
}

public function sameValueAs(ValueObject $object): bool
Expand Down
27 changes: 26 additions & 1 deletion tests/Model/Todo/TodoDeadlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,38 @@ public function it_correctly_validates_the_deadline($deadline, $inThePast): void
}
}

/**
* @test
* @dataProvider getDeadlines
*/
public function it_correctly_validates_the_deadline_is_met($deadline, $inThePast): void
{
$deadline = TodoDeadline::fromString($deadline);
$isMet = $deadline->isMet();

if ($inThePast) {
$this->assertFalse($isMet, 'Deadline is not met');
} else {
$this->assertTrue($isMet, 'Deadline is met');
}
}


public function getDeadlines(): array
{
return [
[
'2047-02-01 10:00:00',
'2049-12-15T17:19:27+01:00',
false,
],
[
'2037-01-01 10:00:00',
false,
],
[
'2017-12-15T17:19:27+01:00',
true,
],
[
'1947-01-01 10:00:00',
true,
Expand Down

0 comments on commit a5cc346

Please sign in to comment.