classes/fields/datetime.php
public function convert_format( $source_format, $args = array() ) {

		// @todo Improve source/target logic.
		$args = array_merge(
			array(
				'source' => 'php',
			// 'jquery_ui' for reverse.
			), $args
		);

		// Keep keys and values sorted by string length.
		$symbols = array(
			// Day
			'd' => 'dd',
			'l' => 'DD',
			'D' => 'D',
			'j' => 'd',
			'N' => '',
			'S' => '',
			'w' => '',
			'z' => 'o',
			// Week
			'W' => '',
			// Month
			'F' => 'MM',
			'm' => 'mm',
			'M' => 'M',
			'n' => 'm',
			't' => '',
			// Year
			'L' => '',
			'o' => '',
			'Y' => 'yy',
			'y' => 'y',
			// AM/PM
			'a' => 'tt',
			'A' => 'TT',
			// Swatch internet time (not supported)
			'B' => '',
			// Hour
			'h' => 'hh',
			'H' => 'HH',
			'g' => 'h',
			'G' => 'H',
			// Minute
			'i' => 'mm',
			// Second
			's' => 'ss',
			// Microsecond
			'u' => 'c',
		);

		if ( version_compare( PHP_VERSION, '7.0.0' ) >= 0 ) {
			// Millisecond
			$symbols['v'] = 'l';
		}

		if ( 'jquery_ui' === $args['source'] ) {
			// Remove empty values.
			$symbols = array_filter( $symbols );
			$symbols = array_flip( $symbols );
		}

		$new_format = '';
		$escaping   = false;

		$source_format_length = strlen( $source_format );

		for ( $i = 0; $i < $source_format_length; $i ++ ) {
			$char = $source_format[ $i ];

			// PHP date format escaping character
			// @todo Do we want to support non-format characters?
			if ( '\\' === $char ) {
				$i ++;

				if ( $escaping ) {
					$new_format .= $source_format[ $i ];
				} else {
					$new_format .= '\'' . $source_format[ $i ];
				}

				$escaping = true;
			} else {
				if ( $escaping ) {
					$new_format .= "'";
					$escaping    = false;
				}

				$symbol_key = false;

				if ( isset( $source_format[ $i + 1 ] ) ) {
					$symbol_key = $char . $source_format[ $i + 1 ];
				}

				// Support 2 characters.
				if ( $symbol_key && isset( $symbols[ $symbol_key ] ) ) {
					$new_format .= $symbols[ $symbol_key ];

					$i ++;
				} elseif ( isset( $symbols[ $char ] ) ) {
					$new_format .= $symbols[ $char ];
				} else {
					$new_format .= $char;
				}
			}//end if
		}//end for

		return $new_format;
	}
public function convert_format( $source_format, $args = array() ) {

		// @todo Improve source/target logic.
		$args = array_merge(
			array(
				'source' => 'php',
			// 'jquery_ui' for reverse.
			), $args
		);

		// Keep keys and values sorted by string length.
		$symbols = array(
			// Day
			'd' => 'dd',
			'l' => 'DD',
			'D' => 'D',
			'j' => 'd',
			'N' => '',
			'S' => '',
			'w' => '',
			'z' => 'o',
			// Week
			'W' => '',
			// Month
			'F' => 'MM',
			'm' => 'mm',
			'M' => 'M',
			'n' => 'm',
			't' => '',
			// Year
			'L' => '',
			'o' => '',
			'Y' => 'yy',
			'y' => 'y',
			// AM/PM
			'a' => 'tt',
			'A' => 'TT',
			// Swatch internet time (not supported)
			'B' => '',
			// Hour
			'h' => 'hh',
			'H' => 'HH',
			'g' => 'h',
			'G' => 'H',
			// Minute
			'i' => 'mm',
			// Second
			's' => 'ss',
			// Microsecond
			'u' => 'c',
		);

		if ( version_compare( PHP_VERSION, '7.0.0' ) >= 0 ) {
			// Millisecond
			$symbols['v'] = 'l';
		}

		if ( 'jquery_ui' === $args['source'] ) {
			// Remove empty values.
			$symbols = array_filter( $symbols );
			$symbols = array_flip( $symbols );
		}

		$new_format = '';
		$escaping   = false;

		$source_format_length = strlen( $source_format );

		for ( $i = 0; $i < $source_format_length; $i ++ ) {
			$char = $source_format[ $i ];

			// PHP date format escaping character
			// @todo Do we want to support non-format characters?
			if ( '\\' === $char ) {
				$i ++;

				if ( $escaping ) {
					$new_format .= $source_format[ $i ];
				} else {
					$new_format .= '\'' . $source_format[ $i ];
				}

				$escaping = true;
			} else {
				if ( $escaping ) {
					$new_format .= "'";
					$escaping    = false;
				}

				$symbol_key = false;

				if ( isset( $source_format[ $i + 1 ] ) ) {
					$symbol_key = $char . $source_format[ $i + 1 ];
				}

				// Support 2 characters.
				if ( $symbol_key && isset( $symbols[ $symbol_key ] ) ) {
					$new_format .= $symbols[ $symbol_key ];

					$i ++;
				} elseif ( isset( $symbols[ $char ] ) ) {
					$new_format .= $symbols[ $char ];
				} else {
					$new_format .= $char;
				}
			}//end if
		}//end for

		return $new_format;
	}
