Automattic\WooCommerce\Admin\Features\Fulfillments
Fulfillment::normalize_date_to_utc
Normalize a date input to a UTC 'Y-m-d H:i:s' string.
Bare MySQL-format strings are interpreted as site-local time (matching the convention of current_time('mysql')). Strings that include an explicit timezone designator (Z, numeric offset, or named zone) are respected as-is.
Метод класса: Fulfillment{}
Хуков нет.
Возвращает
string|null. UTC datetime string, or null for empty/invalid input.
Использование
// private - только в коде основоного (родительского) класса $result = $this->normalize_date_to_utc( ?string $date ): ?string;
- ?string $date(обязательный)
- .
Список изменений
| С версии 10.8.0 | Введена. |
Код Fulfillment::normalize_date_to_utc() Fulfillment::normalize date to utc WC 11.3.0
private function normalize_date_to_utc( ?string $date ): ?string {
$date = null === $date ? null : trim( $date );
if ( null === $date || '' === $date ) {
return null;
}
try {
// The second DateTimeZone is used only when the string has no explicit zone.
$datetime = new \DateTime( $date, wp_timezone() );
// DateTime silently normalizes invalid calendar dates (e.g. Feb 30 -> Mar 2);
// reject those so callers don't persist a different date than the user supplied.
$parse_errors = \DateTime::getLastErrors();
if ( false !== $parse_errors && ( $parse_errors['warning_count'] > 0 || $parse_errors['error_count'] > 0 ) ) {
return null;
}
$datetime->setTimezone( new \DateTimeZone( 'UTC' ) );
return $datetime->format( 'Y-m-d H:i:s' );
} catch ( \Exception $e ) {
return null;
}
}