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

Time can be initialized with negative nanoseconds #5370

Closed
til opened this Issue Oct 15, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@til
Copy link

til commented Oct 15, 2018

Environment

jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.181-b13 on 1.8.0_181-b13 [linux-x86_64]
Linux 4.18.12-arch1-1-ARCH #1 SMP PREEMPT Thu Oct 4 01:01:27 UTC 2018 x86_64 GNU/Linux

Expected Behavior

Initializing Time with a negative value for seconds should raise an error.

On MRI it does:

irb(main):001:0> Time.new(2018, 1, 1, 10, 30, -0.1)
Traceback (most recent call last):
        4: from /home/tils/.rubies/ruby-2.5.1/bin/irb:11:in `<main>'
        3: from (irb):1
        2: from (irb):1:in `new'
        1: from (irb):1:in `initialize'
ArgumentError (argument out of range)

On JRuby it does not, when only given fraction of a second:

irb(main):003:0> Time.new(2018, 1, 1, 10, 30, -0.1)
=> 2018-01-01 10:29:59 +0100

When the number is small enough, it will have negative nsec:

irb(main):011:0> Time.new(2018, 1, 1, 10, 30, -0.0009).nsec
=> -900000

which becomes a problem in very specific serializations, e.g. with Sequel and postgres-jdbc it produces this invalid timestamp representation:

[2] pry(main)> DB.literal(Time.new(2018, 1, 1, 10, 1, -0.0009))
=> "'2018-01-01 10:01:00.-00900+0000'"

Actual Behavior

Behave like MRI and always raise an ArgumentError when sec < 0.

headius added a commit to headius/jruby that referenced this issue Oct 15, 2018

headius added a commit to headius/jruby that referenced this issue Oct 15, 2018

headius added a commit to headius/jruby that referenced this issue Oct 15, 2018

@headius headius added this to the JRuby 9.2.1.0 milestone Oct 15, 2018

eregon added a commit to ruby/spec that referenced this issue Oct 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.