Skip to content

Commit 944deec

Browse files
authored
Fix bug where timestamp in change objects are still date objects (#290)
1 parent b598d9a commit 944deec

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spec/providers/firestore.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23+
import * as admin from 'firebase-admin';
24+
2325
import * as firestore from '../../src/providers/firestore';
2426
import * as _ from 'lodash';
2527
import { expect } from 'chai';
@@ -428,7 +430,9 @@ describe('Firestore Functions', () => {
428430
})
429431
);
430432
expect(snapshot.data()).to.deep.equal({
431-
timestampVal: new Date('2017-06-13T00:58:40.349Z'),
433+
timestampVal: admin.firestore.Timestamp.fromDate(
434+
new Date('2017-06-13T00:58:40.349Z')
435+
),
432436
});
433437
});
434438

@@ -444,7 +448,9 @@ describe('Firestore Functions', () => {
444448
})
445449
);
446450
expect(snapshot.data()).to.deep.equal({
447-
timestampVal: new Date('2017-06-13T00:58:40Z'),
451+
timestampVal: admin.firestore.Timestamp.fromDate(
452+
new Date('2017-06-13T00:58:40Z')
453+
),
448454
});
449455
});
450456

src/providers/firestore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export function snapshotConstructor(event: Event): DocumentSnapshot {
161161
export function beforeSnapshotConstructor(event: Event): DocumentSnapshot {
162162
if (!firestoreInstance) {
163163
firestoreInstance = firebase.firestore(apps().admin);
164+
firestoreInstance.settings({ timestampsInSnapshots: true });
164165
}
165166
let oldValueProto = _getValueProto(
166167
event.data,

0 commit comments

Comments
 (0)