Permalink
Browse files

Merge pull request #11 from nessche/integer_comparison

Changed rule_for_reference to use timestamps where possible
  • Loading branch information...
2 parents 165ac05 + 0291c09 commit 488513af12c251a5a607aaee6bdbdfc402f35a49 @panthomakos committed May 16, 2012
Showing with 1,047 additions and 1 deletion.
  1. +18 −1 lib/timezone/zone.rb
  2. +1,017 −0 test/data/Helsinki_rules_without_timestamps.json
  3. +12 −0 test/timezone_test.rb
View
@@ -114,7 +114,24 @@ def list(*args)
def rule_for_reference reference
reference = reference.utc
- @rules.detect{ |rule| _parsetime(rule['_from']) <= reference && _parsetime(rule['_to']) > reference }
+ @rules.detect do |rule|
+ if rule['from'] && rule['to']
+ from = _read_timestamp(rule['from'])
+ to = _read_timestamp(rule['to'])
+ else
+ from = _parsetime(rule['_from'])
+ to = _parsetime(rule['_to'])
+ end
+ from <= reference && to > reference
+ end
+ end
+
+ def _read_timestamp timestamp #:nodoc:
+ begin
+ Time.at(timestamp.to_i / 1000.0)
+ rescue Exception => e
+ raise Timezone::Error::ParseTime, e.message
+ end
end
def timezone_id lat, lon #:nodoc:
Oops, something went wrong.

0 comments on commit 488513a

Please sign in to comment.