Make sure that stored timestamps are always in UTC time zone
This commit is contained in:
parent
2280822ab4
commit
3d838d175e
|
@ -5,8 +5,11 @@ declare(strict_types=1);
|
|||
namespace App\Contract\Service;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
|
||||
interface ClockInterface
|
||||
{
|
||||
public function getUtcTimeZone(): DateTimeZone;
|
||||
|
||||
public function getCurrentDateTime(): DateTimeImmutable;
|
||||
}
|
||||
|
|
|
@ -10,9 +10,14 @@ use DateTimeZone;
|
|||
|
||||
final class Clock implements ClockInterface
|
||||
{
|
||||
public function getUtcTimeZone(): DateTimeZone
|
||||
{
|
||||
return new DateTimeZone(timezone: 'UTC');
|
||||
}
|
||||
|
||||
public function getCurrentDateTime(): DateTimeImmutable
|
||||
{
|
||||
$timezone = new DateTimeZone(timezone: 'UTC');
|
||||
$timezone = $this->getUtcTimeZone();
|
||||
return new DateTimeImmutable(datetime: 'now', timezone: $timezone);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ namespace App\Service;
|
|||
use App\Doctrine\Entity\NexusRawData;
|
||||
use DateTimeImmutable;
|
||||
|
||||
use DateTimeZone;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
final class NexusRawDataFactory
|
||||
{
|
||||
public function createFromJsonDataSubmission(object $decodedJsonData): NexusRawData
|
||||
public function createFromJsonDataSubmission(object $decodedJsonData, DateTimeZone $timeZone): NexusRawData
|
||||
{
|
||||
$nexusRawData = new NexusRawData();
|
||||
|
||||
|
@ -19,10 +21,12 @@ final class NexusRawDataFactory
|
|||
|
||||
if (array_key_exists(key: 'requestStartedAt', array: $data)) {
|
||||
$requestStartedAt = new DateTimeImmutable(datetime: $data['requestStartedAt']);
|
||||
$requestStartedAt->setTimezone(timezone: $timeZone);
|
||||
$nexusRawData->setRequestStartedAt(requestStartedAt: $requestStartedAt);
|
||||
}
|
||||
if (array_key_exists(key: 'responseCompletedAt', array: $data)) {
|
||||
$responseCompletedAt = new DateTimeImmutable(datetime: $data['responseCompletedAt']);
|
||||
$responseCompletedAt->setTimezone(timezone: $timeZone);
|
||||
$nexusRawData->setResponseCompletedAt(responseCompletedAt: $responseCompletedAt);
|
||||
}
|
||||
if (array_key_exists(key: 'method', array: $data)) {
|
||||
|
|
|
@ -23,9 +23,13 @@ final class NexusRawDataManager
|
|||
string $userAccessTokenValue,
|
||||
object $decodedJsonData
|
||||
): NexusRawDataSubmissionResult {
|
||||
$timeZone = $this->clock->getUtcTimeZone();
|
||||
$currentDateTime = $this->clock->getCurrentDateTime();
|
||||
|
||||
$nexusRawData = $this->nexusRawDataFactory->createFromJsonDataSubmission(decodedJsonData: $decodedJsonData);
|
||||
$nexusRawData = $this->nexusRawDataFactory->createFromJsonDataSubmission(
|
||||
decodedJsonData: $decodedJsonData,
|
||||
timeZone: $timeZone
|
||||
);
|
||||
|
||||
$userAccessToken = $this->userAccessTokenRepository->findByValue(value: $userAccessTokenValue);
|
||||
if (null === $userAccessToken) {
|
||||
|
|
Reference in New Issue