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.
Instance Method Summary collapse
- #_bson_to_i ⇒ Object private
-
#bson_type ⇒ Object
Get the BSON type for the ActiveSupport::TimeWithZone.
-
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the ActiveSupport::TimeWithZone as encoded BSON.
Instance Method Details
#_bson_to_i ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 55 56 57 58 59 60 |
# File 'lib/bson/time_with_zone.rb', line 52 def _bson_to_i # Workaround for JRuby's #to_i rounding negative timestamps up # rather than down (https://github.com/jruby/jruby/issues/6104) if BSON::Environment.jruby? (self - usec.to_r/1000000).to_i else to_i end end |
#bson_type ⇒ Object
Get the BSON type for the ActiveSupport::TimeWithZone.
As the ActiveSupport::TimeWithZone is converted to a time, this returns the BSON type for time.
47 48 49 |
# File 'lib/bson/time_with_zone.rb', line 47 def bson_type ::Time::BSON_TYPE end |
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the ActiveSupport::TimeWithZone as encoded BSON.
39 40 41 |
# File 'lib/bson/time_with_zone.rb', line 39 def to_bson(buffer = ByteBuffer.new) buffer.put_int64((to_i * 1000) + (usec / 1000)) end |