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

Instant.toSeconds should return int #62

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

isaacl
Copy link
Member

@isaacl isaacl commented Sep 30, 2024

This is generally safe (for now), and should be included to be consistent with LocalDateTime.toSeconds, which is already an int.

Also add some doc.

This is generally safe (for now), and should be included to be
consistent with LocalDateTime.toSeconds, which is already an int.

Also add some doc.
*
* This uses a checked conversion, it will overflow and raise if the year is after 2038.
*/
def toSeconds: Int = Math.toIntExact(d.toEpochSecond(utc_))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use LocalDateTime, Instant to present sometime in the future, so this is not actually safe? I guess to make things more consistent, we should return Long here instead of return Int everywhere else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's not totally safe because even in 2024 we could theoretically construct a LocalDateTime or Instant that corresponds to year 2038. That's why it's a checked cast for the LocalDateTime and Instant extension methods but unchecked for nowSeconds

It's a little unclean but working with ints when ints suffice is worth it, for now imo. This won't come up as an issue in lila until 2036 or later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just recently changed the other method to Int, yes we could undo them and return long. But do we really need to? Idk

@ornicar
Copy link
Collaborator

ornicar commented Oct 1, 2024

I think it's ok for now.

Hi future me! Hope you're doing great.

@ornicar ornicar merged commit 72a58bd into lichess-org:master Oct 1, 2024
1 check passed
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 this pull request may close these issues.

3 participants