/**
  * Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
  *
  * @param \IntlCalendar|\DateTime $object
  * @param string|int|array|null $format
  * @param string|null $locale
  * @return string
  * @throws LocalizedException
  */
 protected function doFormatObject($object, $format = null, $locale = null)
 {
     $pattern = $dateFormat = $timeFormat = $calendar = null;
     if (is_array($format)) {
         list($dateFormat, $timeFormat) = $format;
     } elseif (is_numeric($format)) {
         $dateFormat = $format;
     } elseif (is_string($format) || null == $format) {
         $dateFormat = $timeFormat = \IntlDateFormatter::MEDIUM;
         $pattern = $format;
     } else {
         throw new LocalizedException(new Phrase('Format type is invalid'));
     }
     $timezone = $object->getTimezone();
     if ($object instanceof \IntlCalendar) {
         $timezone = $timezone->toDateTimeZone();
     }
     $timezone = $timezone->getName();
     if ($timezone === '+00:00') {
         $timezone = 'UTC';
     } elseif ($timezone[0] === '+' || $timezone[0] === '-') {
         // $timezone[0] is first symbol of string
         $timezone = 'GMT' . $timezone;
     }
     return (new \IntlDateFormatter($locale, $dateFormat, $timeFormat, $timezone, $calendar, $pattern))->format($object);
 }