diff --git a/lib/EbookPlaceholder.php b/lib/EbookPlaceholder.php index 300eab77..3b88a670 100644 --- a/lib/EbookPlaceholder.php +++ b/lib/EbookPlaceholder.php @@ -2,6 +2,7 @@ /** * @property bool $IsPublicDomain + * @property string $TimeTillIsPublicDomain A string describing how much longer it will be before this work is in the U.S. public domain, like `3 months` or `20 years`. */ class EbookPlaceholder{ use Traits\Accessor; @@ -17,6 +18,7 @@ class EbookPlaceholder{ public ?string $Notes = null; protected bool $_IsPublicDomain; + protected string $_TimeTillIsPublicDomain; protected function GetIsPublicDomain(): bool{ if(!isset($this->_IsPublicDomain)){ @@ -32,6 +34,30 @@ class EbookPlaceholder{ return $this->_IsPublicDomain; } + protected function GetTimeTillIsPublicDomain(): string{ + if(!isset($this->_TimeTillIsPublicDomain)){ + if($this->IsPublicDomain || $this->YearPublished === null){ + $this->_TimeTillIsPublicDomain = ''; + } + else{ + $years = (int)($this->YearPublished) + 96 - (int)(NOW->format('Y')); + if($years > 1){ + $this->_TimeTillIsPublicDomain = $years . ' years'; + } + else{ + $months = 13 - (int)(NOW->format('n')); + $this->_TimeTillIsPublicDomain = $months . ' month'; + + if($months != 1){ + $this->_TimeTillIsPublicDomain .= 's'; + } + } + } + } + + return $this->_TimeTillIsPublicDomain; + } + public function FillFromHttpPost(): void{ $this->PropertyFromHttp('YearPublished'); $this->PropertyFromHttp('IsWanted'); diff --git a/www/ebook-placeholders/get.php b/www/ebook-placeholders/get.php index 5455bd9c..60db0984 100644 --- a/www/ebook-placeholders/get.php +++ b/www/ebook-placeholders/get.php @@ -77,7 +77,7 @@ catch(Exceptions\EbookNotFoundException){

We don’t have this ebook in our catalog yet.

You can sponsor the production of this ebook and we’ll get working on it immediately!

EbookPlaceholder->YearPublished !== null){ ?> -

This book was published in EbookPlaceholder->YearPublished ?>, and will therefore enter the U.S. public domain on January 1, EbookPlaceholder->YearPublished + 96 ?>.

+

This book was published in EbookPlaceholder->YearPublished ?>, and will therefore enter the U.S. public domain EbookPlaceholder->TimeTillIsPublicDomain != '' ? 'in ' . $ebook->EbookPlaceholder->TimeTillIsPublicDomain : '' ?> on January 1, EbookPlaceholder->YearPublished + 96 ?>.

We can’t work on it any earlier than that.

This book is not yet in the U.S. public domain. We can’t offer it until it is.