Add DateTimeFormat enum

This commit is contained in:
Alex Cabal 2024-11-08 16:41:15 -06:00
parent be5574eaec
commit c35c47b793
18 changed files with 38 additions and 26 deletions

View file

@ -54,11 +54,11 @@ class AtomFeed extends Feed{
foreach($this->Entries as $entry){
$obj = new StdClass();
if($entry instanceof Ebook){
$obj->Updated = $entry->EbookUpdated->format('Y-m-d\TH:i:s\Z');
$obj->Updated = $entry->EbookUpdated->format(Enums\DateTimeFormat::Iso->value);
$obj->Id = SITE_URL . $entry->Url;
}
else{
$obj->Updated = $entry->Updated !== null ? $entry->Updated->format('Y-m-d\TH:i:s\Z') : '';
$obj->Updated = $entry->Updated !== null ? $entry->Updated->format(Enums\DateTimeFormat::Iso->value) : '';
$obj->Id = $entry->Id;
}
$currentEntries[] = $obj;

View file

@ -0,0 +1,12 @@
<?
namespace Enums;
enum DateTimeFormat: string{
case Sql = 'Y-m-d H:i:s'; // `2022-01-05 23:42:12`
case Iso = 'Y-m-d\TH:i:s\Z'; // `2022-01-05T23:42:12Z`
case FullDateTime = 'F j, Y g:i a'; // `January 5, 2022 2:04 pm`
case Ical = 'Ymd\THis\Z'; //20220105T234212Z
case Html = 'Y-m-d\TH:i:s'; // `2022-01-05T23:42:12`
case Rss = 'r'; // `D, d M Y H:i:s`
case UnixTimestamp = 'U';
}

View file

@ -98,7 +98,7 @@ class Session{
public static function SetSessionCookie(string $sessionId): void{
/** @throws void */
setcookie('sessionid', $sessionId, ['expires' => intval((new DateTimeImmutable('+1 week'))->format('U')), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks
setcookie('sessionid', $sessionId, ['expires' => intval((new DateTimeImmutable('+1 week'))->format(Enums\DateTimeFormat::UnixTimestamp->value)), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks
}
/**