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