Antonio Ooi
Antonio Ooi

Reputation: 1828

Firestore Timestamp toDate() returns wrong UTC date?

I have the following dates stored in my Firestore Emulator v9.16.0:

enter image description here

As you can see in the screenshot, when my mouse hover on the EndDate, it shows the correct UTC Date, i.e. 2021-08-13T11:09:58.000Z, but when I issue the following code, it returns the wrong UTC date (2021-08-13T09:09:58.000Z):

In my localhost server Node.js:

let maintConfigRef = db.collection("Configurations").doc("Maintenance");
let maintConfigDoc = await maintConfigRef.get();

if (maintConfigDoc.exists) {
     let maintConfigData = maintConfigDoc.data();
     let endDate = maintConfigData.EndDate.toDate().toJSON(); // Returns 2021-08-13T09:09:58.000Z
     console.log(endDate); // Output "2021-08-13T09:09:58.000Z"
};

Which means it should be ...T11:09 (as shown in the tooltip) instead of ...T09:09. Anyone knows what's wrong with it and what else should I do to get it right? Thanks in advance!

Upvotes: 2

Views: 343

Answers (1)

Antonio Ooi
Antonio Ooi

Reputation: 1828

Not sure if it was a bug, but after installing firebase-tools 9.16.5, the problem disappeared:

npm install -g firebase-tools

Upvotes: 1

Related Questions