Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-list-collections
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
dmurvihill committed Mar 2, 2020
2 parents 4dfa974 + d1c7634 commit 4a6a54d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
behavior of `onAuthStateChanged()` (see below)
- Support for Firebase Messaging (Admin API)
- Support for [FieldValue.increment](https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue#increment)
- Support for [firestore.Timestamp.now()](https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp#now)
- Support for `listCollections` in [DocumentReferences](https://googleapis.dev/nodejs/firestore/latest/DocumentReference.html#listCollections)

### Changed
Expand Down
4 changes: 4 additions & 0 deletions src/timestamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Timestamp.fromMillis = function(ms) {
return new Timestamp(sec, ns);
};

Timestamp.now = function() {
return Timestamp.fromDate(new Date());
};

Timestamp.prototype.toDate = function () {
var millis = this.seconds * 1000 + this.nanoseconds / (1000 * 1000);
return new Date(millis);
Expand Down
15 changes: 15 additions & 0 deletions test/unit/timestamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ var sinon = require('sinon');
var Timestamp = require('../../src/timestamp');

describe('Timestamp', function () {
var clock;
beforeEach(function () {
clock = sinon.useFakeTimers();
});
afterEach(function () {
clock.restore();
});

describe('fromDate', function () {
it('should convert from date', function () {
var date = new Date('2009-02-13T23:31:30.123456789Z');
Expand All @@ -20,6 +28,13 @@ describe('Timestamp', function () {
expect(timestamp.nanoseconds).to.equal(123000000);
});
});
describe('now', function () {
it('should create a current Timestamp', function () {
var now = new Date();
var timestamp = Timestamp.now();
expect(timestamp.toDate().getTime()).to.equal(now.getTime());
});
});
describe('#toDate', function () {
it('should convert to date', function () {
var ts = new Timestamp(1234567890, 123456789);
Expand Down

0 comments on commit 4a6a54d

Please sign in to comment.