本文整理匯總了PHP中Nette\Utils\DateTime::getLastErrors方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateTime::getLastErrors方法的具體用法?PHP DateTime::getLastErrors怎麽用?PHP DateTime::getLastErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Utils\DateTime
的用法示例。
在下文中一共展示了DateTime::getLastErrors方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validateValue
/**
* @Todo Separate this method to some DateTime Utils class
*
* @param string $value
* @param string $pattern
* @return DateTime
* @throws DateTimeParseException
*/
private static function validateValue($value, $pattern)
{
$value = static::strip($value);
if (($parsed = DateTime::createFromFormat($pattern, $value)) === FALSE) {
throw new DateTimeParseException("Value does not match desired format: '{$pattern}'.");
}
$error = DateTime::getLastErrors();
if ($error['error_count'] > 0 || $error['warning_count'] > 0) {
throw new DateTimeParseException('Invalid date given. ' . 'Errors: ' . implode(', ', $error['errors']) . ' ' . 'Warnings: ' . implode(', ', $error['warnings']));
}
$strippedCrossCheckValue = static::strip($parsed->format($pattern));
if ($value !== $strippedCrossCheckValue) {
throw new DateTimeParseException("Invalid date given. Check value does not match original. ['{$strippedCrossCheckValue}' !== '{$value}']");
}
return $parsed;
}
示例2: createFromFormat
/**
* @param string $value
* @param string $pattern
* @return DateTime
* @throws DateTimeParseException
*/
protected function createFromFormat($value, $pattern)
{
$parsed = DateTime::createFromFormat($pattern, $value);
$errors = DateTime::getLastErrors();
if ($parsed === FALSE || $errors['error_count'] > 0 || $errors['warning_count'] > 0) {
$message = sprintf('Invalid date given. Errors: [%s], Warnings: [%s]', implode(', ', $errors['errors']), implode(', ', $errors['warnings']));
throw new DateTimeParseException(sprintf("Value does not match desired format: '%s'. Error message: '%s'", $pattern, $message));
}
return $parsed;
}