class BSON::Timestamp
@since 2.0.0
@see bsonspec.org/#/specification<br><br>Represents a timestamp type, which is predominately used for sharding.
def self.from_bson(buffer, **options)
- Since: - 2.0.0
Other tags:
- See: http://bsonspec.org/#/specification -
Returns:
-
(Timestamp)
- The decoded timestamp.
Options Hash:
(**options)
-
:mode
(nil | :bson
) -- Decoding mode to use.
Parameters:
-
buffer
(ByteBuffer
) -- The byte buffer.
def self.from_bson(buffer, **options) increment = buffer.get_uint32 seconds = buffer.get_uint32 new(seconds, increment) end
def <=>(other)
- Since: - 4.3.0
Returns:
-
(true, false)
- The result of the comparison.
Parameters:
-
other
(Object
) -- The object to compare against.
Other tags:
- Example: Compare the timestamp. -
def <=>(other) raise ArgumentError.new(COMPARISON_ERROR_MESSAGE % other.class) unless other.is_a?(Timestamp) return 0 if self == other a = [ seconds, increment ] b = [ other.seconds, other.increment ] [ a, b ].sort[0] == a ? -1 : 1 end
def ==(other)
- Since: - 2.0.0
Returns:
-
(true, false)
- If the objects are equal.
Parameters:
-
other
(Object
) -- The object to compare against.
Other tags:
- Example: Check the timestamp equality. -
def ==(other) return false unless other.is_a?(Timestamp) seconds == other.seconds && increment == other.increment end
def as_extended_json(**options)
-
(Hash)
- The extended json representation.
Options Hash:
(**opts)
-
:mode
(nil | :relaxed | :legacy
) -- Serialization mode
def as_extended_json(**options) { "$timestamp" => { "t" => seconds, "i" => increment } } end
def as_json(*args)
- Use as_extended_json instead.
Other tags:
- Since: - 2.0.0
Returns:
-
(Hash)
- The timestamp as a JSON hash.
Other tags:
- Example: Get the timestamp as a JSON hash. -
def as_json(*args) as_extended_json end
def initialize(seconds, increment)
- Since: - 2.0.0
Parameters:
-
increment
(Integer
) -- The increment value. -
seconds
(Integer
) -- The number of seconds.
Other tags:
- Example: Instantiate the timestamp. -
def initialize(seconds, increment) @seconds, @increment = seconds, increment end
def to_bson(buffer = ByteBuffer.new)
- Since: - 2.0.0
Other tags:
- See: http://bsonspec.org/#/specification -
Returns:
-
(BSON::ByteBuffer)
- The buffer with the encoded object.
Other tags:
- Example: Get the timestamp as BSON. -
def to_bson(buffer = ByteBuffer.new) buffer.put_uint32(increment) buffer.put_uint32(seconds) end