module BSON::TimeWithZone

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

@see bsonspec.org/#/specification

@since 4.4.0

Public Instance Methods

bson_type() click to toggle source

Get the BSON type for the ActiveSupport::TimeWithZone.

As the ActiveSupport::TimeWithZone is converted to a time, this returns the BSON type for time.

# File lib/bson/time_with_zone.rb, line 45
def bson_type
  ::Time::BSON_TYPE
end
to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) click to toggle source

Get the ActiveSupport::TimeWithZone as encoded BSON.

@example Get the ActiveSupport::TimeWithZone as encoded BSON.

Time.utc(2012, 12, 12, 0, 0, 0).in_time_zone("Pacific Time (US & Canada)").to_bson

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

@see bsonspec.org/#/specification

@since 4.4.0

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