Module: BSON::Date

Defined in:
lib/bson/date.rb

Overview

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

See Also:

Since:

  • 2.1.0

Instance Method Summary collapse

Instance Method Details

#to_bson(encoded = ''.force_encoding(BINARY)) ⇒ String

Get the date as encoded BSON.

Examples:

Get the date as encoded BSON.

Date.new(2012, 1, 1).to_bson

Returns:

  • (String)

    The encoded string.

See Also:

Since:

  • 2.1.0



35
36
37
# File 'lib/bson/date.rb', line 35

def to_bson(encoded = ''.force_encoding(BINARY))
  ::Time.utc(year, month, day).to_bson(encoded)
end