krainboltgreene / time-lord

time-lord is a ruby gem that adds extra functionality to the time class.
MIT License
156 stars 19 forks source link

Bug? Looks like Rails internal time calculation DSL gets fucked up!? #11

Open kristianmandrup opened 11 years ago

kristianmandrup commented 11 years ago

I have written the timespan gem. After including time-lordweird things started to happen.

https://github.com/kristianmandrup/timespan/issues/2

Then I wrote this test:

require 'spec_helper'

# To test and make sure that none of the included gems or any core extensions of this gem fuck up the 
# normal date calculation/comparison etc functionality of Ruby and Rails ;)

describe 'Ensure system Time calculations still operate as the should!' do
  it 'should add Time + Time normally' do
    expect(1.days + 3.days).to eq 4.days
  end

  it 'should add Date + Time normally' do
    expect(Date.today + 3.days).to eq 3.days.from_now.to_date
  end
end

Removed time-lord, and then the tests passed again. You should look into this ;)

krainboltgreene commented 11 years ago

Could you gist in the failure message?

Although I'm not surprised. Time-lord handles time math a lot differently than Rails but has the same interfaces. Including time-lord in your rails application will overrwrite the ActiveSupport::TimeHelpers and use the new time math.

The best I can do is make sure all interfaces are covered so you're completely using new time-lord stuff.

Alternatively you can require: false in your Gemfile and only require parts of time-lord.

On Fri, Mar 29, 2013 at 5:06 AM, Kristian Mandrup notifications@github.comwrote:

I have written the timespan gem. After including time-lordweird things started to happen.

kristianmandrup/timespan#2https://github.com/kristianmandrup/timespan/issues/2

Then I wrote this test:

require 'spec_helper'

To test and make sure that none of the included gems or any core extensions of this gem fuck up the # normal date calculation/comparison etc functionality of Ruby and Rails ;)

describe 'Ensure system Time calculations still operate as the should!' do it 'should add Time + Time normally' do expect(1.days + 3.days).to eq 4.days end

it 'should add Date + Time normally' do expect(Date.today + 3.days).to eq 3.days.from_now.to_date endend

Removed time-lord, and then the tests passed again. You should look into this ;)

— Reply to this email directly or view it on GitHubhttps://github.com/krainboltgreene/time-lord/issues/11 .

Kurtis Rainbolt-Greene, Hacker Software Developer 612 S. Flower St. Los Angeles, CA, 90017

kristianmandrup commented 11 years ago

Here are some...

require 'spec_helper'

# without this, the tests below pass just fine
require 'time-lord'

# To test and make sure that none of the included gems or any core extensions of this gem fuck up the 
# normal date calculation/comparison etc functionality of Ruby and Rails ;)

describe 'Ensure system Time calculations still operate as the should!' do
  it 'should add Time + Time normally' do
    expect(1.days + 3.days).to eq 4.days
  end

  it 'should add Date + Time normally' do
    expect(Date.today + 3.days).to eq 3.days.from_now.to_date
  end
end

Removing the .to_date

  it 'should add Date + Time normally' do
    expect(Date.today + 3.days).to eq 3.days.from_now
  end
Ensure system Time calculations still operate as the should! should add Date + Time normally
     Failure/Error: expect(Date.today + 3.days).to eq 3.days.from_now

       expected: #<TimeLord::Period:0x007f91b08890c0 @beginning=2013-04-01 20:14:08 +0200, @ending=2013-03-29 19:14:08 +0100>
            got: Tue, 28 Nov 2722

       (compared using ==)

       Diff:
       @@ -1,4 +1,2 @@
       -#<TimeLord::Period:0x007f91b08890c0
       - @beginning=2013-04-01 20:14:08 +0200,
       - @ending=2013-03-29 19:14:08 +0100>
       +Tue, 28 Nov 2722

Oops! Calculation about 710 years wrong!!!

I think the problem is either the + or the compare overrides? include Comparable ?

Would be nice if you could at least make these two scenarios pass ;)

Thanks!