Convert a .NET custom date format string to it's PHP equivalent.

@param string $dotnetFormat

@return string

@throws UnsupportedFormatException
501377
public function convert($dotnetFormat)
    {
        // get string literals and replace with a placeholder to make specifier matching simpler
        $stringLiterals = [];

        $callback = function ($matches) use (&$stringLiterals) {
            $stringLiterals[] = reset($matches);
            return '%s';
        };

        $dotnetFormatPlaceholders = preg_replace_callback(
            $this->getPatternStringLiteralsDotNet(),
            $callback,
            $dotnetFormat
        );

        // match .NET specifiers
        $callback = function ($matches) use ($dotnetFormat) {
            $specifier = reset($matches);

            if (!isset($this->dotnetToPhp[$specifier])) {
                throw new UnsupportedFormatException($dotnetFormat, $specifier);
            }

            return $this->dotnetToPhp[$specifier];
        };

        $phpFormatPlaceholders = preg_replace_callback(
            $this->getPatternSpecifiersDotnet(),
            $callback,
            $dotnetFormatPlaceholders
        );

        // remove slashes from literals
        $callback = function ($value) {
            if ($value == '\\') {
                // don't remove single slashes - these are literal slashes
                return $value;
            }

            // slashes within quotes are literal slashes
            if (preg_match('/^["\'].+["\']$/', $value)) {
                return $value;
            }

            $value = stripslashes($value);

            return $value;
        };

        $stringLiterals = array_map($callback, $stringLiterals);

        // remove quotes from literals
        $stringLiterals = str_replace(['"', '\''], '', $stringLiterals);

        // escape any PHP specifier characters that appear in the string literals
        $callback = function ($matches) {
            $match = reset($matches);
            return '\\' . $match;
        };

        $stringLiterals = preg_replace_callback($this->getPatternSpecifiersPhp(), $callback, $stringLiterals);

        // replace placeholders with string literals
        return vsprintf($phpFormatPlaceholders, $stringLiterals);
    }
372607
public static function formatDate($format, $timestamp)
    {
        static $datesPatterns = null;
        static $timesPatterns = null;

        if ($datesPatterns === null || $timesPatterns === null) {
            $datesPatterns = "/\b(" . implode('|', array_keys(static::$_map['date'])) . ")\b(?![^']*'(?:(?:[^']*'){2})*[^']*$)/i";
            $timesPatterns = "/\b(" . implode('|', array_keys(static::$_map['time'])) . ")\b(?![^']*'(?:(?:[^']*'){2})*[^']*$)/i";
        }

        // normalize formats
        $result = preg_replace_callback($datesPatterns, function ($matches) use ($timestamp) {
            return date(static::$_map['date'][$matches[1]], $timestamp);
        }, trim($format));

        $result = preg_replace_callback($timesPatterns, function ($matches) use ($timestamp) {
            return date(static::$_map['time'][$matches[1]], $timestamp);
        }, $result);

        return str_replace('\'', '', $result);
    }
1193124
public static function fromFormat(string $format, string $timeString) : TimeOfDay
    {
        return self::fromNative(\DateTimeImmutable::createFromFormat($format, $timeString));
    }
102636
public function getDateFormat()
    {
        $formatter = new IntlDateFormatter(
            $this->getLocale(),
            IntlDateFormatter::MEDIUM,
            IntlDateFormatter::NONE
        );
        $format = $formatter->getPattern();

        $this->extend('updateDateFormat', $format);

        return $format;
    }
322811
public static function formatPhpDateToJsDate($php_format)
    {
        $SYMBOLS_MATCHING = [
            // Day
            'd' => 'DD',
            'D' => 'D',
            'j' => 'd',
            'l' => 'DD',
            'N' => '',
            'S' => '',
            'w' => '',
            'z' => 'o',
            // Week
            'W' => '',
            // Month
            'F' => 'MM',
            'm' => 'MM',
            'M' => 'M',
            'n' => 'm',
            't' => '',
            // Year
            'L' => '',
            'o' => '',
            'Y' => 'YYYY',
            'y' => 'y',
            // Time
            'a' => '',
            'A' => '',
            'B' => '',
            'g' => '',
            'G' => '',
            'h' => '',
            'H' => 'HH',
            'i' => 'mm',
            's' => '',
            'u' => ''
        ];

        $replacement = "";
        $escaping    = false;

        for ($i = 0; $i < strlen($php_format); $i++) {
            $char = $php_format [$i];
            if ($char === '\\')            // PHP date format escaping character
            {
                $i++;
                if ($escaping) {
                    $replacement .= $php_format [$i];
                } else {
                    $replacement .= '\'' . $php_format [$i];
                }
                $escaping = true;
            } else {
                if ($escaping) {
                    $replacement .= "'";
                    $escaping    = false;
                }
                if (isset ($SYMBOLS_MATCHING [$char])) {
                    $replacement .= $SYMBOLS_MATCHING [$char];
                } else {
                    $replacement .= $char;
                }
            }
        }
        return $replacement;
    }
