Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ulid/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def random_bytes
end

def millisecond_time
(@time.to_f * 1_000).to_i
(@time.to_r * 1_000).to_i
end

# THIS IS CORRECT (to the ULID spec)
Expand Down
6 changes: 6 additions & 0 deletions spec/ulid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
expect(ULID.at(KNOWN_TIME)).to be_a_valid_ulid
end

it 'handles timestamp as the milliseconds precision' do
expect(ULID.at(Time.parse('2016-07-30 22:36:16.001000000 UTC'))).to start_with('01ARYZ6RR1')
expect(ULID.at(Time.parse('2016-07-30 22:36:16.002000000 UTC'))).to start_with('01ARYZ6RR2')
expect(ULID.at(Time.parse('2016-07-30 22:36:16.003000000 UTC'))).to start_with('01ARYZ6RR3')
end

end

describe '.time' do
Expand Down