Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date does not work with variable precision of microseconds #293

Open
bendavies opened this issue Dec 6, 2019 · 1 comment
Open

date does not work with variable precision of microseconds #293

bendavies opened this issue Dec 6, 2019 · 1 comment

Comments

@bendavies
Copy link

bendavies commented Dec 6, 2019

Hi,

Assertion::date('2019-10-31 14:08:46.429', 'Y-m-d H:i:s.u') will not work formatting the resulting date will not be the same as the input string:

if (false === $dateTime || $value !== $dateTime->format($format)) {

2019-10-31 14:08:46.429 will be formatted as 2019-10-31 14:08:46.429000.
These dates are equivalent.

A different method is needed to compare the dates.

A better check would be

$errors = \DateTime::getLastErrors();

if (0 < $errors['warning_count'] || 0 < $errors['error_count']) {
 //invalid
}
@mvanduijker
Copy link

mvanduijker commented Aug 3, 2023

Same issue with DATE_RFC3339 format.

If input is '2021-10-20T10:00:00Z' which is valid, but the output of $dateTime->format will be '2021-10-20T10:00:00+00:00' so the assertion fails unexpectedly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants