Skip to content

Commit

Permalink
Fix Time encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
fbernier committed Mar 23, 2014
1 parent 44605b3 commit 4d59e4a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/bson/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Time
#
# @since 2.0.0
def to_bson(encoded = ''.force_encoding(BINARY))
encoded << [ (to_f * 1000.0).to_i ].pack(Int64::PACK)
encoded << [ (to_i * 1000) + (usec / 1000) ].pack(Int64::PACK)
end

module ClassMethods
Expand Down
4 changes: 2 additions & 2 deletions spec/bson/time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

context "when the time is post epoch" do

let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0) }
let(:bson) { [ (obj.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
let(:obj) { Time.at(Time.utc(2014,03,22,18,05,05).to_i, 505000).utc }
let(:bson) { [ (obj.to_i * 1000) + (obj.usec / 1000) ].pack(BSON::Int64::PACK) }

it_behaves_like "a serializable bson element"
it_behaves_like "a deserializable bson element"
Expand Down

0 comments on commit 4d59e4a

Please sign in to comment.