Get timestamp field from snapshot as Timestamp inside Cloud Function Triggers

Get timestamp field from snapshot as Timestamp inside Cloud Function Triggers

In typescript, I can create document with field like createdAt, updatedAt as Timestamp by using&nbsp;<code>change.after.updateTime</code>&nbsp;or&nbsp;<code>snap.createTime</code>&nbsp;inside Cloud Functions Triggers.

In typescript, I can create document with field like createdAt, updatedAt as Timestamp by using change.after.updateTime or snap.createTime inside Cloud Functions Triggers.

But inside other triggers like onUpdate, the field change.after.data().updatedAt that suppose to store a Timestamp, gives me an object.

How can i compare them if i can't get them as Timestamp value ? How can i get the field as Timestamp value ? Thanks

admin.initializeApp();
const firestore = admin.firestore();
const settings = { timestampsInSnapshots: true };
firestore.settings(settings);


export const setCreatedAt = functions.firestore.document('path') .onCreate(async (snap, context) => {

    return snap.ref.update({
        createdAt: snap.createTime, // Type Timestamp
        updatedAt: snap.createTime // Type Timestamp
    });

});

export const setUpdatedAt = functions.firestore.document('path') .onUpdate(async (change, context) => {

    let beforeTimestamp = change.before.data().updatedAt; // Type object, not Timestamp
    let afterTimestamp = change.after.data().updatedAt; // Type object, not Timestamp

    console.log('beforeTimestamp', beforeTimestamp);
    console.log('afterTimestamp', afterTimestamp);

    if (change.before.data().updatedAt === change.after.data().updatedAt) {
        change.after.ref.update({
            updatedAt: change.after.updateTime, // Type Timestamp
        });
    }
});

The image below shows the logs when doing an update. 

It looks like the { timestampsInSnapshots: true } settings has no effect because i still have the warning inside the console. But why ?

The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Learn TypeScript | TypeScript Crash Course | TypeScript Tutorial for Beginners

Learn TypeScript | TypeScript Crash Course | TypeScript Tutorial for Beginners: My goal with this courses is just give your the fundamentals of the language, show you what TypeScript is and how to use it. We as developers don't have time neither can we afford to spend too much time on any tehcnology.

What is Enum in Typescript?

In this post, you will learn about Enum in Typescript

TypeScript, Angular, Firebase & Angular Material Master class Tutorial

As the course progresses, you'll get familiar with: TypeScript, Angular Application Architecture, and Angular CLI. Angular Modules and Angular Components. Angular's Component LifeCycle Hooks....