How to use @google-cloud/precise-date - 8 common examples

To help you get started, we’ve selected a few @google-cloud/precise-date examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-spanner / test / codec.ts View on Github external
it('should determine if the value is a timestamp', () => {
      assert.deepStrictEqual(codec.getType(new PreciseDate()), {
        type: 'timestamp',
      });
    });
github googleapis / nodejs-spanner / test / transaction.ts View on Github external
it('should convert `readTimestamp` Date to proto', () => {
        const fakeTimestamp = new PreciseDate();

        sandbox.stub(fakeTimestamp, 'toStruct').returns(PROTO_TIMESTAMP);

        const options = Snapshot.encodeTimestampBounds({
          readTimestamp: fakeTimestamp,
        });

        assert.strictEqual(options.readTimestamp, PROTO_TIMESTAMP);
      });
github googleapis / nodejs-spanner / test / transaction.ts View on Github external
it('should localize `readTimestamp` if present', done => {
        const expectedTimestamp = new PreciseDate(0);
        const readTimestamp = {seconds: 0, nanos: 0};
        const response = Object.assign({readTimestamp}, BEGIN_RESPONSE);

        REQUEST.callsFake((_, callback) => callback(null, response));

        snapshot.begin(err => {
          assert.ifError(err);
          assert.deepStrictEqual(snapshot.readTimestamp, expectedTimestamp);
          assert.strictEqual(snapshot.readTimestampProto, readTimestamp);
          done();
        });
      });
github googleapis / nodejs-spanner / test / codec.ts View on Github external
it('should decode TIMESTAMP', () => {
      const value = new Date();
      const expected = new PreciseDate(value.getTime());
      const decoded = codec.decode(value.toJSON(), {
        code: s.TypeCode.TIMESTAMP,
      });

      assert.deepStrictEqual(decoded, expected);
    });
github googleapis / nodejs-spanner / test / codec.ts View on Github external
it('should encode TIMESTAMP', () => {
      const value = new PreciseDate();

      const encoded = codec.encode(value);

      assert.strictEqual(encoded, value.toJSON());
    });
github googleapis / nodejs-spanner / test / transaction.ts View on Github external
it('should convert `minReadTimestamp` Date to proto', () => {
        const fakeTimestamp = new PreciseDate();

        sandbox.stub(fakeTimestamp, 'toStruct').returns(PROTO_TIMESTAMP);

        const options = Snapshot.encodeTimestampBounds({
          minReadTimestamp: fakeTimestamp,
        });

        assert.strictEqual(options.minReadTimestamp, PROTO_TIMESTAMP);
      });
github googleapis / nodejs-pubsub / src / subscriber.ts View on Github external
*
     * **EXPERIMENTAL:** This feature is part of a closed alpha release. This
     * API might be changed in backward-incompatible ways and is not recommended
     * for production use. It is not subject to any SLA or deprecation policy.
     *
     * @name Message#orderingKey
     * @type {string}
     */
    this.orderingKey = message!.orderingKey!;
    /**
     * The time at which the message was published.
     *
     * @name Message#publishTime
     * @type {external:PreciseDate}
     */
    this.publishTime = new PreciseDate(message!.publishTime as DateStruct);
    /**
     * The time at which the message was recieved by the subscription.
     *
     * @name Message#received
     * @type {number}
     */
    this.received = Date.now();

    this._handled = false;
    this._length = this.data.length;
    this._subscriber = sub;
  }
  /**
github googleapis / nodejs-spanner / src / batch-transaction.ts View on Github external
callback(err, null, resp);
        return;
      }

      const partitions = resp.partitions.map(partition => {
        return extend({}, query, partition);
      });

      if (resp.transaction) {
        const {id, readTimestamp} = resp.transaction;

        this.id = id;

        if (readTimestamp) {
          this.readTimestampProto = readTimestamp;
          this.readTimestamp = new PreciseDate(readTimestamp);
        }
      }

      callback(null, partitions, resp);
    });
  }

@google-cloud/precise-date

A simple utility for precise-dateing functions and classes.

Apache-2.0
Latest version published 9 months ago

Package Health Score

85 / 100
Full package analysis

Popular @google-cloud/precise-date functions