Skip to content

Commit

Permalink
Add extra offset to the new DateTime value to avoid time differences …
Browse files Browse the repository at this point in the history
…during the import.

Change footer links.
Make grid links to open in new window and nofollow by crawler
  • Loading branch information
Nikita Tychuk committed Aug 30, 2021
1 parent e73de1a commit 231b1c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
19 changes: 15 additions & 4 deletions src/Command/Auction/ImportMaterialPricesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
protected function configure(): void
{
$url = Config::AUCTION_PRICES_API_URL;
$this->setDescription("Import material prices from external API $url");
$this->setDescription("Import material prices from external API <href=$url>$url</>");
}

/**
Expand All @@ -67,7 +67,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$url = Config::AUCTION_PRICES_API_URL;
$output->writeln("Importing prices from $url...");
$output->writeln("Importing prices from <href=$url>$url</>...");

$materials = $this->materialRepository->findAll();

Expand Down Expand Up @@ -157,10 +157,21 @@ private function importMaterialPriceByName(string $materialName): array
private function convertTimestampToDateTime(int $timestamp): \DateTime
{
$dateTime = new \DateTime();

$dateTime->setTimezone(new \DateTimeZone(Config::CONSOLE_TIMEZONE));
$dateTime->setTimestamp($timestamp);

$consoleDateTime = new \DateTime();
$emulatedDateTime = new \DateTime('now', new \DateTimeZone(Config::CONSOLE_TIMEZONE));

// Since the ORM reads DateTime field from the database in a string form, in case of incorrect timezone
// configured for PHP, the timestamp of the field is incorrect and has extra offset. So for the correct
// comparison and saving to the database, the same offset should be added to the new DateTime value.
//
// For example, if PHP uses UTC timezone but the database uses Europe/Kiev, ORM reads Europe/Kiev time
// as a UTC time adding extra offset 10800 (in summer) to the timestamp
$emulatedOffset = $emulatedDateTime->getOffset() - $consoleDateTime->getOffset();

$dateTime->setTimestamp($timestamp + $emulatedOffset);

return $dateTime;
}

Expand Down
10 changes: 4 additions & 6 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ class Config

const AUCTION_PRICES_API_URL = 'https://atherdev.nl/sb/api/v2';

/**
* Since there is no permission to specify timezone for console PHP on the server,
* the timezone is hardcoded here to avoid time difference during the import
*
* @note Use for console commands only!
*/
// Since there is no permission to specify timezone for console PHP on the server,
// the timezone is hardcoded here to avoid time differences during the import.
//
// Use for console commands only!
const CONSOLE_TIMEZONE = 'Europe/Kiev';
}
4 changes: 2 additions & 2 deletions templates/_footer.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<footer class="my-5 pt-5 text-muted text-center text-small">
<p class="mb-1">1SB:Trader Pro <small class="text-muted">by Valant13</small></p>
<ul class="list-inline">
<li class="list-inline-item"><a href="https://symfony.com/" target="_blank" rel="nofollow">Symfony</a></li>
<li class="list-inline-item"><a href="https://bootswatch.com/" target="_blank" rel="nofollow">Bootswatch</a></li>
<li class="list-inline-item"><a href="https://gitlab.com/Valant13/1sb" target="_blank" rel="nofollow">GitLab</a></li>
<li class="list-inline-item"><a href="https://atherdev.nl/sb/api/v2" target="_blank" rel="nofollow">Auction API</a></li>
<li class="list-inline-item"><a href="https://wiki.starbasegame.com/" target="_blank" rel="nofollow">Starbase wiki</a></li>
</ul>
</footer>
2 changes: 1 addition & 1 deletion templates/_grid.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{% endif %}
{% elseif cell.type == "link" %}
{% if cell.href %}
<a href="{{ cell.href }}">{{ cell.text }}</a>
<a href="{{ cell.href }}" target="_blank" rel="nofollow">{{ cell.text }}</a>
{% else %}
{{ cell.text }}
{% endif %}
Expand Down

0 comments on commit 231b1c8

Please sign in to comment.