Split timezone by its parts

@param  string $value
@return array[time, zone]
196334
protected function splitTime($value)
    {
        //guard
        if (empty($value)) {
            return array(null, null);
        }

        //try to find zone, z == UTC
        $partsZ = explode('z', $value);
        $partsM = explode('-', $value);
        $partsP = explode('+', $value);
        if ($this->laxZone) {
            //trim the time part cus there may be a space
            $partsZ[0] = rtrim($partsZ[0]);
            $partsM[0] = rtrim($partsM[0]);
            $partsP[0] = rtrim($partsP[0]);
        }
        //guard
        if (count($partsZ) == 0 && count($partsM) == 0 && count($partsP) == 0) {
            return array(null, null);
        }
        //UTC timezone stated
        if (count($partsZ) == 2 && empty($partsZ[1])) {
            $this->zonepartFound = true;
            return array($partsZ[0], $this->getUTCTimezone());
        }

        //minus timezone stated
        if (count($partsM) == 2) {
            $this->zonepartFound = true;
            return array($partsM[0], "-{$partsM[1]}");
        }

        //plus timezone stated
        if (count($partsP) == 2) {
            $this->zonepartFound = true;
            return array($partsP[0], "+{$partsP[1]}");
        }

        //no zone found
        return array((empty($value) ? null : $value), null);
    }
720412
public function filter($value)
    {
        if (! is_array($value)) {
            // nothing to do
            return $value;
        }

        // Convert the date to a specific format
        if ($this->isNullOnEmpty()
            && array_reduce($value, __CLASS__ . '::reduce', false)
        ) {
            return;
        }

        if ($this->isNullOnAllEmpty()
            && array_reduce($value, __CLASS__ . '::reduce', true)
        ) {
            return;
        }

        $this->filterable($value);

        ksort($value);
        $value = vsprintf($this->format, $value);

        return $value;
    }
1134925
public static function toDateTime($value, DateTimeZone $dtz) : DateTime
    {
        // TODO : Figure out where to move. Can vary for different source objects
        $format = 'Y-m-d H:i:s';

        if (is_string($value)) {
            $val = strtotime($value);
            if (false === $val) {
                throw new InvalidArgumentException(sprintf('Unsupported datetime string provided: %s', $value));
            }

            return new DateTime(date($format, $val), $dtz);
        }

        if ($value instanceof Time) {
            $value = $value->format($format);

            return new DateTime($value, $dtz);
        }

        if ($value instanceof DateTime) {
            return $value;
        }

        throw new InvalidArgumentException("Type [" . gettype($value) . "] is not supported for date/time");
    }
273087
public static function getDateTime($value) : DateTimeInterface
    {
        $datetime  = false;
        $exception = null;

        if ($value instanceof DateTimeInterface) {
            return $value;
        } elseif ($value instanceof UTCDateTime) {
            $datetime = $value->toDateTime();
            $datetime->setTimezone(new DateTimeZone(date_default_timezone_get()));
        } elseif (is_numeric($value)) {
            $value         = (float) $value;
            $seconds       = (int) $value;
            $microseconds  = abs(round($value - $seconds, 6));
            $microseconds *= 1000000;

            $datetime = static::craftDateTime($seconds, (int) $microseconds);
        } elseif (is_string($value)) {
            try {
                $datetime = new DateTime($value);
            } catch (Throwable $e) {
                $exception = $e;
            }
        }

        if ($datetime === false) {
            throw new InvalidArgumentException(sprintf('Could not convert %s to a date value', is_scalar($value) ? '"' . $value . '"' : gettype($value)), 0, $exception);
        }

        return $datetime;
    }
363042
private static function parseTimeZone(string $timeZone): array
    {
        $parts = explode('/', $timeZone);

        if (count($parts) > 2) {
            return [$parts[0], $parts[1] . ' / ' . $parts[2]];
        }

        if (count($parts) > 1) {
            return [$parts[0], $parts[1]];
        }

        return ['Other', $parts[0]];
    }
