create formatted output for calendar component VTIMEZONE object instance

@author Kjell-Inge Gustafsson <ical@kigkonsult.se>
@since 2.0.6 - 2007-06-20
@param array $xcaldecl
@return string
771700
function createComponent( &$xcaldecl ) {
    $objectname    = $this->_createFormat();
    $component     = $this->componentStart1.$objectname.$this->componentStart2.$this->nl;
    $component    .= $this->createTzid();
    $component    .= $this->createLastModified();
    $component    .= $this->createTzurl();
    $component    .= $this->createDtstart( TRUE );
    $component    .= $this->createTzoffsetfrom();
    $component    .= $this->createTzoffsetto();
    $component    .= $this->createComment();
    $component    .= $this->createRdate( TRUE );
    $component    .= $this->createRrule();
    $component    .= $this->createTzname();
    $component    .= $this->createXprop();
    if( $this->nl != substr( $component, ( 0 - strlen( $this->nl ))))
      $component  .= $this->nl;
    $component    .= $this->createSubComponent();
    $component    .= $this->componentEnd1.$objectname.$this->componentEnd2;
    if( is_array( $this->xcaldecl ) && ( 0 < count( $this->xcaldecl ))) {
      foreach( $this->xcaldecl as $localxcaldecl )
        $xcaldecl[] = $localxcaldecl;
    }
    return $component;
  }
1318218
private function createCalendar(string $locale = null) : \IntlCalendar
    {
        $timezone = \IntlTimeZone::createTimeZone($this->date()->getTimezone()->getName());
        $calendar = \IntlCalendar::createInstance($timezone, $locale);
        
        $calendar->setTime($this->timestampWithMillisecond());
        
        return $calendar;
    }
1083485
protected function makeCallables(
        $listener,
        $callable,
        /*# int */ $priority
    )/*# : array */ {
        $result = [];
        if (is_array($callable)) {
            if (isset($callable[1]) && is_int($callable[1])) {
                $priority = $callable[1];
                $xc = $callable[0];
            } else {
                foreach ($callable as $cc) {
                    $result = array_merge(
                        $result,
                        $this->makeCallables($listener, $cc, $priority)
                    );
                }
                return $result;
            }
        } elseif (is_string($callable)) {
            $xc = $callable;
        }

        if (isset($xc)) {
            if (!is_callable($xc)) {
                $xc = array($listener, $xc);
            }
            if (is_callable($xc)) {
                $result[] = [ $xc, $priority ];
            }
        }
        return $result;
    }
1322231
private function normalizeTtl($ttl)
    {
        if ($ttl === null) {
            return self::DEFAULT_TTL; // Default TTL is one hour
        }

        if (\is_int($ttl)) {
            return $ttl;
        }

        if ($ttl instanceof DateInterval) {
            $currentDateTime = new \DateTimeImmutable();
            $ttlDateTime = $currentDateTime->add($ttl);

            return $ttlDateTime->getTimestamp() - $currentDateTime->getTimestamp();
        }

        throw new InvalidArgumentException('Invalid TTL: ' . print_r($ttl, true));
    }
172266
function createDtstamp() {
    if( !isset( $htis->dtstamp['value']['year'] )  &&
        !isset( $this->dtstamp['value']['month'] ) &&
        !isset( $this->dtstamp['value']['day'] )   &&
        !isset( $this->dtstamp['value']['hour'] )  &&
        !isset( $this->dtstamp['value']['min'] )   &&
        !isset( $this->dtstamp['value']['sec'] ))
      $this->_makeDtstamp();
    $formatted  = $this->_format_date_time( $this->dtstamp['value'], 7 );
    $attributes = $this->_createParams( $this->dtstamp['params'] );
    return $this->_createElement( 'DTSTAMP', $attributes, $formatted );
  }
833225
public function ceil($prec = 0)
  {
    $dst = clone $this;
    $dst->value = $this->_ceil($this->value, $prec);
    return $dst;
  }
290384
public static String calendarToString(GregorianCalendar cal) {
        String s = String.format("%1$tFT%1$tT.%1$tL%1$tz", cal);
        /* s is almost right, but is missing the colon in the offset */
        assert Pattern.matches(".*[-+][0-9]{4}$", s);
        int n = s.length();
        return s.substring(0, n-2) + ":" + s.substring(n-2);
    }
465729
private function _getTzDelta()
    {
        if (is_null($this->tzDelta)) {
            $this->tzDelta = $this->manObj->get(\Magento\Framework\Stdlib\DateTime\DateTime::class);
        }
        return $this->tzDelta;
    }
1210122
function createDtstart( $localtime=FALSE ) {
    if( !isset( $this->dtstart['value']['year'] )  &&
        !isset( $this->dtstart['value']['month'] ) &&
        !isset( $this->dtstart['value']['day'] )   &&
        !isset( $this->dtstart['value']['hour'] )  &&
        !isset( $this->dtstart['value']['min'] )   &&
        !isset( $this->dtstart['value']['sec'] ))
      return;
    if( $localtime )
      unset( $this->dtstart['value']['tz'] );
    $formatted  = $this->_format_date_time( $this->dtstart['value'] );
    $attributes = $this->_createParams( $this->dtstart['params'] );
    return $this->_createElement( 'DTSTART', $attributes, $formatted );
  }
575449
public function fromSqlToIso8601Time(string $string, ?DateTimeZone $displayedTimeZone = null): string
    {
        $dateTime = DateTime::createFromFormat(
            "Y-m-d H:i:s",
            $string,
            $displayedTimeZone
        );

        if ($dateTime === false) {
            return "";
        }

        return $dateTime->format(DateTime::ATOM);
    }
