wc_rest_prepare_date_response()WC 2.6.0

Parses and formats a date for ISO8601/RFC3339.

Required WP 4.4 or later. See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/

Хуков нет.

Возвращает

Строку|null. ISO8601/RFC3339 formatted datetime.

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

wc_rest_prepare_date_response( $date, $utc );
$date(строка|null|WC_DateTime) (обязательный)
Date.
$utc(true|false)
Send false to get local/offset time.
По умолчанию: true

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

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

Код wc_rest_prepare_date_response() WC 8.7.0

function wc_rest_prepare_date_response( $date, $utc = true ) {
	if ( is_numeric( $date ) ) {
		$date = new WC_DateTime( "@$date", new DateTimeZone( 'UTC' ) );
		$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
	} elseif ( is_string( $date ) ) {
		$date = new WC_DateTime( $date, new DateTimeZone( 'UTC' ) );
		$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
	}

	if ( ! is_a( $date, 'WC_DateTime' ) ) {
		return null;
	}

	// Get timestamp before changing timezone to UTC.
	return gmdate( 'Y-m-d\TH:i:s', $utc ? $date->getTimestamp() : $date->getOffsetTimestamp() );
}