719584
protected function asDateTime($value)
    {
        if ($value instanceof Carbon) {
            return $value->timezone($this->getTimezone());
        }

        if ($value instanceof \DateTimeInterface) {
            return new Carbon(
                $value->format('Y-m-d H:i:s.u'),
                $value->getTimezone()
            );
        }

        if (is_numeric($value)) {
            return Carbon::createFromTimestamp($value)->timezone($this->getTimezone());
        }

        return Carbon::createFromFormat($this->getFormat(), $value);
    }
1191726
public function formatDatetime($value)
	{
		return $this->getLocale()->dateFormatter->formatDateTime($this->normalizeDateValue($value), $this->dateFormat, $this->timeFormat);
	}
819719
public function filter($value)
    {
        if (!is_scalar($value) && !is_array($value)) {
            return $value;
        }

        if (StringUtils::hasPcreUnicodeSupport()) {
            $pattern     = ['#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#', '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#'];
            $replacement = [$this->separator . '\1', $this->separator . '\1'];
        } else {
            $pattern     = ['#(?<=(?:[A-Z]))([A-Z]+)([A-Z][a-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'];
            $replacement = ['\1' . $this->separator . '\2', $this->separator . '\1'];
        }

        return preg_replace($pattern, $replacement, $value);
    }
990936
public function filter($value)
    {
        if ($value instanceof \DateTime) {
            return $value;
        }
        
        try {
            $datetime = new \DateTime($value);
        } catch (\Exception $exception) {
            return false;
        }
        
        return $datetime;
    }
669176
public function formatDate($value)
	{
		return $this->getLocale()->dateFormatter->formatDateTime($this->normalizeDateValue($value), $this->dateFormat, null);
	}
102091
protected function timestamp_to_date_array($value) {
        $calendartype = \core_calendar\type_factory::get_calendar_instance();
        $currentdate = $calendartype->timestamp_to_date_array($value, $this->_options['timezone']);
        return array(
            'minute' => $currentdate['minutes'],
            'hour' => $currentdate['hours'],
            'day' => $currentdate['mday'],
            'month' => $currentdate['mon'],
            'year' => $currentdate['year']);
    }
1099170
protected function _deconstructDate($value, $options)
    {
        if ($value === '' || $value === null) {
            return [
                'year' => '', 'month' => '', 'day' => '',
                'hour' => '', 'minute' => '', 'second' => '',
                'meridian' => '',
            ];
        }
        try {
            if (is_string($value) && !is_numeric($value)) {
                $date = new DateTime($value);
            } elseif (is_bool($value)) {
                $date = new DateTime();
            } elseif (is_int($value) || is_numeric($value)) {
                $date = new DateTime('@' . $value);
            } elseif (is_array($value)) {
                $dateArray = [
                    'year' => '', 'month' => '', 'day' => '',
                    'hour' => '', 'minute' => '', 'second' => '',
                    'meridian' => '',
                ];
                $validDate = false;
                foreach ($dateArray as $key => $dateValue) {
                    $exists = isset($value[$key]);
                    if ($exists) {
                        $validDate = true;
                    }
                    if ($exists && $value[$key] !== '') {
                        $dateArray[$key] = str_pad($value[$key], 2, '0', STR_PAD_LEFT);
                    }
                }
                if ($validDate) {
                    if (!isset($dateArray['second'])) {
                        $dateArray['second'] = 0;
                    }
                    if (!empty($value['meridian'])) {
                        $isAm = strtolower($dateArray['meridian']) === 'am';
                        $dateArray['hour'] = $isAm ? $dateArray['hour'] : $dateArray['hour'] + 12;
                    }
                    if (!empty($dateArray['minute']) && isset($options['minute']['interval'])) {
                        $dateArray['minute'] += $this->_adjustValue($dateArray['minute'], $options['minute']);
                        $dateArray['minute'] = str_pad((string)$dateArray['minute'], 2, '0', STR_PAD_LEFT);
                    }

                    return $dateArray;
                }

                $date = new DateTime();
            } else {
                /* @var \DateTime $value */
                $date = clone $value;
            }
        } catch (Exception $e) {
            $date = new DateTime();
        }

        if (isset($options['minute']['interval'])) {
            $change = $this->_adjustValue((int)$date->format('i'), $options['minute']);
            $date->modify($change > 0 ? "+$change minutes" : "$change minutes");
        }

        return [
            'year' => $date->format('Y'),
            'month' => $date->format('m'),
            'day' => $date->format('d'),
            'hour' => $date->format('H'),
            'minute' => $date->format('i'),
            'second' => $date->format('s'),
            'meridian' => $date->format('a'),
        ];
    }
