Firestore Timestamp not being recognized as such in the console

Viewed 234

I have a script which loads some data into Firestore from a excel sheet. For each entry that is loaded in, I want to add two fields, dateAdded and dateModified.

const service:Service = {
   name: data.PROFISSIONAL,
   description: data.DESCRICAO,
   category: data.CLASSIFICACAO,
   cellphones,
   phones,
   reviews: reviews,
   numReviews: reviews.length,
   excluded: data.EXCLUIDO === 'SIM',
   instagram: data.INSTAGRAM,
   location: data.LOCAL,
   dateAdded: Timestamp.now(),
   dateModified: Timestamp.now(),
   tags: getTags(data.CLASSIFICACAO)
};

I have a intermediate step which saves an array of these services to a json object. The data then gets uploaded to firestore:

const jsonToFirestore = async () => {
  console.log(`Uploading table`)

  try {
    console.log('Initializing Firebase');
    initializeApp(serviceAccount);
    console.log('Firebase Initialized');

    await restore('./data/services.json');
    console.log('Upload Success');
  }
  catch (error) {
    console.log(error);
  }
};

When I look in the Firebase console though, the date fields have not been recognized as Timestamps.

Firestore console dates not recognized

Is there any way for them to be recognized? Like this for example:

Firestore console dates recognized

I appreciate any help provided.

1 Answers

It looks like this format of the Timestamp is working as expected:

A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time.

Try using the toDate method in order to convert a Timestamp to a JavaScript Date object.

Related