Skip to content

Negative nsec on Time initialisation #5438

@sebastianguarin

Description

@sebastianguarin

Environment

  • jRuby 9.2.3.0
  • Rails 4.2.9
  • Darwin 14.5.0 Darwin Kernel Version 14.5.0: Sun Jun 4 21:40:08 PDT 2017; root:xnu-2782.70.3~1/RELEASE_X86_64 x86_64
    TimeZone AEDT

Expected Behavior

  • Keep nano seconds that were given on the args
pry(main)> ::Time.utc(1969, 11, 12, 13, 18, 57, 404240).nsec
=> 404240000

Actual Behavior

jruby-9.2.3.0 :001 > ::Time.utc(1969, 11, 12, 13, 18, 57, 404240).nsec
 => -595760000

I got this issue while running some specs that generate random past dates, which are failing due https://github.com/jruby/jruby/pull/5371/files

(49.years + 1.days).ago

Traceback (most recent call last):
       16: from /Users/sebastianm/.rvm/rubies/jruby-9.2.3.0/lib/ruby/gems/shared/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'
       15: from org/jruby/RubyKernel.java:1181:in `catch'
       14: from org/jruby/RubyKernel.java:1181:in `catch'
       13: from org/jruby/RubyKernel.java:1415:in `loop'
       12: from org/jruby/RubyKernel.java:1043:in `eval'
       11: from (irb):6:in `evaluate'
       10: from /Users/sebastianm/.rvm/rubies/jruby-9.2.3.0/lib/ruby/gems/shared/gems/activesupport-4.2.10/lib/active_support/duration.rb:109:in `ago'
        9: from /Users/sebastianm/.rvm/rubies/jruby-9.2.3.0/lib/ruby/gems/shared/gems/activesupport-4.2.10/lib/active_support/duration.rb:134:in `sum'
        8: from org/jruby/RubyEnumerable.java:1047:in `inject'
        7: from org/jruby/RubyArray.java:1789:in `each'
        6: from /Users/sebastianm/.rvm/rubies/jruby-9.2.3.0/lib/ruby/gems/shared/gems/activesupport-4.2.10/lib/active_support/duration.rb:139:in `block in sum'
        5: from /Users/sebastianm/.rvm/rubies/jruby-9.2.3.0/lib/ruby/gems/shared/gems/activesupport-4.2.10/lib/active_support/time_with_zone.rb:294:in `advance'
        4: from /Users/sebastianm/.rvm/rubies/jruby-9.2.3.0/lib/ruby/gems/shared/gems/activesupport-4.2.10/lib/active_support/time_with_zone.rb:383:in `method_missing'
        3: from /Users/sebastianm/.rvm/rubies/jruby-9.2.3.0/lib/ruby/gems/shared/gems/activesupport-4.2.10/lib/active_support/core_ext/time/calculations.rb:135:in `advance'
        2: from /Users/sebastianm/.rvm/rubies/jruby-9.2.3.0/lib/ruby/gems/shared/gems/activesupport-4.2.10/lib/active_support/core_ext/time/calculations.rb:102:in `change'
        1: from org/jruby/RubyTime.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions