[GH-ISSUE #51] Return type of getTimestamp() #23

Closed
opened 2026-02-25 20:32:12 +03:00 by kerem · 2 comments
Owner

Originally created by @SebastianS90 on GitHub (Oct 17, 2016).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/51

The return type of getTimestamp is specified to be int.
But the value returned is the result from floor, and that is float (see documentation).

You even test that the value is a float.

Can we make that consistent, please?

  • Return int
    • Insert a cast to int in getTimestamp
    • Adjust the test to check is_int
  • Return float
    • Fix @return annotation in interface and class

I can do a pull request for either choice if you tell me which way to go. In my opinion, int is better here because the value is floored anyways and even a 32 bit signed integer for a unix timestamp divided by 30 will be enough for almost another 2000 years - and by that time everyone should have switched to a system aware of 64 bit integers 😄

Originally created by @SebastianS90 on GitHub (Oct 17, 2016). Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/51 The return type of `getTimestamp` is [specified](https://github.com/antonioribeiro/google2fa/blob/ac2b66265d5fda38ce097782d47089bc3366683d/src/Contracts/Google2FA.php#L20) to be `int`. But the value returned is the [result from floor](https://github.com/antonioribeiro/google2fa/blob/ac2b66265d5fda38ce097782d47089bc3366683d/src/Google2FA.php#L122), and that is `float` (see [documentation](http://php.net/manual/en/function.floor.php#refsect1-function.floor-returnvalues)). You even [test that the value is a float](https://github.com/antonioribeiro/google2fa/blob/ac2b66265d5fda38ce097782d47089bc3366683d/tests/spec/Google2FASpec.php#L102). Can we make that consistent, please? - Return `int` - Insert a cast to `int` in `getTimestamp` - Adjust the test to check `is_int` - Return `float` - Fix `@return` annotation in interface and class I can do a pull request for either choice if you tell me which way to go. In my opinion, `int` is better here because the value is floored anyways and even a 32 bit signed integer for a unix timestamp _divided by 30_ will be enough for almost another 2000 years - and by that time everyone should have switched to a system aware of 64 bit integers :smile:
kerem closed this issue 2026-02-25 20:32:12 +03:00
Author
Owner

@aik099 commented on GitHub (Oct 17, 2016):

👍 for adding (int) before returning value. Thanks to dynamic casting in PHP this was never a problem.

<!-- gh-comment-id:254311280 --> @aik099 commented on GitHub (Oct 17, 2016): 👍 for adding `(int)` before returning value. Thanks to dynamic casting in PHP this was never a problem.
Author
Owner

@antonioribeiro commented on GitHub (Jun 17, 2017):

Moved it all to (int).
Thank you!

<!-- gh-comment-id:309192870 --> @antonioribeiro commented on GitHub (Jun 17, 2017): Moved it all to (int). Thank you!
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/google2fa#23
No description provided.