module BSON::Time

Injects behaviour for encoding and decoding time values to and from raw bytes as specified by the BSON spec.

@see bsonspec.org/#/specification

@since 2.0.0

Constants

BSON_TYPE

A time is type 0x09 in the BSON spec.

@since 2.0.0

Public Instance Methods

to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) click to toggle source

Get the time as encoded BSON.

@example Get the time as encoded BSON.

Time.new(2012, 1, 1, 0, 0, 0).to_bson

@return [ BSON::ByteBuffer ] The buffer with the encoded object.

@see bsonspec.org/#/specification

@since 2.0.0

# File lib/bson/time.rb, line 40
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
  buffer.put_int64((to_i * 1000) + (usec / 1000))
end