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

feat(UNIX_TIMESTAMP): add basic support for UNIX_TIMESTAMP function #32

Merged
merged 1 commit into from
Apr 12, 2022

Conversation

rtm-ctrlz
Copy link
Contributor

Added basic support for UNIX_TIMESTAMP() function:

  • without arguments: returns current timestamp
  • with single argument: transforms string representation of date/datetime to timestamp

Things could be done:

  • add some checks for invalid values/formats
  • add support for timezones
  • support for floating point type of return value
    mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.012');
        -> 1447431619.012
    

Docs for function - MySQL 8.0 Reference Manual

@sergiosalvatore
Copy link
Contributor

Hi -- thanks for the submission! Would you be able to address the issues Psalm flagged?

@rtm-ctrlz
Copy link
Contributor Author

rtm-ctrlz commented Mar 29, 2022

@sergiosalvatore, I'm not sure that I know proper way to do it.

After $column = Evaluator::evaluate($conn, $scope, $args[0], $row, $result); line variable $column may have almost any type, so I see some ways:

  • convert to string and let strtotime handle it;
  • add check for type and pass only string, otherwise return NULL like original function do.

Also I'll add some things to this PR a bit later:

  • fix for a typo (exception message)
  • convertion false -> null for strtotime

@rtm-ctrlz rtm-ctrlz closed this Mar 29, 2022
@rtm-ctrlz
Copy link
Contributor Author

Sorry, misclicked close button

@rtm-ctrlz
Copy link
Contributor Author

@sergiosalvatore , have look, things done:

  • fixed couple typos
  • fixed psalm issue
  • fixed return type to int | null , like original function
  • with invalid values (when strtotime returns false) function will return NULL, like original function
  • "refactored" from if's to switch for argument count check

@rtm-ctrlz
Copy link
Contributor Author

bump ;)

@muglug muglug merged commit 3be4c68 into vimeo:master Apr 12, 2022
@muglug
Copy link
Collaborator

muglug commented Apr 12, 2022

Thanks!

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