Timestamp()

Constructor

Defines a Timestamp class for representing a 64-bit two’s-complement integer value, which faithfully simulates the behavior of a Java “Timestamp”. This implementation is derived from TimestampLib in GWT.

class Timestamp()
Arguments:
  • low (number) – the low (signed) 32 bits of the Timestamp.
  • high (number) – the high (signed) 32 bits of the Timestamp.

Constructs a 64-bit two’s-complement integer, given its low and high 32-bit values as signed integers. See the from* functions below for more convenient ways of constructing Timestamps.

The internal representation of a Timestamp is the two given signed, 32-bit values. We use 32-bit pieces because these are the size of integers on which Javascript performs bit-operations. For operations like addition and multiplication, we split each number into 16-bit pieces, which can easily be multiplied within Javascript’s floating-point representation without overflow or change in sign.

In the algorithms below, we frequently reduce the negative case to the positive case by negating the input(s) and then post-processing the result. Note that we must ALWAYS check specially whether those values are MIN_VALUE (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as a positive number, it overflows back into a negative). Not handling this case would often result in infinite recursion.

toInt

Return the int value.

toInt()
Returns:number the value, assuming it is a 32-bit integer.

toNumber

Return the Number value.

toNumber()
Returns:number the closest floating-point representation to this value.

toJSON

Return the JSON value.

toJSON()
Returns:string the JSON representation.

toString

Return the String value.

toString([opt_radix])
Arguments:
  • [opt_radix] (number) – the radix in which the text should be written.
Returns:

string the textual representation of this value.

getHighBits

Return the high 32-bits value.

getHighBits()
Returns:number the high 32-bits as a signed value.

getLowBits

Return the low 32-bits value.

getLowBits()
Returns:number the low 32-bits as a signed value.

getLowBitsUnsigned

Return the low unsigned 32-bits value.

getLowBitsUnsigned()
Returns:number the low 32-bits as an unsigned value.

getNumBitsAbs

Returns the number of bits needed to represent the absolute value of this Timestamp.

getNumBitsAbs()
Returns:number Returns the number of bits needed to represent the absolute value of this Timestamp.

isZero

Return whether this value is zero.

isZero()
Returns:boolean whether this value is zero.

isNegative

Return whether this value is negative.

isNegative()
Returns:boolean whether this value is negative.

isOdd

Return whether this value is odd.

isOdd()
Returns:boolean whether this value is odd.

equals

Return whether this Timestamp equals the other

equals(other)
Arguments:
  • other (timestamp) – Timestamp to compare against.
Returns:

boolean whether this Timestamp equals the other

notEquals

Return whether this Timestamp does not equal the other.

notEquals(other)
Arguments:
  • other (timestamp) – Timestamp to compare against.
Returns:

boolean whether this Timestamp does not equal the other.

lessThan

Return whether this Timestamp is less than the other.

lessThan(other)
Arguments:
  • other (timestamp) – Timestamp to compare against.
Returns:

boolean whether this Timestamp is less than the other.

lessThanOrEqual

Return whether this Timestamp is less than or equal to the other.

lessThanOrEqual(other)
Arguments:
  • other (timestamp) – Timestamp to compare against.
Returns:

boolean whether this Timestamp is less than or equal to the other.

greaterThan

Return whether this Timestamp is greater than the other.

greaterThan(other)
Arguments:
  • other (timestamp) – Timestamp to compare against.
Returns:

boolean whether this Timestamp is greater than the other.

greaterThanOrEqual

Return whether this Timestamp is greater than or equal to the other.

greaterThanOrEqual(other)
Arguments:
  • other (timestamp) – Timestamp to compare against.
Returns:

boolean whether this Timestamp is greater than or equal to the other.

compare

Compares this Timestamp with the given one.

compare(other)
Arguments:
  • other (timestamp) – Timestamp to compare against.
Returns:

boolean 0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.

negate

The negation of this value.

negate()
Returns:timestamp the negation of this value.

add

Returns the sum of this and the given Timestamp.

add(other)
Arguments:
  • other (timestamp) – Timestamp to add to this one.
Returns:

timestamp the sum of this and the given Timestamp.

subtract

Returns the difference of this and the given Timestamp.

subtract(other)
Arguments:
  • other (timestamp) – Timestamp to subtract from this.
Returns:

timestamp the difference of this and the given Timestamp.

multiply

Returns the product of this and the given Timestamp.

multiply(other)
Arguments:
  • other (timestamp) – Timestamp to multiply with this.
Returns:

timestamp the product of this and the other.

div

Returns this Timestamp divided by the given one.

div(other)
Arguments:
  • other (timestamp) – Timestamp by which to divide.
Returns:

timestamp this Timestamp divided by the given one.

modulo

Returns this Timestamp modulo the given one.

modulo(other)
Arguments:
  • other (timestamp) – Timestamp by which to mod.
Returns:

timestamp this Timestamp modulo the given one.

not

The bitwise-NOT of this value.

not()
Returns:timestamp the bitwise-NOT of this value.

and

Returns the bitwise-AND of this Timestamp and the given one.

and(other)
Arguments:
  • other (timestamp) – the Timestamp with which to AND.
Returns:

timestamp the bitwise-AND of this and the other.

or

Returns the bitwise-OR of this Timestamp and the given one.

or(other)
Arguments:
  • other (timestamp) – the Timestamp with which to OR.
Returns:

timestamp the bitwise-OR of this and the other.

xor

Returns the bitwise-XOR of this Timestamp and the given one.

xor(other)
Arguments:
  • other (timestamp) – the Timestamp with which to XOR.
Returns:

timestamp the bitwise-XOR of this and the other.

shiftLeft

Returns this Timestamp with bits shifted to the left by the given amount.

shiftLeft(numBits)
Arguments:
  • numBits (number) – the number of bits by which to shift.
Returns:

timestamp this shifted to the left by the given amount.

shiftRight

Returns this Timestamp with bits shifted to the right by the given amount.

shiftRight(numBits)
Arguments:
  • numBits (number) – the number of bits by which to shift.
Returns:

timestamp this shifted to the right by the given amount.

shiftRightUnsigned

Returns this Timestamp with bits shifted to the right by the given amount, with the new top bits matching the current sign bit.

shiftRightUnsigned(numBits)
Arguments:
  • numBits (number) – the number of bits by which to shift.
Returns:

timestamp this shifted to the right by the given amount, with zeros placed into the new leading bits.

Timestamp.fromInt

Returns a Timestamp representing the given (32-bit) integer value.

Timestamp.fromInt(value)
Arguments:
  • value (number) – the 32-bit integer in question.
Returns:

timestamp the corresponding Timestamp value.

Timestamp.fromNumber

Returns a Timestamp representing the given value, provided that it is a finite number. Otherwise, zero is returned.

Timestamp.fromNumber(value)
Arguments:
  • value (number) – the number in question.
Returns:

timestamp the corresponding Timestamp value.

Timestamp.fromBits

Returns a Timestamp representing the 64-bit integer that comes by concatenating the given high and low bits. Each is assumed to use 32 bits.

Timestamp.fromBits(lowBits, highBits)
Arguments:
  • lowBits (number) – the low 32-bits.
  • highBits (number) – the high 32-bits.
Returns:

timestamp the corresponding Timestamp value.

Timestamp.fromString

Returns a Timestamp representation of the given string, written using the given radix.

Timestamp.fromString(str, opt_radix)
Arguments:
  • str (string) – the textual representation of the Timestamp.
  • opt_radix (number) – the radix in which the text is written.
Returns:

timestamp the corresponding Timestamp value.

Contents

Manual

MongoDB Wiki