Skip to content

Specs for Time#gmtime/Time#utc are insufficient #1205

@herwinw

Description

@herwinw

These use a shared spec (time_gmtime) with tests like this:

it "converts self to UTC, modifying the receiver" do
  # Testing with America/Regina here because it doesn't have DST
  with_timezone("CST", -6) do
    t = Time.local(2007, 1, 9, 6, 0, 0)
    t.send(@method)
    t.should == Time.gm(2007, 1, 9, 12, 0, 0)
  end
end

It looks like the == (or <=>) method normalizes the time zones for comparison, although I could not find any reference to this in the specs or the documentation of the Time class.

If we alter the file gmtime_spec.rb to this:

describe "Time#gmtime" do
  it_behaves_like :time_gmtime, :itself
end

If we call it like this, we don't modify anything in the time object and this still passes most of these specs (the only failure is a spec for frozen input).

I guess we need to change two things:

  • Add extra validations in shared/gmtime.rb to check the time zone of the object (this could be done with Time#utc?, but there might be a way without introducing an additional dependency)
  • Validate the behaviour for Time comparison with time zones. Add this behaviour to the specs (and possible get it in the docs of Ruby)

I'm planning to take a look into this later this week, but if anybody feels inspired and want to tackle this: be my guest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions