Skip to content

Time.new gives unexpected value #8860

@azimux

Description

@azimux

This is probably a duplicate as I see other date/time parsing related issues, but filing it anyways just in case

Environment Information

  • jruby 10.0.0.1 (3.4.2) 2025-05-07 79cf1e4 Java HotSpot(TM) 64-Bit Server VM 24.0.1+9-30 on 24.0.1+9-30 +indy +jit [x86_64-linux]
  • No command line flags passed in or relevant env vars set
  • Linux6.12.27-amd64 break script engine #1 SMP PREEMPT_DYNAMIC Debian 6.12.27-1 (2025-05-06) x86_64 GNU/Linux

Actual Behavior

The following specs:

        let(:value) { { year: "2020", month: 1, day: 2, hours: 3, minutes: 4, seconds: 5, zone: "-0700" } }

        it { is_expected.to eq(Time.new(2020, 1, 2, 3, 4, 5, in: "-0700")) }

and

      let(:value) { "2020-01-02 03:04:05.500 -1200" }

      it { is_expected.to eq(Time.new(2020, 1, 2, 3, 4, 5.5, in: "-12:00")) } 

result in:

     Failure/Error: it { is_expected.to eq(Time.new(2020, 1, 2, 3, 4, 5, in: "-0700")) }
     
       expected: 2020-01-02 03:04:00.000000000 -0700
            got: 2020-01-02 03:04:05.000000000 -0700
     # ./spec/builtin_types/datetime_spec.rb:33:in 'block in <main>'

and

     Failure/Error: it { is_expected.to eq(Time.new(2020, 1, 2, 3, 4, 5.5, in: "-12:00")) }
     
       expected: 2020-01-02 03:04:00.000000000 -1200
            got: 2020-01-02 03:04:05.500000000 -1200

Expected Behavior

In MRI, these specs pass.

To reproduce

I can actually reproduce this locally in IRB with the following:

irb(main):001> Time.new(2020, 1, 2, 3, 4, 5, in: "-0700")
=> 2020-01-02 03:04:00 -0700
irb(main):002> 

Looks like the seconds are coming out as 0 even though a 5 was passed in.

I could give a more complicated way of reproducing if needed involving cloning/checking out a branch and running rspec. Just let me know!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions