timerizer icon indicating copy to clipboard operation
timerizer copied to clipboard

Implement to_f

Open greggilbert opened this issue 6 years ago • 2 comments

Nice to see another gem that's trying to break free from Rails dependencies. Thanks for the effort!

A number of other libraries run to_f on durations (e.g. Sidekiq). When I tried it with timerizer, it threw:

NoMethodError: undefined method `to_f' for #<Timerizer::Duration:0x00007f25c88d79e0 @seconds=60, @months=0>

It'd be a huge help in terms of compatibilty if .to_f worked for duration.

greggilbert avatar Sep 20 '19 21:09 greggilbert

Timerizer isn't really meant to be a drop-in replacement for Rails' time syntax, but this seems low-cost and clear enough that it's probably still worth doing. Since Timerizer doesn't support sub-second units, would something like this be sufficient?

class Duration
  # ...

  def to_f
    self.to_i.to_f
  end
end

kylewlacy avatar Oct 02 '19 02:10 kylewlacy

Yeah, I think that'd work.

greggilbert avatar Oct 02 '19 03:10 greggilbert