Switch from DateTime to DateTimeImmutable across codebase

This commit is contained in:
Alex Cabal 2024-04-13 14:05:14 -05:00
parent 92c647f2b1
commit e55fecaaa2
35 changed files with 102 additions and 99 deletions

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\date;
/**
@ -12,8 +12,8 @@ use function Safe\date;
class Artist extends Accessor{
public ?int $ArtistId = null;
public ?string $Name = null;
public ?datetime $Created = null;
public ?datetime $Updated = null;
public ?DateTimeImmutable $Created = null;
public ?DateTimeImmutable $Updated = null;
protected ?int $_DeathYear = null;
protected ?string $_UrlName = null;
protected ?string $_Url = null;
@ -82,7 +82,7 @@ class Artist extends Accessor{
// *******
public function Validate(): void{
$now = new DateTime('now', new DateTimeZone('UTC'));
$now = new DateTimeImmutable();
$thisYear = intval($now->format('Y'));
$error = new Exceptions\ValidationException();

View file

@ -1,7 +1,7 @@
<?
use Exceptions\InvalidUrlException;
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\apcu_cache_info;
use function Safe\copy;
@ -40,8 +40,8 @@ class Artwork extends Accessor{
public ?int $ArtistId = null;
public ?int $CompletedYear = null;
public bool $CompletedYearIsCirca = false;
public ?DateTime $Created = null;
public ?DateTime $Updated = null;
public ?DateTimeImmutable $Created = null;
public ?DateTimeImmutable $Updated = null;
public ?string $EbookUrl = null;
public ?int $SubmitterUserId = null;
public ?int $ReviewerUserId = null;
@ -356,7 +356,7 @@ class Artwork extends Accessor{
}
}
$now = new DateTime('now', new DateTimeZone('UTC'));
$now = new DateTimeImmutable();
$thisYear = intval($now->format('Y'));
$error = new Exceptions\ValidationException();
@ -680,7 +680,7 @@ class Artwork extends Accessor{
$this->Validate($imagePath, true);
$this->Created = new DateTime();
$this->Created = new DateTimeImmutable();
$tags = [];
foreach($this->Tags as $artworkTag){
@ -745,7 +745,7 @@ class Artwork extends Accessor{
// Manually set the updated timestamp, because if we only update the image and nothing else, the row's
// updated timestamp won't change automatically.
$this->Updated = new DateTime('now', new DateTimeZone('UTC'));
$this->Updated = new DateTimeImmutable();
$this->_ImageUrl = null;
$this->_ThumbUrl = null;
$this->_Thumb2xUrl = null;

View file

@ -1,10 +1,10 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
class AtomFeed extends Feed{
public string $Id;
public ?DateTime $Updated = null;
public ?DateTimeImmutable $Updated = null;
public ?string $Subtitle = null;
/**
@ -39,7 +39,7 @@ class AtomFeed extends Feed{
// Did we actually update the feed? If so, write to file and update the index
if($this->HasChanged($this->Path)){
// Files don't match, save the file
$this->Updated = new DateTime();
$this->Updated = new DateTimeImmutable();
$this->Save();
return true;
}

View file

@ -1,10 +1,10 @@
<?
// Auto-included by Composer in composer.json to satisfy PHPStan
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\define;
$now = new DateTime('now', new DateTimeZone('UTC'));
$nowPd = new DateTime('now', new DateTimeZone('America/Juneau')); // Latest continental US time zone
$now = new DateTimeImmutable();
$nowPd = new DateTimeImmutable('now', new DateTimeZone('America/Juneau')); // Latest continental US time zone
const SITE_STATUS_LIVE = 'live';
const SITE_STATUS_DEV = 'dev';
@ -94,7 +94,7 @@ const ARTWORK_UPLOADS_LOG_FILE_PATH = '/var/log/local/artwork-uploads.log'; // M
define('PD_YEAR', intval($nowPd->format('Y')) - 96);
define('PD_STRING', 'January 1, ' . (PD_YEAR + 1));
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_HOLIDAY_ALERT_ON', $now > new DateTimeImmutable('November 15, ' . $now->format('Y')) || $now < new DateTimeImmutable('January 7, ' . $now->add(new DateInterval('P1Y'))->format('Y')));
define('DONATION_ALERT_ON', DONATION_HOLIDAY_ALERT_ON || rand(1, 4) == 2);
// Controls the progress bar donation dialog

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\preg_match;
use function Safe\posix_getpwuid;
@ -199,7 +199,7 @@ class DbConnection{
switch($metadata[$i]['native_type'] ?? null){
case 'DATETIME':
case 'TIMESTAMP':
$object->{$metadata[$i]['name']} = new DateTime($row[$i], new DateTimeZone('UTC'));
$object->{$metadata[$i]['name']} = new DateTimeImmutable($row[$i], new DateTimeZone('UTC'));
break;
case 'LONG':

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
use function Safe\filesize;
use function Safe\json_encode;
@ -67,8 +67,8 @@ class Ebook{
public $Contributors = [];
public ?string $ContributorsHtml = null;
public string $TitleWithCreditsHtml = '';
public DateTime $Created;
public DateTime $Updated;
public DateTimeImmutable $Created;
public DateTimeImmutable $Updated;
public string $TextUrl;
public string $TextSinglePageUrl;
public ?string $TextSinglePageSizeNumber = null;
@ -222,12 +222,12 @@ class Ebook{
$date = $xml->xpath('/package/metadata/dc:date') ?: [];
if($date !== false && sizeof($date) > 0){
$this->Created = new DateTime((string)$date[0]);
$this->Created = new DateTimeImmutable((string)$date[0]);
}
$modifiedDate = $xml->xpath('/package/metadata/meta[@property="dcterms:modified"]') ?: [];
if($modifiedDate !== false && sizeof($modifiedDate) > 0){
$this->Updated = new DateTime((string)$modifiedDate[0]);
$this->Updated = new DateTimeImmutable((string)$modifiedDate[0]);
}
// Get SE tags

View file

@ -22,7 +22,7 @@ class ValidationException extends AppException{
public function Add(\Exception $exception, bool $isFatal = false): void{
if(is_a($exception, static::class)){
// Type hint for linter
/** @var ValidationException $exception */
/** @var ValidationException $childException */
foreach($exception->Exceptions as $childException){
$this->Add($childException);
}

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\apcu_fetch;
use function Safe\exec;
use function Safe\filemtime;
@ -432,7 +432,7 @@ class Library{
private static function FillBulkDownloadObject(string $dir, string $downloadType, string $urlRoot): stdClass{
$obj = new stdClass();
$now = new DateTime('now', new DateTimeZone('UTC'));
$now = new DateTimeImmutable();
// The count of ebooks in each file is stored as a filesystem attribute
$obj->EbookCount = exec('attr -g se-ebook-count ' . escapeshellarg($dir)) ?: null;
@ -479,7 +479,7 @@ class Library{
$obj->ZipFiles[] = $zipFile;
}
$obj->Updated = new DateTime('@' . filemtime($files[0]));
$obj->Updated = new DateTimeImmutable('@' . filemtime($files[0]));
$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('/^(.+?)(?<!May) /', '\1. ', $obj->UpdatedString);
@ -546,7 +546,7 @@ class Library{
foreach($dirs as $dir){
$obj = self::FillBulkDownloadObject($dir, 'months', '/months');
$date = new DateTime($obj->Label . '-01');
$date = new DateTimeImmutable($obj->Label . '-01');
$year = $date->format('Y');
$month = $date->format('F');

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\fopen;
use function Safe\fwrite;
use function Safe\fclose;
@ -33,7 +33,7 @@ class Log{
return;
}
$now = new DateTime('now', new DateTimeZone('UTC'));
$now = new DateTimeImmutable();
fwrite($fp, $now->format('Y-m-d H:i:s') . "\t" . $this->RequestId . "\t" . $text . "\n");
fclose($fp);

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
/**
* @property User $User
@ -10,7 +10,7 @@ class NewsletterSubscription extends Accessor{
public bool $IsSubscribedToSummary = false;
public bool $IsSubscribedToNewsletter = false;
public ?int $UserId = null;
public DateTime $Created;
public DateTimeImmutable $Created;
protected $_User;
protected $_Url = null;
@ -44,7 +44,7 @@ class NewsletterSubscription extends Accessor{
}
$this->UserId = $this->User->UserId;
$this->Created = new DateTime();
$this->Created = new DateTimeImmutable();
try{
Db::Query('

View file

@ -1,6 +1,4 @@
<?
use Safe\DateTime;
class OpdsAcquisitionFeed extends OpdsFeed{
public bool $IsCrawlable;

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\file_put_contents;
class OpdsFeed extends AtomFeed{
@ -24,7 +24,7 @@ class OpdsFeed extends AtomFeed{
// METHODS
// *******
protected function SaveUpdated(string $entryId, DateTime $updated): void{
protected function SaveUpdated(string $entryId, DateTimeImmutable $updated): void{
// Only save the updated timestamp for the given entry ID in this file
foreach($this->Entries as $entry){
if($entry instanceof OpdsNavigationEntry){
@ -50,7 +50,7 @@ class OpdsFeed extends AtomFeed{
if($this->HasChanged($this->Path)){
// Files don't match, save the file and update the parent navigation feed with the last updated timestamp
$this->Updated = new DateTime();
$this->Updated = new DateTimeImmutable();
if($this->Parent !== null){
$this->Parent->SaveUpdated($this->Id, $this->Updated);

View file

@ -1,15 +1,17 @@
<?
use Safe\DateTimeImmutable;
class OpdsNavigationEntry{
public string $Id;
public string $Url;
public string $Rel;
public string $Type;
public ?DateTime $Updated = null;
public ?DateTimeImmutable $Updated = null;
public string $Description;
public string $Title;
public string $SortTitle;
public function __construct(string $title, string $description, string $url, ?DateTime $updated, string $rel, string $type){
public function __construct(string $title, string $description, string $url, ?DateTimeImmutable $updated, string $rel, string $type){
$this->Id = SITE_URL . $url;
$this->Url = $url;
$this->Rel = $rel;

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
class OpdsNavigationFeed extends OpdsFeed{
@ -25,7 +25,7 @@ class OpdsNavigationFeed extends OpdsFeed{
foreach($xml->xpath('//entry') ?: [] as $existingEntry){
foreach($this->Entries as $entry){
if($entry->Id == $existingEntry->id){
$entry->Updated = new DateTime($existingEntry->updated);
$entry->Updated = new DateTimeImmutable($existingEntry->updated);
}
}
}

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
/**
* @property User $User
@ -10,8 +10,8 @@ class Patron extends Accessor{
public bool $IsAnonymous;
public ?string $AlternateName = null;
public bool $IsSubscribedToEmails;
public ?DateTime $Created = null;
public ?DateTime $Ended = null;
public ?DateTimeImmutable $Created = null;
public ?DateTimeImmutable $Ended = null;
// *******
@ -19,7 +19,7 @@ class Patron extends Accessor{
// *******
public function Create(): void{
$this->Created = new DateTime();
$this->Created = new DateTimeImmutable();
Db::Query('
INSERT into Patrons (Created, UserId, IsAnonymous, AlternateName, IsSubscribedToEmails)
values(?,

View file

@ -1,11 +1,13 @@
<?
use Safe\DateTimeImmutable;
/**
* @property User $User
*/
class Payment extends Accessor{
public int $PaymentId;
public ?int $UserId = null;
public DateTime $Created;
public DateTimeImmutable $Created;
public int $ChannelId;
public string $TransactionId;
public float $Amount;

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\usort;
/**
@ -15,9 +15,9 @@ class Poll extends Accessor{
public string $Name;
public string $UrlName;
public string $Description;
public DateTime $Created;
public DateTime $Start;
public DateTime $End;
public DateTimeImmutable $Created;
public DateTimeImmutable $Start;
public DateTimeImmutable $End;
protected ?string $_Url = null;
protected $_PollItems = null;
protected $_PollItemsByWinner = null;
@ -85,7 +85,7 @@ class Poll extends Accessor{
// *******
public function IsActive(): bool{
$now = new DateTime();
$now = new DateTimeImmutable();
if( ($this->Start !== null && $this->Start > $now) || ($this->End !== null && $this->End < $now)){
return false;
}

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
/**
* @property User $User
@ -8,7 +8,7 @@ use Safe\DateTime;
*/
class PollVote extends Accessor{
public int $UserId;
public DateTime $Created;
public DateTimeImmutable $Created;
public ?int $PollItemId = null;
protected ?User $_User = null;
protected ?PollItem $_PollItem = null;
@ -98,7 +98,7 @@ class PollVote extends Accessor{
}
$this->Validate();
$this->Created = new DateTime();
$this->Created = new DateTimeImmutable();
Db::Query('
INSERT into PollVotes (UserId, PollItemId, Created)
values (?,

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
use function Safe\filesize;
use function Safe\preg_replace;
@ -27,7 +27,7 @@ class RssFeed extends Feed{
protected function GetXmlString(): string{
if($this->XmlString === null){
$feed = Template::RssFeed(['url' => $this->Url, 'description' => $this->Description, 'title' => $this->Title, 'entries' => $this->Entries, 'updated' => (new DateTime())->format('r')]);
$feed = Template::RssFeed(['url' => $this->Url, 'description' => $this->Description, 'title' => $this->Title, 'entries' => $this->Entries, 'updated' => (new DateTimeImmutable())->format('r')]);
$this->XmlString = $this->CleanXmlString($feed);
}

View file

@ -2,7 +2,7 @@
use Exceptions\InvalidLoginException;
use Ramsey\Uuid\Uuid;
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\strtotime;
/**
@ -12,7 +12,7 @@ use function Safe\strtotime;
class Session extends Accessor{
public int $UserId;
protected ?User $_User = null;
public DateTime $Created;
public DateTimeImmutable $Created;
public string $SessionId;
public ?string $_Url = null;
@ -53,7 +53,7 @@ class Session extends Accessor{
else{
$uuid = Uuid::uuid4();
$this->SessionId = $uuid->toString();
$this->Created = new DateTime();
$this->Created = new DateTimeImmutable();
Db::Query('
INSERT into Sessions (UserId, SessionId, Created)
values (?,

View file

@ -1,6 +1,6 @@
<?
use Ramsey\Uuid\Uuid;
use Safe\DateTime;
use Safe\DateTimeImmutable;
/**
* @property Array<Payment> $Payments
@ -12,7 +12,7 @@ class User extends Accessor{
public int $UserId;
public ?string $Name = null;
public ?string $Email = null;
public DateTime $Created;
public DateTimeImmutable $Created;
public string $Uuid;
public ?string $PasswordHash = null;
protected ?bool $_IsRegistered = null;
@ -78,7 +78,7 @@ class User extends Accessor{
public function Create(?string $password = null): void{
$uuid = Uuid::uuid4();
$this->Uuid = $uuid->toString();
$this->Created = new DateTime();
$this->Created = new DateTimeImmutable();
$this->PasswordHash = null;
if($password !== null){

View file

@ -2,7 +2,7 @@
<?
require_once('/standardebooks.org/web/lib/Core.php');
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\getopt;
use function Safe\mkdir;
use function Safe\preg_replace;
@ -11,7 +11,7 @@ function SortByUpdatedDesc($a, $b){
return $b->Updated <=> $a->Updated;
}
function SaveFeed(Feed $feed, bool $force, ?string $label = null, ?string $labelSort = null, DateTime $now = null): void{
function SaveFeed(Feed $feed, bool $force, ?string $label = null, ?string $labelSort = null, DateTimeImmutable $now = null): void{
$updateAttrs = false;
if($force){
@ -31,7 +31,7 @@ function SaveFeed(Feed $feed, bool $force, ?string $label = null, ?string $label
}
}
function CreateOpdsCollectionFeed(string $name, string $url, string $description, array $collections, array $ebooks, DateTime $now, string $webRoot, OpdsNavigationFeed $opdsRoot, bool $force): void{
function CreateOpdsCollectionFeed(string $name, string $url, string $description, array $collections, array $ebooks, DateTimeImmutable $now, string $webRoot, OpdsNavigationFeed $opdsRoot, bool $force): void{
$collator = collator_create('en_US'); // Used for sorting letters with diacritics like in author names
usort($collections, function($a, $b) use($collator){ return $collator->compare($a['sortedname'], $b['sortedname']); });
@ -108,7 +108,7 @@ usort($allEbooks, 'SortByUpdatedDesc');
usort($newestEbooks, function($a, $b){ return $b->Created <=> $a->Created; });
$newestEbooks = array_slice($newestEbooks, 0, $ebooksPerNewestEbooksFeed);
$now = new DateTime();
$now = new DateTimeImmutable();
// Create OPDS feeds
$opdsRootEntries = [

View file

@ -16,7 +16,7 @@ use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Firefox\FirefoxDriver;
use Facebook\WebDriver\Firefox\FirefoxOptions;
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
use function Safe\preg_replace;
use function Safe\putenv;
@ -44,7 +44,7 @@ $lastSeenTransactionId = null;
$firstTransactionId = null;
$transactionFilePath = '/tmp/last-fa-donation';
$transactionIds = [];
$now = new DateTime('now', new DateTimeZone('UTC'));
$now = new DateTimeImmutable();
$today = $now->format('n/j/Y');
$faItemsPerPage = 20; // How many items are on a full page of FA results?

View file

@ -9,7 +9,7 @@ use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Firefox\FirefoxDriver;
use Facebook\WebDriver\Firefox\FirefoxOptions;
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\preg_match;
use function Safe\preg_replace;
use function Safe\putenv;
@ -31,8 +31,8 @@ $capabilities->setCapability(FirefoxOptions::CAPABILITY, $firefoxOptions);
$driver = null;
$log = new Log(DONATIONS_LOG_FILE_PATH);
$lastMonth = (new DateTime())->sub(new DateInterval('P45D')); // 45 days, a 15 day grace period before Patrons Circle members are dropped off
$lastYear = (new DateTime())->sub(new DateInterval('P1Y'));
$lastMonth = (new DateTimeImmutable())->sub(new DateInterval('P45D')); // 45 days, a 15 day grace period before Patrons Circle members are dropped off
$lastYear = (new DateTimeImmutable())->sub(new DateInterval('P1Y'));
$faUsername = get_cfg_var('se.secrets.fractured_atlas.username');
$faPassword = get_cfg_var('se.secrets.fractured_atlas.password');
@ -152,7 +152,7 @@ try{
$payment->User = null;
}
$payment->Created = DateTime::createFromFormat('n/j/Y', trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::th[normalize-space(.) = "Created"]]'))->getText()));
$payment->Created = DateTimeImmutable::createFromFormat('n/j/Y', trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::th[normalize-space(.) = "Created"]]'))->getText()));
$payment->IsRecurring = sizeof($headerRow->findElements(WebDriverBy::xpath('//td[contains(., "Recurring")]'))) > 0;
$payment->Amount = floatval(str_replace('$', '', trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::th[normalize-space(.) = "Total Amount"]]'))->getText())));
$payment->Fee = floatval(str_replace('$', '', trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::th[normalize-space(.) = "Fee"]]'))->getText())));

View file

@ -2,12 +2,14 @@
<?
require_once('/standardebooks.org/web/lib/Core.php');
use Safe\DateTimeImmutable;
// Get a list of payments that are within 1 year / 45 days of today, and deactivate Patrons Circle members
// who aren't in that list.
// We give a 15 day grace period to Patrons Circle members because sometimes FA can be delayed in charging.
$now = new DateTime();
$lastYear = new DateTime('-1 year');
$now = new DateTimeImmutable();
$lastYear = new DateTimeImmutable('-1 year');
$expiredPatrons = Db::Query('
SELECT * from Patrons
@ -38,7 +40,7 @@ if(sizeof($expiredPatrons) > 0){
preg_match_all('/<dc:date>(.+?)<\/dc:date>/iu', $metadata, $matches);
if(sizeof($matches) > 0){
$created = new DateTime($matches[1][0]);
$created = new DateTimeImmutable($matches[1][0]);
if($created >= $lastYear){
$ebooksThisYear++;
}

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
$artwork = $artwork ?? null;
@ -10,7 +10,7 @@ if($artwork === null){
$isEditForm = $isEditForm ?? false;
$now = new DateTime('now', new DateTimeZone('America/Juneau')); // Latest continental US time zone
$now = new DateTimeImmutable('now', new DateTimeZone('America/Juneau')); // Latest continental US time zone
?>
<fieldset>
<legend>Artist details</legend>

View file

@ -1,8 +1,9 @@
<?
use Safe\DateTimeImmutable;
$start = new DateTime(DONATION_DRIVE_COUNTER_START);
$end = new DateTime(DONATION_DRIVE_COUNTER_END);
$now = new DateTime();
$start = new DateTimeImmutable(DONATION_DRIVE_COUNTER_START);
$end = new DateTimeImmutable(DONATION_DRIVE_COUNTER_END);
$now = new DateTimeImmutable();
// Hide the alert if the user has closed it
if(!DONATION_DRIVE_COUNTER_ON || ($autoHide ?? $_COOKIE['hide-donation-alert'] ?? false) || $now > $end){

View file

@ -1,14 +1,14 @@
<?
use Safe\DateTimeImmutable;
$start = new DateTime(DONATION_DRIVE_START);
$end = new DateTime(DONATION_DRIVE_END);
$start = new DateTimeImmutable(DONATION_DRIVE_START);
$end = new DateTimeImmutable(DONATION_DRIVE_END);
$now = new DateTimeImmutable();
$totalCurrent = 0;
$baseTarget = 50;
$stretchCurrent = 0;
$stretchTarget = 20;
$now = new DateTime();
// Hide the alert if the user has closed it
if(!DONATION_DRIVE_ON || ($autoHide ?? $_COOKIE['hide-donation-alert'] ?? false) || $GLOBALS['User'] !== null || $now > $end){
return;

View file

@ -1,6 +1,4 @@
<?
use Safe\DateTime;
// Note that the XSL stylesheet gets stripped during `se clean` when we generate the feed.
// `se clean` will also start adding empty namespaces everywhere if we include the stylesheet declaration first.
// We have to add it programmatically when saving the feed file.

View file

@ -297,7 +297,7 @@ catch(Exceptions\EbookNotFoundException){
<ol>
<? foreach($ebook->GitCommits as $commit){ ?>
<li>
<time datetime="<?= $commit->Created->format(DateTime::RFC3339) ?>"><?= $commit->Created->format('M j, Y') ?></time>
<time datetime="<?= $commit->Created->format(DateTimeImmutable::RFC3339) ?>"><?= $commit->Created->format('M j, Y') ?></time>
<p><a href="<?= Formatter::EscapeHtml($ebook->GitHubUrl) ?>/commit/<?= Formatter::EscapeHtml($commit->Hash) ?>"><?= Formatter::EscapeHtml($commit->Message) ?></a></p>
</li>
<? } ?>

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
$ebooks = [];
@ -25,7 +25,7 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"" . S
<title>Search Results</title>
<subtitle>Results for <?= Formatter::EscapeXml($query) ?>”.</subtitle>
<icon><?= SITE_URL ?>/images/logo.png</icon>
<updated><?= (new Datetime())->Format('Y-m-d\TH:i:s\Z') ?></updated>
<updated><?= (new DateTimeImmutable())->Format('Y-m-d\TH:i:s\Z') ?></updated>
<author>
<name>Standard Ebooks</name>
<uri><?= SITE_URL ?></uri>

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
$ebooks = [];
@ -26,7 +26,7 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"". SI
<title>Search Results</title>
<subtitle>Results for <?= Formatter::EscapeXml($query) ?>”.</subtitle>
<icon><?= SITE_URL ?>/images/logo.png</icon>
<updated><?= (new Datetime())->Format('Y-m-d\TH:i:s\Z') ?></updated>
<updated><?= (new DateTimeImmutable())->Format('Y-m-d\TH:i:s\Z') ?></updated>
<author>
<name>Standard Ebooks</name>
<uri><?= SITE_URL ?></uri>

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
$ebooks = [];
@ -24,7 +24,7 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<?xml-stylesheet href=\"" . S
<description>Results for <?= Formatter::EscapeXml($query) ?>”.</description>
<language>en-US</language>
<copyright>https://creativecommons.org/publicdomain/zero/1.0/</copyright>
<lastBuildDate><?= (new DateTime())->format('r') ?></lastBuildDate>
<lastBuildDate><?= (new DateTimeImmutable())->format('r') ?></lastBuildDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<atom:link href="<?= SITE_URL ?>/feeds/rss/all?query=<?= urlencode($query) ?>" rel="self" type="application/rss+xml"/>
<atom:link href="<?= SITE_URL ?>/ebooks/opensearch" rel="search" type="application/opensearchdescription+xml" />

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
$poll = new Poll();
$canVote = true; // Allow non-logged-in users to see the 'vote' button
@ -7,7 +7,7 @@ $canVote = true; // Allow non-logged-in users to see the 'vote' button
try{
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname'));
if(!$poll->IsActive() && $poll->End !== null && $poll->End < new DateTime()){
if(!$poll->IsActive() && $poll->End !== null && $poll->End < new DateTimeImmutable()){
// If the poll ended, redirect to the results
header('Location: ' . $poll->Url . '/votes');
exit();
@ -47,7 +47,7 @@ catch(Exceptions\AppException){
<a href="<?= $poll->Url ?>/votes" class="button">View results</a>
</p>
<? }else{ ?>
<? if($poll->Start !== null && $poll->Start > new DateTime()){ ?>
<? if($poll->Start !== null && $poll->Start > new DateTimeImmutable()){ ?>
<p class="center-notice">This poll opens on <?= $poll->Start->format('F j, Y g:i a') ?>.</p>
<? }else{ ?>
<p class="center-notice">This poll closed on <?= $poll->End->format('F j, Y g:i a') ?>.</p>

View file

@ -1,5 +1,5 @@
<?
use Safe\DateTime;
use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
use function Safe\preg_match;
use function Safe\preg_replace;