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

#bson_typeObject

Get the BSON type for the date.

As the date is converted to a time, this returns the BSON type for time.

Since:

  • 2.1.0



54
55
56
# File 'lib/bson/date.rb', line 54

def bson_type
  ::Time::BSON_TYPE
end

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

Get the date as encoded BSON.

Examples:

Get the date as encoded BSON.

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

Returns:

See Also:

Since:

  • 2.1.0



47
48
49
# File 'lib/bson/date.rb', line 47

def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
  buffer.put_int64((jd - DATE_REFERENCE) * MILLISECONDS_IN_DAY)
end