本文整理汇总了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;
}