public function convert_format ( $ source_format , $ args = array ( ) ) { // @todo Improve source/target logic. $ args = array_merge ( array ( 'source' => 'php' , // 'jquery_ui' for reverse. ) , $ args ) ; // Keep keys and values sorted by string length. $ symbols = array ( // Day 'd' => 'dd' , 'l' => 'DD' , 'D' => 'D' , 'j' => 'd' , 'N' => '' , 'S' => '' , 'w' => '' , 'z' => 'o' , // Week 'W' => '' , // Month 'F' => 'MM' , 'm' => 'mm' , 'M' => 'M' , 'n' => 'm' , 't' => '' , // Year 'L' => '' , 'o' => '' , 'Y' => 'yy' , 'y' => 'y' , // AM/PM 'a' => 'tt' , 'A' => 'TT' , // Swatch internet time (not supported) 'B' => '' , // Hour 'h' => 'hh' , 'H' => 'HH' , 'g' => 'h' , 'G' => 'H' , // Minute 'i' => 'mm' , // Second 's' => 'ss' , // Microsecond 'u' => 'c' , ) ; if ( version_compare ( PHP_VERSION , '7.0.0' ) >= 0 ) { // Millisecond $ symbols [ 'v' ] = 'l' ; } if ( 'jquery_ui' === $ args [ 'source' ] ) { // Remove empty values. $ symbols = array_filter ( $ symbols ) ; $ symbols = array_flip ( $ symbols ) ; } $ new_format = '' ; $ escaping = false ; $ source_format_length = strlen ( $ source_format ) ; for ( $ i = 0 ; $ i < $ source_format_length ; $ i ++ ) { $ char = $ source_format [ $ i ] ; // PHP date format escaping character // @todo Do we want to support non-format characters? if ( '\\' === $ char ) { $ i ++ ; if ( $ escaping ) { $ new_format .= $ source_format [ $ i ] ; } else { $ new_format .= '\'' . $ source_format [ $ i ] ; } $ escaping = true ; } else { if ( $ escaping ) { $ new_format .= "'" ; $ escaping = false ; } $ symbol_key = false ; if ( isset ( $ source_format [ $ i + 1 ] ) ) { $ symbol_key = $ char . $ source_format [ $ i + 1 ] ; } // Support 2 characters. if ( $ symbol_key && isset ( $ symbols [ $ symbol_key ] ) ) { $ new_format .= $ symbols [ $ symbol_key ] ; $ i ++ ; } elseif ( isset ( $ symbols [ $ char ] ) ) { $ new_format .= $ symbols [ $ char ] ; } else { $ new_format .= $ char ; } } //end if } //end for return $ new_format ; }
Matches each symbol of PHP date format standard with jQuery equivalent codeword.

@link   http://stackoverflow.com/questions/16702398/convert-a-php-date-format-to-a-jqueryui-datepicker-date-format
@link   https://api.jqueryui.com/datepicker/
@link   http://trentrichardson.com/examples/timepicker/

@since 2.7.0

@param  string $source_format Source format string.
@param  array  $args          Format arguments.

@return string
Matches each symbol of PHP date format standard with jQuery equivalent codeword .