Convert use of gmdate() to DateTime

This commit is contained in:
Alex Cabal 2024-01-10 11:25:56 -06:00
parent 854fb2c816
commit 1237a65bc8
4 changed files with 17 additions and 11 deletions

View file

@ -1,9 +1,12 @@
<? <?
// Auto-included by Composer in composer.json to satisfy PHPStan // Auto-included by Composer in composer.json to satisfy PHPStan
use Safe\DateTime;
use function Safe\define; use function Safe\define;
use function Safe\gmdate;
use function Safe\strtotime; use function Safe\strtotime;
$now = new DateTime('now', new DateTimeZone('UTC'));
$nowPd = new DateTime('now', new DateTimeZone('America/Juneau')); // Latest continental US time zone
const SITE_STATUS_LIVE = 'live'; const SITE_STATUS_LIVE = 'live';
const SITE_STATUS_DEV = 'dev'; const SITE_STATUS_DEV = 'dev';
@ -110,10 +113,10 @@ const ZOHO_WEBHOOK_LOG_FILE_PATH = '/var/log/local/webhooks-zoho.log'; // Must b
const DONATIONS_LOG_FILE_PATH = '/var/log/local/donations.log'; // Must be writable by `www-data` Unix user. const DONATIONS_LOG_FILE_PATH = '/var/log/local/donations.log'; // Must be writable by `www-data` Unix user.
const ARTWORK_UPLOADS_LOG_FILE_PATH = '/var/log/local/artwork-uploads.log'; // Must be writable by `www-data` Unix user. const ARTWORK_UPLOADS_LOG_FILE_PATH = '/var/log/local/artwork-uploads.log'; // Must be writable by `www-data` Unix user.
define('PD_YEAR', intval(gmdate('Y')) - 96); define('PD_YEAR', intval($nowPd->format('Y')) - 96);
define('PD_STRING', 'January 1, ' . (PD_YEAR + 1)); 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); define('DONATION_ALERT_ON', DONATION_HOLIDAY_ALERT_ON || rand(1, 4) == 2);
// Controls the progress bar donation dialog // Controls the progress bar donation dialog

View file

@ -5,7 +5,6 @@ use function Safe\exec;
use function Safe\filemtime; use function Safe\filemtime;
use function Safe\filesize; use function Safe\filesize;
use function Safe\glob; use function Safe\glob;
use function Safe\gmdate;
use function Safe\ksort; use function Safe\ksort;
use function Safe\preg_replace; use function Safe\preg_replace;
use function Safe\shell_exec; use function Safe\shell_exec;
@ -342,6 +341,7 @@ class Library{
private static function FillBulkDownloadObject(string $dir, string $downloadType, string $urlRoot): stdClass{ private static function FillBulkDownloadObject(string $dir, string $downloadType, string $urlRoot): stdClass{
$obj = new stdClass(); $obj = new stdClass();
$now = new DateTime('now', new DateTimeZone('UTC'));
// The count of ebooks in each file is stored as a filesystem attribute // The count of ebooks in each file is stored as a filesystem attribute
$obj->EbookCount = exec('attr -g se-ebook-count ' . escapeshellarg($dir)) ?: null; $obj->EbookCount = exec('attr -g se-ebook-count ' . escapeshellarg($dir)) ?: null;
@ -392,7 +392,7 @@ class Library{
$obj->UpdatedString = $obj->Updated->format('M j'); $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) // Add a period to the abbreviated month, but not if it's May (the only 3-letter month)
$obj->UpdatedString = preg_replace('/^(.+?)(?<!May) /', '\1. ', $obj->UpdatedString); $obj->UpdatedString = preg_replace('/^(.+?)(?<!May) /', '\1. ', $obj->UpdatedString);
if($obj->Updated->format('Y') != gmdate('Y')){ if($obj->Updated->format('Y') != $now->format('Y')){
$obj->UpdatedString = $obj->Updated->format('M j, Y'); $obj->UpdatedString = $obj->Updated->format('M j, Y');
} }

View file

@ -1,9 +1,9 @@
<? <?
use Safe\DateTime;
use function Safe\fopen; use function Safe\fopen;
use function Safe\fwrite; use function Safe\fwrite;
use function Safe\fclose; use function Safe\fclose;
use function Safe\error_log; use function Safe\error_log;
use function Safe\gmdate;
use function Safe\substr; use function Safe\substr;
class Log{ class Log{
@ -34,7 +34,9 @@ class Log{
return; return;
} }
fwrite($fp, gmdate('Y-m-d H:i:s') . "\t" . $this->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); fclose($fp);
} }
} }

View file

@ -1,5 +1,5 @@
<? <?
use function Safe\gmdate; use Safe\DateTime;
use function Safe\session_unset; use function Safe\session_unset;
session_start(); session_start();
@ -8,6 +8,7 @@ $created = HttpInput::Bool(SESSION, 'artwork-created', false);
$exception = $_SESSION['exception'] ?? null; $exception = $_SESSION['exception'] ?? null;
/** @var Artwork $artwork */ /** @var Artwork $artwork */
$artwork = $_SESSION['artwork'] ?? null; $artwork = $_SESSION['artwork'] ?? null;
$now = new DateTime('now', new DateTimeZone('America/Juneau')); // Latest continental US time zone
try{ try{
if($GLOBALS['User'] === null){ if($GLOBALS['User'] === null){
@ -93,7 +94,7 @@ catch(Exceptions\InvalidPermissionsException){
type="number" type="number"
name="artist-year-of-death" name="artist-year-of-death"
min="1" min="1"
max="<?= gmdate('Y') ?>" max="<?= $now->format('Y') ?>"
value="<?= $artwork->Artist->DeathYear ?>" value="<?= $artwork->Artist->DeathYear ?>"
/> />
</label> </label>
@ -112,7 +113,7 @@ catch(Exceptions\InvalidPermissionsException){
type="number" type="number"
name="artwork-year" name="artwork-year"
min="1" min="1"
max="<?= gmdate('Y') ?>" max="<?= $now->format('Y') ?>"
value="<?= $artwork->CompletedYear ?>" value="<?= $artwork->CompletedYear ?>"
/> />
</label> </label>
@ -169,7 +170,7 @@ catch(Exceptions\InvalidPermissionsException){
type="number" type="number"
name="artwork-publication-year" name="artwork-publication-year"
min="1" min="1"
max="<?= gmdate('Y') ?>" max="<?= $now->format('Y') ?>"
value="<?= $artwork->PublicationYear ?>" value="<?= $artwork->PublicationYear ?>"
/> />
</label> </label>