171929
private static function transformValue($value)
    {
        if (is_null($value)) {
            return $value;
        }

        if ($value instanceof PrimalValued) {
            $value = $value->toPrimitive();
        } elseif ($value instanceof Arrayable) {
            $value = $value->toArray();
            if (empty($value)) {
                $value = null;
            }
        } elseif (is_array($value)) {
            $value = array_map(function ($arrValue) {
                return self::transformValue($arrValue);
            }, $value);
        } elseif ($value instanceof \DateTimeZone) {
            $value = $value->getName();
        } elseif ($value instanceof Carbon) {
            $value = $value->toRfc3339String();
        }

        return $value;
    }
1261242
public function formatTime($value)
    {
        return \MUtil_Html::create(
                'span',
                ' ',
                // array('class' => 'time'),
                // $this->_timeImg,
                \MUtil_Date::format($value, 'HH:mm ' . \Zend_Date::WEEKDAY_SHORT, $this->_dateStorageFormat)
                );
    }
476636
protected static function formatValue($value)
    {
        if ($value instanceof \DateTime) {
            $value = $value->format(\DateTime::ISO8601);
        } elseif (\is_bool($value)) {
            $value = $value ? 'True' : 'False';
        } elseif (\is_array($value) || $value instanceof \IteratorAggregate) {
            $itValue = $value instanceof \IteratorAggregate ? $value->getIterator() : $value;
            $value = [];
            foreach ($itValue as $key => $arrayValue) {
                $value[$key] = static::formatValue($arrayValue);
            }
            $value = implode("\n  ", $value);
        }

        return (string) $value;
    }
997888
public static function niceDatetime($value, array $options = []) {
		if (!isset($value)) return '';
		try {
			$server_timezone = self::$options['server_timezone_code'] ?? Application::get('php.date.timezone');
			$object = new DateTime($value, new DateTimeZone($server_timezone));
			// change timezone
			if (empty($options['skip_user_timezone'])) {
				$object->setTimezone(new DateTimeZone(self::$options['timezone_code']));
			}
			$value = i18n(null, $object->format('F')) . ' ' . $object->format('j') . self::$symbol_comma . ' ' . $object->format('Y');
			// process time
			$hours = intval($object->format('G'));
			$minutes = intval($object->format('i'));
			$seconds = intval($object->format('s'));
			// if we have time
			if (!($hours == 0 && $minutes == 0 && $seconds == 0)) {
				$timeformat = self::getDateFormat('time');
				$am_pm = stripos($timeformat, 'a') !== false;
				$timeformat = str_ireplace(['a', ' '], '', $timeformat);
				$time = $object->format($timeformat);
				$time = trim2($time, ':00$', '');
				$time = trim2($time, ':00$', '');
				if (!empty($time)) {
					$value.= ' ' . $time;
					if ($am_pm) {
						$value.= ' ' . str_ireplace(['am', 'pm'], [i18n(null, 'am', ['skip_i_symbol' => true]), i18n(null, 'pm', ['skip_i_symbol' => true])], $object->format('a'));
					}
				}
			}
		} catch (Exception $e) {
			// on exception we return as is
		}
		return $value;
	}
490700
public function filter($value) {
        if($value === null)
            return null;

        try {
            $sourceDT = new DateTime($value);
            $targetTZ = new DateTimeZone($this->options["timezone"] ? $this->options["timezone"] : date_default_timezone_get());
            $targetDT = $sourceDT;
            $targetDT->setTimeZone($targetTZ);

            return $targetDT->format($this->options["format"]);
        }
        catch(Exception $e) {
            return false;
        }
    }