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

Getting max time fails #2580

Open
gogainda opened this issue Jan 26, 2022 · 1 comment
Open

Getting max time fails #2580

gogainda opened this issue Jan 26, 2022 · 1 comment
Assignees

Comments

@gogainda
Copy link
Contributor

ruby -e 'puts Time.at((2**64)-1)'

ruby 3:

584554051223-11-09 08:00:15 +0100

truffleruby fails with:

<internal:core> core/time.rb:303:in `at': TruffleRuby doesn't have a case for the org.truffleruby.core.time.TimeNodesFactory$TimeAtPrimitiveNodeFactory$TimeAtPrimitiveNodeGen node with values of type Class(org.truffleruby.core.klass.RubyClass) org.truffleruby.core.numeric.RubyBignum java.lang.Integer=0 (TypeError)
	from org.truffleruby.core.time.TimeNodesFactory$TimeAtPrimitiveNodeFactory$TimeAtPrimitiveNodeGen.executeAndSpecialize(TimeNodesFactory.java:733)
	from org.truffleruby.core.time.TimeNodesFactory$TimeAtPrimitiveNodeFactory$TimeAtPrimitiveNodeGen.execute(TimeNodesFactory.java:715)
	from org.truffleruby.language.control.IfElseNode.execute(IfElseNode.java:43)
	from org.truffleruby.language.control.IfElseNode.execute(IfElseNode.java:45)
	from org.truffleruby.language.control.IfNode.execute(IfNode.java:39)
	from org.truffleruby.language.locals.WriteLocalVariableNode.execute(WriteLocalVariableNode.java:32)
	from org.truffleruby.language.RubyNode.doExecuteVoid(RubyNode.java:63)
	from org.truffleruby.language.control.SequenceNode.execute(SequenceNode.java:33)
	from org.truffleruby.language.RubyMethodRootNode.execute(RubyMethodRootNode.java:58)
	from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:655)
	from -e:1:in `<main>'
@eregon
Copy link
Member

eregon commented Jan 26, 2022

Note that (2**64)-1 is not LONG_MAX, LONG_MAX is (2**63)-1.

With (2**63)-1 it also fails:

$ ruby -e 'puts Time.at((2**63)-1)'
<internal:core> core/time.rb:313:in `at': UNIX epoch + 9223372036854775807 seconds out of range for Time (java.time limitation) (RangeError)
	from -e:1:in `<main>'

And this is basically not fixable without a huge effort, yet I don't think it makes any sense in many applications to use a time 292 billion years in the future (we'll all be dead by then).

Also Time is for timestamps close to our days, for precise calendars far in the future or past, one should use DateTime:
https://docs.ruby-lang.org/en/3.1/DateTime.html#class-DateTime-label-When+should+you+use+DateTime+and+when+should+you+use+Time-3F

We should add a specialization so that the Bignum case fails the same way as a too large long.

Any test relying on this should be fixed to use a more sensible Time, or to use DateTime.

> DateTime.new 292277026596
=> #<DateTime: 292277026596-01-01T00:00:00+00:00 ((581465470j,0s,0n),+0s,2299161j)>
works fine on TruffleRuby

@eregon eregon self-assigned this Jan 26, 2022
graalvmbot pushed a commit that referenced this issue Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants