1*db926724SAndreas Gohr<?php 2*db926724SAndreas Gohr 3*db926724SAndreas Gohrnamespace PHP81_BC\strftime; 4*db926724SAndreas Gohr 5*db926724SAndreas Gohruse DateTimeInterface; 6*db926724SAndreas Gohr 7*db926724SAndreas Gohr/** 8*db926724SAndreas Gohr * This formatter uses simple, non-locale aware formatting of dates 9*db926724SAndreas Gohr * 10*db926724SAndreas Gohr * It should only be used when the intl extension is not available and thus the IntlLocaleFormatter can't be used 11*db926724SAndreas Gohr */ 12*db926724SAndreas Gohrclass DateLocaleFormatter extends AbstractLocaleFormatter 13*db926724SAndreas Gohr{ 14*db926724SAndreas Gohr /** @var string[] strftime() to date() like formats that are dependend on Locales */ 15*db926724SAndreas Gohr protected $formats = [ 16*db926724SAndreas Gohr '%a' => 'D', // An abbreviated textual representation of the day Sun through Sat 17*db926724SAndreas Gohr '%A' => 'l', // A full textual representation of the day Sunday through Saturday 18*db926724SAndreas Gohr '%b' => 'M', // Abbreviated month name, Jan through Dec 19*db926724SAndreas Gohr '%B' => 'F', // Full month name, January through December 20*db926724SAndreas Gohr '%h' => 'M', // Abbreviated month name, (an alias of %b) Jan through Dec 21*db926724SAndreas Gohr '%c' => 'F j, Y \a\t g:i A', // Preferred date and time stamp 22*db926724SAndreas Gohr '%x' => 'n/j/y', // Preferred date representation, without the time 23*db926724SAndreas Gohr '%X' => 'g:i:s A', // Time only 24*db926724SAndreas Gohr ]; 25*db926724SAndreas Gohr 26*db926724SAndreas Gohr /** @inheritdoc */ 27*db926724SAndreas Gohr public function __invoke(DateTimeInterface $timestamp, string $format) 28*db926724SAndreas Gohr { 29*db926724SAndreas Gohr if (!isset($this->formats[$format])) { 30*db926724SAndreas Gohr throw new \RuntimeException("'$format' is not a supported locale placeholder"); 31*db926724SAndreas Gohr } 32*db926724SAndreas Gohr 33*db926724SAndreas Gohr trigger_error('Formatting without \\IntlDateFormatter only return english formats'); 34*db926724SAndreas Gohr 35*db926724SAndreas Gohr return $timestamp->format($this->formats[$format]); 36*db926724SAndreas Gohr } 37*db926724SAndreas Gohr 38*db926724SAndreas Gohr} 39