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

Unix timestamp not detected and throw an error #9

Closed
magicoli opened this issue Sep 7, 2022 · 0 comments
Closed

Unix timestamp not detected and throw an error #9

magicoli opened this issue Sep 7, 2022 · 0 comments

Comments

@magicoli
Copy link
Contributor

magicoli commented Sep 7, 2022

When passing a unix timestamp, the formatter tries to format it as a string and throw an error:

Uncaught Exception: Failed to parse time string (1671062400) at position 8 (0): Unexpected character in (...)vendor/openpsa/ranger/src/Ranger.php:243

The issue is that prepare_date() first checks if the input is a string (although, technically, an integer is also a string).

I solved it by replacing

        if (is_string($input)) {
            return new Datetime($input);
        }
        if (is_int($input)) {
            $date = new Datetime;
            $date->setTimestamp($input);
            return $date;
        }

with

        if (is_numeric($input)) {
            $date = new Datetime;
            $date->setTimestamp($input);
            return $date;
        }
        if (is_string($input)) {
            return new Datetime($input);
        }

I also replaced is_int() by is_numeric(), which is the recommended way to distinguish a number from a string, is_int() failing in some cases.

@magicoli magicoli changed the title Unix timestamp not detected an throw an error Unix timestamp not detected and throw an error Sep 7, 2022
@flack flack closed this as completed in 7bd8885 Sep 8, 2022
flack added a commit that referenced this issue Sep 8, 2022
Fix #9 Unix timestamp string not detected
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

1 participant