734661
public static function formatDate($date)
    {
        $format = DateTime::ATOM;
        if ($date instanceof DateTime) {
            $d = $date->format($format);
        } elseif (is_numeric($date)) {
            $d = date($format, $date);
        } else {
            $d = (string) $date;
        }
        return $d;
    }
668362
public static function formatDate($date, $fromFormat='d-m-Y', $toFormat='Y-m-d')
    {   
        $dt = \DateTime::createFromFormat($fromFormat, $date);
        return !$dt ? null : $dt->format($toFormat);
    }
905167
public function getDateTimeFormat(string $format='Y-m-d H:i:s')
    {
        $this->setDateTimeZone()->setDateTime();

        return $this->dateTime->format($format);
    }
143062
private function convertFormat($time, $dateFormat)
    {
        if (!($time instanceof \DateTime)) {
            if (is_numeric($time)) {
                $transformer = new DateTimeToTimestampTransformer();
                $time = $transformer->reverseTransform($time);
            } else {
                $transformer = new DateTimeToStringTransformer(null, null, $dateFormat);
                $time = $transformer->reverseTransform($time);
            }
        }

        return $time;
    }
1368707
public static function getDateTimeFormattedEvent($varEvent, $blnSeparatedDateTime = true, $strFormat = '%s (%s)')
	{
		$objEvent = $varEvent;
		if (is_numeric($varEvent))
		{
			if (($objEvent = \CalendarEventsModel::findByPk($varEvent)) === null)
				return '';
		}

		$strDateTime = DateUtil::getFormattedDateTime($objEvent, $blnSeparatedDateTime);

		return sprintf($strFormat, $objEvent->title, $strDateTime);
	}
1258984
function getDateFormatString( $type, $pref ) {
		if ( !isset( $this->dateFormatStrings[$type][$pref] ) ) {
			if ( $pref == 'default' ) {
				$pref = $this->getDefaultDateFormat();
				$df = self::$dataCache->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
			} else {
				$df = self::$dataCache->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
				if ( is_null( $df ) ) {
					$pref = $this->getDefaultDateFormat();
					$df = self::$dataCache->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
				}
			}
			$this->dateFormatStrings[$type][$pref] = $df;
		}
		return $this->dateFormatStrings[$type][$pref];
	}
843637
public function getFormat(string $dateLength): string
    {
        // Oops, unknown length of date
        if (false === (new DateLength())->isCorrectType($dateLength)) {
            throw UnknownDateLengthException::createException($dateLength);
        }

        $format = '';

        switch ($dateLength) {
            case DateLength::DATE:
                $format = $this->dateFormat;

                break;
            case DateLength::DATETIME:
                $format = $this->dateTimeFormat;

                break;
            case DateLength::TIME:
                $format = $this->timeFormat;

                break;
        }

        return $format;
    }
657034
public static function timeFormat($timestamp = null, $format = 'Y-m-d H:i:s')
    {
        if ($timestamp === null) {
            $timestamp = time();
        } elseif (empty($timestamp)) {
            return null;
        } else {
            $timestamp = intval($timestamp);
        }
        if (strncmp($format, 'php:', 4) === 0) {
            $format = substr($format, 4);
        }
        
        return date($format, $timestamp);
    }
717796
public function format($format = 'date', $timestamp = null)
    {
        $timestamp = is_numeric($timestamp) ? '@'.intval($timestamp) : $timestamp;
        $timestamp = is_a($timestamp, 'DateTime') ? $timestamp : new DateTime($timestamp);

        $key = $this->getTranslationKey("date.formats.{$format}");
        $format = $this->translator->has($key) ? $this->translator->get($key) : null;

        if (is_null($format)) {
            throw new \InvalidArgumentException('Date format is invalid or does not exists in current language');
        }

        return strftime($format, $timestamp->format('U'));
    }
741735
public function setPublishDate($dateFormat = 'F d, Y')
	{
		$name_separate = explode('-', $this->getFileName(), 4);
		$originalDate = $name_separate[0] . '-' . $name_separate[1] . '-' .$name_separate[2];
		$this->publishDate = date($dateFormat, strtotime($originalDate));
	}
865093
private function formatTimeAsString(\DateTimeInterface $dateTime, $ns)
    {
        $dateTime = $dateTime->setTimeZone(new \DateTimeZone('UTC'));
        if ($ns === null) {
            return $dateTime->format(Timestamp::FORMAT);
        } else {
            $ns = (string) $ns;
            $ns = str_pad($ns, 9, '0', STR_PAD_LEFT);
            if (substr($ns, 6, 3) === '000') {
                $ns = substr($ns, 0, 6);
            }

            return sprintf(
                $dateTime->format(Timestamp::FORMAT_INTERPOLATE),
                $ns
            );
        }
    }
813138
public static function isSupportedFormatAndVersion ($xmlData) {
        $xmlreader = new \XMLReader();
        $xmlreader->XML($xmlData);

        return self::isValidFormatAndVersion($xmlreader);

    }