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(encoded = ''.force_encoding(BINARY)) ⇒ String

Get the time as encoded BSON.

Examples:

Get the time as encoded BSON.

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

Returns:

  • (String)

    The encoded string.

See Also:

Since:

  • 2.0.0



40
41
42
# File 'lib/bson/time.rb', line 40

def to_bson(encoded = ''.force_encoding(BINARY))
  encoded << [ (to_i * 1000) + (usec / 1000) ].pack(Int64::PACK)
end