src/ICal/ICal.php
public function iCalDateWithTimeZone(array $event, $key, $format = self::DATE_TIME_FORMAT)
    {
        if (!isset($event[$key . '_array']) || !isset($event[$key])) {
            return false;
        }

        $dateArray = $event[$key . '_array'];

        if ($key === 'DURATION') {
            $duration = end($dateArray);
            $dateTime = $this->parseDuration($event['DTSTART'], $duration, null);
        } else {
            $dateTime = new \DateTime($dateArray[1], new \DateTimeZone(self::TIME_ZONE_UTC));
            $dateTime->setTimezone(new \DateTimeZone($this->calendarTimeZone()));
        }

        // Force time zone
        if (isset($dateArray[0]['TZID'])) {
            if ($this->isValidIanaTimeZoneId($dateArray[0]['TZID'])) {
                $dateTime->setTimezone(new \DateTimeZone($dateArray[0]['TZID']));
            } elseif ($this->isValidCldrTimeZoneId($dateArray[0]['TZID'])) {
                $dateTime->setTimezone(new \DateTimeZone($this->isValidCldrTimeZoneId($dateArray[0]['TZID'], true)));
            } else {
                $dateTime->setTimezone(new \DateTimeZone($this->defaultTimeZone));
            }
        }

        if (is_null($format)) {
            $output = $dateTime;
        } else {
            if ($format === self::UNIX_FORMAT) {
                $output = $dateTime->getTimestamp();
            } else {
                $output = $dateTime->format($format);
            }
        }

        return $output;
    }
public function iCalDateWithTimeZone(array $event, $key, $format = self::DATE_TIME_FORMAT)
    {
        if (!isset($event[$key . '_array']) || !isset($event[$key])) {
            return false;
        }

        $dateArray = $event[$key . '_array'];

        if ($key === 'DURATION') {
            $duration = end($dateArray);
            $dateTime = $this->parseDuration($event['DTSTART'], $duration, null);
        } else {
            $dateTime = new \DateTime($dateArray[1], new \DateTimeZone(self::TIME_ZONE_UTC));
            $dateTime->setTimezone(new \DateTimeZone($this->calendarTimeZone()));
        }

        // Force time zone
        if (isset($dateArray[0]['TZID'])) {
            if ($this->isValidIanaTimeZoneId($dateArray[0]['TZID'])) {
                $dateTime->setTimezone(new \DateTimeZone($dateArray[0]['TZID']));
            } elseif ($this->isValidCldrTimeZoneId($dateArray[0]['TZID'])) {
                $dateTime->setTimezone(new \DateTimeZone($this->isValidCldrTimeZoneId($dateArray[0]['TZID'], true)));
            } else {
                $dateTime->setTimezone(new \DateTimeZone($this->defaultTimeZone));
            }
        }

        if (is_null($format)) {
            $output = $dateTime;
        } else {
            if ($format === self::UNIX_FORMAT) {
                $output = $dateTime->getTimestamp();
            } else {
                $output = $dateTime->format($format);
            }
        }

        return $output;
    }
public function iCalDateWithTimeZone ( array $ event , $ key , $ format = self :: DATE_TIME_FORMAT ) { if ( ! isset ( $ event [ $ key . '_array' ] ) || ! isset ( $ event [ $ key ] ) ) { return false ; } $ dateArray = $ event [ $ key . '_array' ] ; if ( $ key === 'DURATION' ) { $ duration = end ( $ dateArray ) ; $ dateTime = $ this -> parseDuration ( $ event [ 'DTSTART' ] , $ duration , null ) ; } else { $ dateTime = new \ DateTime ( $ dateArray [ 1 ] , new \ DateTimeZone ( self :: TIME_ZONE_UTC ) ) ; $ dateTime -> setTimezone ( new \ DateTimeZone ( $ this -> calendarTimeZone ( ) ) ) ; } // Force time zone if ( isset ( $ dateArray [ 0 ] [ 'TZID' ] ) ) { if ( $ this -> isValidIanaTimeZoneId ( $ dateArray [ 0 ] [ 'TZID' ] ) ) { $ dateTime -> setTimezone ( new \ DateTimeZone ( $ dateArray [ 0 ] [ 'TZID' ] ) ) ; } elseif ( $ this -> isValidCldrTimeZoneId ( $ dateArray [ 0 ] [ 'TZID' ] ) ) { $ dateTime -> setTimezone ( new \ DateTimeZone ( $ this -> isValidCldrTimeZoneId ( $ dateArray [ 0 ] [ 'TZID' ] , true ) ) ) ; } else { $ dateTime -> setTimezone ( new \ DateTimeZone ( $ this -> defaultTimeZone ) ) ; } } if ( is_null ( $ format ) ) { $ output = $ dateTime ; } else { if ( $ format === self :: UNIX_FORMAT ) { $ output = $ dateTime -> getTimestamp ( ) ; } else { $ output = $ dateTime -> format ( $ format ) ; } } return $ output ; }
Returns a date adapted to the calendar time zone depending on the event `TZID`

@param  array  $event
@param  string $key
@param  string $format
@return string|boolean
Returns a date adapted to the calendar time zone depending on the event TZID