From 1237a65bc8dfe59a1e19c1e57a68636cedd31158 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Wed, 10 Jan 2024 11:25:56 -0600 Subject: [PATCH] Convert use of gmdate() to DateTime --- lib/Constants.php | 9 ++++++--- lib/Library.php | 4 ++-- lib/Log.php | 6 ++++-- www/artworks/new.php | 9 +++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/Constants.php b/lib/Constants.php index 88e91425..2b428167 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -1,9 +1,12 @@ format('Y')) - 96); define('PD_STRING', 'January 1, ' . (PD_YEAR + 1)); -define('DONATION_HOLIDAY_ALERT_ON', time() > strtotime('November 15, ' . gmdate('Y')) || time() < strtotime('January 7, ' . gmdate('Y'))); +define('DONATION_HOLIDAY_ALERT_ON', $now > new DateTime('November 15, ' . $now->format('Y'), new DateTimeZone('UTC')) || $now < new DateTime('January 7, ' . $now->add(new DateInterval('P1Y'))->format('Y'), new DateTimeZone('UTC'))); define('DONATION_ALERT_ON', DONATION_HOLIDAY_ALERT_ON || rand(1, 4) == 2); // Controls the progress bar donation dialog diff --git a/lib/Library.php b/lib/Library.php index 79c50625..d7723100 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -5,7 +5,6 @@ use function Safe\exec; use function Safe\filemtime; use function Safe\filesize; use function Safe\glob; -use function Safe\gmdate; use function Safe\ksort; use function Safe\preg_replace; use function Safe\shell_exec; @@ -342,6 +341,7 @@ class Library{ private static function FillBulkDownloadObject(string $dir, string $downloadType, string $urlRoot): stdClass{ $obj = new stdClass(); + $now = new DateTime('now', new DateTimeZone('UTC')); // The count of ebooks in each file is stored as a filesystem attribute $obj->EbookCount = exec('attr -g se-ebook-count ' . escapeshellarg($dir)) ?: null; @@ -392,7 +392,7 @@ class Library{ $obj->UpdatedString = $obj->Updated->format('M j'); // Add a period to the abbreviated month, but not if it's May (the only 3-letter month) $obj->UpdatedString = preg_replace('/^(.+?)(?UpdatedString); - if($obj->Updated->format('Y') != gmdate('Y')){ + if($obj->Updated->format('Y') != $now->format('Y')){ $obj->UpdatedString = $obj->Updated->format('M j, Y'); } diff --git a/lib/Log.php b/lib/Log.php index ff77e6ab..48c81113 100644 --- a/lib/Log.php +++ b/lib/Log.php @@ -1,9 +1,9 @@ RequestId . "\t" . $text . "\n"); + $now = new DateTime('now', new DateTimeZone('UTC')); + + fwrite($fp, $now->format('Y-m-d H:i:s') . "\t" . $this->RequestId . "\t" . $text . "\n"); fclose($fp); } } diff --git a/www/artworks/new.php b/www/artworks/new.php index bdce9e19..53216dfb 100644 --- a/www/artworks/new.php +++ b/www/artworks/new.php @@ -1,5 +1,5 @@ " + max="format('Y') ?>" value="Artist->DeathYear ?>" /> @@ -112,7 +113,7 @@ catch(Exceptions\InvalidPermissionsException){ type="number" name="artwork-year" min="1" - max="" + max="format('Y') ?>" value="CompletedYear ?>" /> @@ -169,7 +170,7 @@ catch(Exceptions\InvalidPermissionsException){ type="number" name="artwork-publication-year" min="1" - max="" + max="format('Y') ?>" value="PublicationYear ?>" />