From d84f771c5d27d9296c1672880dd81faf96d886f1 Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Tue, 1 Dec 2020 15:49:23 +0100 Subject: [PATCH] Replace `strtotime()` with `Date::toTimestamp()` --- admin/src/Statistics.php | 3 ++- admin/src/Updater.php | 3 ++- formwork/Core/Formwork.php | 5 +++-- formwork/Core/Page.php | 7 ++++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/admin/src/Statistics.php b/admin/src/Statistics.php index 96033a01..738dc896 100644 --- a/admin/src/Statistics.php +++ b/admin/src/Statistics.php @@ -4,6 +4,7 @@ namespace Formwork\Admin; use Formwork\Admin\Utils\IPAnonymizer; use Formwork\Admin\Utils\Registry; +use Formwork\Utils\Date; use Formwork\Utils\FileSystem; use Formwork\Utils\HTTPRequest; use Formwork\Utils\Visitor; @@ -151,7 +152,7 @@ class Statistics $uniqueVisits = array_slice($uniqueVisits, -$limit, null, true); $label = static function (string $day): string { - $time = strtotime($day); + $time = Date::toTimestamp($day, self::DATE_FORMAT); $month = Admin::instance()->label('date.months.short')[date('n', $time) - 1]; $weekday = Admin::instance()->label('date.weekdays.short')[date('N', $time) % 7]; $day = date('j', $time); diff --git a/admin/src/Updater.php b/admin/src/Updater.php index f99f53c4..ba0c9ed4 100644 --- a/admin/src/Updater.php +++ b/admin/src/Updater.php @@ -5,6 +5,7 @@ namespace Formwork\Admin; use Formwork\Admin\Utils\Registry; use Formwork\Core\Formwork; use Formwork\Parsers\JSON; +use Formwork\Utils\Date; use Formwork\Utils\FileSystem; use Formwork\Utils\Str; use RuntimeException; @@ -253,7 +254,7 @@ class Updater $this->release = [ 'name' => $data['name'], 'tag' => $data['tag_name'], - 'date' => strtotime($data['published_at']), + 'date' => Date::toTimestamp($data['published_at'], DATE_ISO8601), 'archive' => $data['zipball_url'] ]; diff --git a/formwork/Core/Formwork.php b/formwork/Core/Formwork.php index 495c9f14..8c421421 100644 --- a/formwork/Core/Formwork.php +++ b/formwork/Core/Formwork.php @@ -10,6 +10,7 @@ use Formwork\Parsers\YAML; use Formwork\Router\RouteParams; use Formwork\Router\Router; use Formwork\Traits\SingletonTrait; +use Formwork\Utils\Date; use Formwork\Utils\FileSystem; use Formwork\Utils\Header; use Formwork\Utils\HTTPRequest; @@ -336,8 +337,8 @@ final class Formwork return $this->site->errorPage(); } if ($this->option('cache.enabled') && ($page->has('publish-date') || $page->has('unpublish-date'))) { - if (($page->published() && !$this->site->modifiedSince((int) strtotime($page->get('publish-date')))) - || (!$page->published() && !$this->site->modifiedSince((int) strtotime($page->get('unpublish-date'))))) { + if (($page->published() && !$this->site->modifiedSince(Date::toTimestamp($page->get('publish-date')))) + || (!$page->published() && !$this->site->modifiedSince(Date::toTimestamp($page->get('unpublish-date'))))) { // Clear cache if the site was not modified since the page has been published or unpublished $this->cache->clear(); FileSystem::touch($this->option('content.path')); diff --git a/formwork/Core/Page.php b/formwork/Core/Page.php index 463b7f8e..beb6311f 100644 --- a/formwork/Core/Page.php +++ b/formwork/Core/Page.php @@ -7,6 +7,7 @@ use Formwork\Metadata\Metadata; use Formwork\Parsers\Markdown; use Formwork\Parsers\YAML; use Formwork\Template\Template; +use Formwork\Utils\Date; use Formwork\Utils\FileSystem; use Formwork\Utils\Header; use Formwork\Utils\Str; @@ -288,7 +289,7 @@ class Page extends AbstractPage $format = Formwork::instance()->option('date.format'); } if ($this->has('publish-date')) { - return date($format, strtotime($this->data['publish-date'])); + return date($format, Date::toTimestamp($this->data['publish-date'])); } return parent::date($format); } @@ -572,11 +573,11 @@ class Page extends AbstractPage $this->published = $this->data['published']; if ($this->has('publish-date')) { - $this->published = $this->published && strtotime($this->get('publish-date')) < time(); + $this->published = $this->published && Date::toTimestamp($this->get('publish-date')) < time(); } if ($this->has('unpublish-date')) { - $this->published = $this->published && strtotime($this->get('unpublish-date')) > time(); + $this->published = $this->published && Date::toTimestamp($this->get('unpublish-date')) > time(); } $this->routable = $this->data['routable'];