panthomakos / timezone

Accurate current and historical timezones for Ruby with support for Geonames and Google latitude - longitude lookups.
http://rubygems.org/gems/timezone
MIT License
354 stars 49 forks source link

Make timezone compatible with gem requiring mathn (e.g.ruby-units) #61

Closed cbillen closed 8 years ago

cbillen commented 8 years ago

When used inside a project requiring mathn, such as ruby-units, the binary search method will fail on certain timezone with a stack too deep

this is due to the fact that mathn will override divisions and not return an integer when two integers are divided. this simple fix cast the mid value to integer in those case.

To reproduce the problem in an unpatched version:

rb(main):001:0> require 'timezone' => true irb(main):002:0> tz = Timezone['America/Regina'];tz.utc_offset => -21600 irb(main):003:0> require 'mathn' => true irb(main):004:0> tz = Timezone['America/Regina'];tz.utc_offset SystemStackError: stack level too deep

cbillen commented 8 years ago

Ok test added. There's some rubocop errors in some other parts of the code though happening in the main repo as well.

panthomakos commented 8 years ago

Please add a CHANGELOG entry. Do not worry about the RuboCop failures. They have been fixed in master. You can feel free to rebase if that makes testing easier.

cbillen commented 8 years ago

Hi there, doesn’t look like i can use asset_nothing_raised with minitest

https://www.ruby-forum.com/topic/493248

but perhaps it’s not needed http://www.thagomizer.com/blog/2013/06/11/assert-nothing-raised.html

panthomakos commented 8 years ago

You are right, you don't need it. The way you updated the test looks good to me. Thanks for the contribution!