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 a5cc346 commit 6263638
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/Model/Todo/TodoDeadline.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ public static function fromString(string $deadline): TodoDeadline

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

$this->deadline = \DateTimeImmutable::createFromMutable($deadlineInUtc);
$this->createdOn = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
}

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

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

public function sameValueAs(ValueObject $object): bool
Expand Down
13 changes: 11 additions & 2 deletions tests/Model/Todo/TodoDeadlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,29 @@ public function it_correctly_validates_the_deadline_is_met($deadline, $inThePast
}
}

/**
* @test
*/
public function it_stores_deadline_in_utc(): void
{
$deadline = TodoDeadline::fromString('2039-12-15T17:19:27+08:00');

$this->assertEquals('2039-12-15T09:19:27+00:00', $deadline->toString());
}

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

0 comments on commit 6263638

Please sign in to comment.