floraison / et-orbi

Time zones for fugit and rufus-scheduler. Urbi et Orbi.
MIT License
24 stars 11 forks source link

Handle Rails Duration types #20

Closed d-m-u closed 5 years ago

d-m-u commented 5 years ago

It'd be nice to handle Rails Durations for comparisons here since as it stands, it doesn't support comparisons with user provided Time objects. Could we do something like this, please?

jmettraux commented 5 years ago

Hello, thanks for the contribution.

It's a bit hard to see what you mean by this change. Do you have some context for me?

I'll do my best to adapt et-orbi then.

Thanks in advance,

d-m-u commented 5 years ago

Sure, sorry. We at ManageIQ just updated to rufus 3.6 and we're using a gross patch because our tests use ActiveRecord TimeWithZone and et-orbi on this particular line doesn't support comparisons of EoTime with AR objects.

I think it'd be cool to be able to do something like this with a rufus scheduler:

job = rufus_scheduler.jobs.first
expect(job.next_time).to eq(3.hours.from_now)
jmettraux commented 5 years ago

meanwhile:

job = rufus_scheduler.jobs.first
expect(job.next_time.to_i).to eq(3.hours.from_now.to_i)

or

job = rufus_scheduler.jobs.first
expect(job.next_time.to_i).to be_within(2).of(3.hours.from_now.to_i)
d-m-u commented 5 years ago

Yes, but that feels like it shouldn't have to be part of the test itself. Since you're checking for EO types on this line, why not make that as true to Postel's law as possible?

jmettraux commented 5 years ago
  1. expect(job.next_time).to eq(3.hours.from_now) is brittle, it only works 3 hours from now, exactly
  2. do you know what stands behind Rspec's eq?
jmettraux commented 5 years ago

Re-opening. I want to make sure comparison with Time and ActiveSupport Time works.

jmettraux commented 5 years ago

Note to self: https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/equality-matchers

jmettraux commented 5 years ago

Closing and moving to gh-7.

jmettraux commented 5 years ago

Hello @d-m-u, would https://github.com/floraison/et-orbi/commit/283f5e207e9a6fe6a50dc2e39fc2e40eebd5b3b5 suit you and your company?

jmettraux commented 5 years ago

@d-m-u Just released et-orbi 1.2.2.

If there is anything wrong, please tell me.

Best regards,

d-m-u commented 5 years ago

Thank you!!