acf_split_date_time()ACF 5.3.8

acf_split_date_time

This function will split a format string into seperate date and time

@type    function

Хуков нет.

Возвращает

$formats. (array)

Использование

acf_split_date_time( $date_time );
$date_time **
-
По умолчанию: ''

Список изменений

С версии 5.3.8 Введена.

Код acf_split_date_time() ACF 5.10.2

function acf_split_date_time( $date_time = '' ) {

	// vars
	$php_date = acf_get_setting( 'php_to_js_date_formats' );
	$php_time = acf_get_setting( 'php_to_js_time_formats' );
	$chars    = str_split( $date_time );
	$type     = 'date';

	// default
	$data = array(
		'date' => '',
		'time' => '',
	);

	// loop
	foreach ( $chars as $i => $c ) {

		// find type
		// - allow misc characters to append to previous type
		if ( isset( $php_date[ $c ] ) ) {

			$type = 'date';

		} elseif ( isset( $php_time[ $c ] ) ) {

			$type = 'time';

		}

		// append char
		$data[ $type ] .= $c;

	}

	// trim
	$data['date'] = trim( $data['date'] );
	$data['time'] = trim( $data['time'] );

	// return
	return $data;

}