| 1 | <?php |
||
| 9 | abstract class AbstractDateParser extends FixedTextParser |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @return string |
||
| 13 | * |
||
| 14 | * @throws UnsupportedDateFormatException |
||
| 15 | */ |
||
| 16 | 2 | public function getText() |
|
| 17 | { |
||
| 18 | try { |
||
| 19 | 2 | $dateFormat = $this->getDateFormat(); |
|
| 20 | |||
| 21 | 2 | $dateFormatter = DateFormatterFactory::getFormatter($dateFormat); |
|
| 22 | |||
| 23 | 2 | return $dateFormatter->format( |
|
| 24 | 2 | $this->getDateTime(), |
|
| 25 | $dateFormat |
||
| 26 | ); |
||
| 27 | } catch (\Exception $e) { |
||
| 28 | throw new UnsupportedDateFormatException($this->getDateFormat()); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Fetch a DateTime object set to the correct date/time. |
||
| 34 | * |
||
| 35 | * @return DateTimeInterface |
||
| 36 | */ |
||
| 37 | abstract protected function getDateTime(); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | 4 | public function getDateFormat() |
|
| 46 | } |
||
| 47 |