Module: BSON::Time

Defined in:
lib/bson/time.rb

Overview

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

See Also:

Since:

  • 2.0.0

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

BSON_TYPE =

A time is type 0x09 in the BSON spec.

Since:

  • 2.0.0

9.chr.force_encoding(BINARY).freeze

Instance Method Summary collapse

Instance Method Details

#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ BSON::ByteBuffer

Get the time as encoded BSON.

Examples:

Get the time as encoded BSON.

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

Returns:

  • (BSON::ByteBuffer)

    The buffer with the encoded object.

See Also:

Since:

  • 2.0.0



40
41
42
# 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