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

\Nette\Utils\DateTime::fromParts(2021,12,28) causing crash #248

Closed
tprochazka opened this issue Feb 7, 2021 · 2 comments
Closed

\Nette\Utils\DateTime::fromParts(2021,12,28) causing crash #248

tprochazka opened this issue Feb 7, 2021 · 2 comments

Comments

@tprochazka
Copy link

tprochazka commented Feb 7, 2021

Nette version: 3.0.8
PHP: 7.2.11 (I did not test the newer version, but Nette has 7.2 as the minimum supported version)
Czech localization system and setlocale(LC_ALL, 'cs_CZ');

\Nette\Utils\DateTime::fromParts(2021,12,28)

End with this exception:
DateTime::__construct(): Failed to parse time string (2021-12-28 00:00:0,00000) at position 23 (0): Unexpected character

I tried to change line

$s = sprintf('%04d-%02d-%02d %02d:%02d:%02.5f', $year, $month, $day, $hour, $minute, $second);

to
$s = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hour, $minute, $second);

And it works now.

Do we need microseconds there, if biggest possible entered value is 1s?

@milo
Copy link
Member

milo commented Feb 7, 2021

Probably better fix is usage of %F which is non-locale aware.

@tprochazka
Copy link
Author

tprochazka commented Feb 7, 2021

Yes. This will also work. So it is caused by , instead of .
But I tested it and adding .000000 brings no difference in the result.
It anyway ends with

Nette\Utils\DateTime
date: '2021-12-28 00:00:00.000000'
timezone_type: 3
timezone: 'Europe/Prague'

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

Successfully merging a pull request may close this issue.

2 participants