Skip to content

Commit

Permalink
Merge pull request #7 from recurly/ruby-2.2-fix
Browse files Browse the repository at this point in the history
Fix for Ruby 2.2 with custom offset
  • Loading branch information
drewish committed Apr 9, 2015
2 parents d3767f0 + f0af6d2 commit 8d58fd8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions druuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class << self
# @param [Time] time of UUID
# @param [Numeric] epoch offset
# @return [Bignum] UUID
def gen time = Time.now, epoch = epoch
ms = ((time.to_f - epoch.to_i) * 1e3).round
def gen time = Time.now, epoch_offset = epoch
ms = ((time.to_f - epoch_offset.to_i) * 1e3).round
rand = (SecureRandom.random_number * 1e16).round
id = ms << (64 - 41)
id | rand % (2 ** (64 - 41))
Expand All @@ -33,9 +33,9 @@ def gen time = Time.now, epoch = epoch
# @example
# Druuid.time 11142943683383068069
# # => 2012-02-04 00:00:00 -0800
def time uuid, epoch = epoch
def time uuid, epoch_offset = epoch
ms = uuid >> (64 - 41)
Time.at (ms / 1e3) + epoch.to_i
Time.at (ms / 1e3) + epoch_offset.to_i
end

end
Expand Down

0 comments on commit 8d58fd8

Please sign in to comment.