1200819
private static function parseCompexDecl($decl) {
        $left = null;
        $right = null;
        $combinator = '';
        if (substr($decl, 0, 1) === '(') {
            $regex = '(^(\(((?>[^()]+)|(?1))*\)))';
            $match = [];
            if (preg_match($regex, $decl, $match)) {
                $sub = (string) $match[0];
                $left = self::fromDecl(substr($sub, 1, -1));
                if ($sub === $decl) {
                    return $left;
                }
                $decl = substr($decl, strlen($sub));
            } else {
                throw new \RuntimeException("Unmatched braces?");
            }
            if (!in_array(substr($decl, 0, 1), ['|', '&'])) {
                throw new \RuntimeException("Unknown position of combinator: $decl");
            }
            $right = self::fromDecl(substr($decl, 1));
            $combinator = substr($decl, 0, 1);
        } else {
            $orPos = strpos($decl, '|');
            $andPos = strpos($decl, '&');
            $pos = 0;
            if ($orPos === false && $andPos !== false) {
                $pos = $andPos;
            } elseif ($orPos !== false && $andPos === false) {
                $pos = $orPos;
            } elseif ($orPos !== false && $andPos !== false) {
                $pos = min($orPos, $andPos);
            } else {
                throw new \RuntimeException("No combinator found: $decl");
            }
            if ($pos === 0) {
                throw new \RuntimeException("Unknown position of combinator: $decl");
            }
            $left = self::fromDecl(substr($decl, 0, $pos));
            $right = self::fromDecl(substr($decl, $pos + 1));
            $combinator = substr($decl, $pos, 1);
        }
        if ($combinator === '|') {
            return new Type(Type::TYPE_UNION, [$left, $right]);
        } elseif ($combinator === '&') {
            return new Type(Type::TYPE_INTERSECTION, [$left, $right]);
        }
        throw new \RuntimeException("Unknown combinator $combinator");
    }
409474
public function format($datetime, $pattern, $locale = null, $timezone = null)
    {
        $date = $this->getDatetime($datetime, $timezone);

        $formatter = self::createInstance([
            'locale' => $locale ?: $this->localeDetector->getLocale(),
            'datetype' => \IntlDateFormatter::FULL,
            'timetype' => \IntlDateFormatter::FULL,
            'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
            'calendar' => \IntlDateFormatter::GREGORIAN,
            'pattern' => $pattern,
        ]);

        return $this->process($formatter, $date);
    }
754730
public function getHolidayListInICalendarFormat(HolidayList $holidayList, TranslatorInterface $translator = null, DateHelper $dateHelper = null)
    {
        $calendarFormatter = new ICalendarFormatter($translator, $dateHelper);
        $content = [];
        $content[] = $calendarFormatter->getHeader();
        $content = array_merge($content, $calendarFormatter->formatList($holidayList));
        $content[] = $calendarFormatter->getFooter();

        return implode(ICalendarFormatter::LINE_ENDING, $content).ICalendarFormatter::LINE_ENDING;
    }
937493
protected function processEventIcalDateTime(array $event, $index = 3)
    {
        $calendarTimeZone = $this->calendarTimeZone(true);

        foreach (array('DTSTART', 'DTEND', 'RECURRENCE-ID') as $type) {
            if (isset($event["{$type}_array"])) {
                $timeZone = (isset($event["{$type}_array"][0]['TZID'])) ? $event["{$type}_array"][0]['TZID'] : $calendarTimeZone;
                $event["{$type}_array"][$index] = ((is_null($timeZone)) ? '' : sprintf(self::ICAL_DATE_TIME_TEMPLATE, $timeZone)) . $event["{$type}_array"][1];
                $event["{$type}_array"][2] = $this->iCalDateToUnixTimestamp($event["{$type}_array"][3], true, true);
            }
        }

        return $event;
    }
1169003
protected function getInternalFormatter($timezone = null)
    {
        if (!$timezone) {
            $timezone = date_default_timezone_get(); // Default to server timezone
        }

        $formatter = IntlDateFormatter::create(
            DBDate::ISO_LOCALE,
            IntlDateFormatter::MEDIUM,
            IntlDateFormatter::MEDIUM,
            $timezone
        );
        $formatter->setLenient(false);

        // Note we omit timezone from this format, and we always assume server TZ
        $formatter->setPattern(DBDatetime::ISO_DATETIME);

        return $formatter;
    }
93083
public function humanReadable(bool $returnDateAndTime = true): string
    {
        $current = new Dates;
        $diff    = parent::diff($current);
        
        $parsedTxt = new class {
            public $date = '';
            public $time = '';
        };

        if ($current == $this) {
            //Now
            $this->humanDateNow($parsedTxt);
        } elseif (
            $this->humanDateIsYesterdayOrTomorrow($diff, $current) === true
        ) {
            if ($diff->invert === 0) {
                $this->humanDateYesterday($parsedTxt); //Yesterday
            } else {
                $this->humanDateTomorrow($parsedTxt); //Tomorrow
            }
        } elseif ($diff->days === 0) {
            //Today
            $this->humanDateToday($parsedTxt, $diff);
        } else {
            $this->humanDateOther($parsedTxt, $current);
        }

        $txtReturned = $parsedTxt->date;
        if ($returnDateAndTime === true && $parsedTxt->time !== '') {
            $txtReturned .= $parsedTxt->time;
        }

        return $txtReturned;
    }
515296
public XMLGregorianCalendar buildXMLGregorianCalendarDate(Calendar cal) {
        XMLGregorianCalendar result = null;
        if (cal != null) {
            result = newXMLGregorianCalendar(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1,
                    cal.get(Calendar.YEAR));
        }
        return result;
    }