Module: BSON::TimeWithZone

Defined in:
lib/bson/time_with_zone.rb

Overview

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

See Also:

Since:

  • 4.4.0

Instance Method Summary collapse

Instance Method Details

#bson_typeObject

Get the BSON type for the ActiveSupport::TimeWithZone.

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

Since:

  • 4.4.0



45
46
47
# 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?) ⇒ BSON::ByteBuffer

Get the ActiveSupport::TimeWithZone as encoded BSON.

Examples:

Get the ActiveSupport::TimeWithZone as encoded BSON.

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

Returns:

  • (BSON::ByteBuffer)

    The buffer with the encoded object.

See Also:

Since:

  • 4.4.0



37
38
39
# 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