FirestoreGoogleAppsScript icon indicating copy to clipboard operation
FirestoreGoogleAppsScript copied to clipboard

Firestore number is sometimes returned as date 12/30/1899 0:00:00 or 10/26/1900 0:00:00

Open yassinsameh opened this issue 3 years ago • 2 comments

Minimal code to reproduce the problem

const firestore = FirestoreApp.getFirestore(email, key, projectId);


        const allDocumentsRequested = firestore.query("bookings").Where("slotTime",">=",startingDate ).Where("slotTime","<=", endDate).OrderBy("slotTime").Execute().map(function(document){
            
            return document.obj;
          });
          
          const first = allDocumentsRequested[0];

          const columns = Object.keys(first);
          

          


          const sheet = SpreadsheetApp.getActiveSheet();
          sheet.appendRow(displayedColumnNames);

          allDocumentsRequested.forEach(function(document){
            const row = columns.map(function(column){
              return document[column];
            });
            sheet.appendRow(row);

          });

Expected Behavior

To print out all Strings, Dates, Boolean and Numbers correctly.

Actual Results

All other non-number fields are working correctly however, on a few occasions the Numbers turn into 12/30/1899 0:00:00 or 10/26/1900 0:00:00, in the database i check the documents and they are numbers correctly example (300).

Library Version:

33

yassinsameh avatar May 14 '21 09:05 yassinsameh

The workaround i found was to convert the returned value to a string, in the code above i checked if it's a number then i return document[column].toString(); I will keep this open however as i believe it's still a bug.

yassinsameh avatar May 15 '21 08:05 yassinsameh

Is the data type is stored in Firestore correctly? Since Firestore stores each field attibuted to a specific data type, this library checks that metadata and converts from string to that data type.

LaughDonor avatar Sep 01 '21 22:09 LaughDonor

Closing due to inactivity.

LaughDonor avatar Aug 24 '22 15:08 LaughDonor

I seemed to miss the follow up apologies. Data types were stored correctly. A note was just that most numbers showed correctly on a few occasions however this issue would arise.

yassinsameh avatar Aug 25 '22 03:08 yassinsameh

@yassinsameh can you provide some example data?

LaughDonor avatar Aug 25 '22 09:08 LaughDonor

I left that project a year ago but an example at the top of my head. Document{ startDate:Timestamp object Price: 300.0 (Number) }

The price type and amount was fixed for all documents and upon inspection for the exporting issue the documents themselves were correct as the others with the same datatype and amount.

yassinsameh avatar Aug 25 '22 10:08 yassinsameh

Sorry, the startDate property doesn't provide sufficient information to followup. If someone else comes across this and has the same issue, please fill us in.

LaughDonor avatar Aug 29 '22 22:08 LaughDonor