2

I’m reasonably new to coding (Started a year ago) and am currently migrating a MySQL database to Firestore and as my project to learn, I am rewriting and migrating from scratch A Joomla website I have been using for years using JavaScript and Firestore as my main tools.

So my current challenge: I have a JSON imported historic date that is stored as a string in a Firestore document. I am trying to convert it to a timestamp format but get the following error "RangeError: Invalid time value" (full error details further below)

So here are the steps.

1) I imported my documents from the old SQL database with a JSON file with the specific date fields into firestore documents. You can see an example of the “created” field in the image below Firestore document tree and field set up

2) I then import the firestore field called "created" using JavaScript on the client and checked it is coming through on the console.log which it is as

dateAdded Sat Oct 15 2016 16:29:41 GMT+0100 (British Summer Time)

3) I change the field to a new date and a timestamp using the code....and check in the console it is showing which it looks like it is and shows in console as follows:

Timestamp uo {seconds: 1476545381, nanoseconds: 0}

I then create a firestore update command for the “created” strong field to replace with the new timestamp converted date Nb I have tried also using the update command to have this in a new field which I called “created_at” and it gave same error.

So before I go further here is the main function which I call later to incur it.

const TimeStamp = (query) => {
  
  let dateAdded = new Date(query.created)
  
  let fTimestamp = new firebase.firestore.Timestamp.fromDate(dateAdded)

  console.log('dateAdded', dateAdded)
  //console returns// dateAdded Sat Oct 15 2016 16:29:41 GMT+0100 (British Summer Time)
  console.log('Timestamp', fTimestamp) 
  //console returns// Timestamp uo {seconds: 1476545381, nanoseconds: 0}

  var queryTime = db.collection("Northern_Ireland").doc('2183').collection("reviews").doc('2573');
  queryTime.update({

    created_at: fTimestamp,
  //console returns//  RangeError: Invalid time value 
  
  
  })
  
  .then(function() {


    console.log("Document successfully updated!");
})
.catch(function(error) {
    // The document probably doesn't exist.
    console.error("Error updating document: ", error);
}); 

}
  

4) I then get the console error "RangeError: Invalid time value" more details in pic below and have read loads but can’t see anything that really explains why? It seems to me it has succeeded in creating the timestamp so at a loss why it won't update the document in Firestore. Maybe the formating is wrong of the core date field string it drives from Console error: console error

5) I have used the same process to update other fields with new string or integer data and have no probs so it seems something specific to the timestamp format

Many thanks if you can help me on this journey.

Daniel Mintz
  • 53
  • 1
  • 7

0 Answers0