Firestore dates written as strings, not Timestamps

Any updates here?

Unfortunately, I don't know of a workaround at the moment and there haven't been any updates yet :grimacing: will let you know here if that changes!

After pulling out my hair and trying and trying and pulling out more hair and shouting at my laptop, I decided to just give up and let Retool write dates as strings to Firestore. I use a function to overwrite the value with an actual date. As much as I love Retool, I hate having to work with it when dates and Firestore are involved. It shouldn't be so difficult!

Here's the override I had to do in Firestore to workaround this basic functionality which is not working properly in Retool:

exports.onCreateNewBus = functions.region('europe-west2').firestore.document('new_buses/{id}').onCreate(async (snapshot, context) => {
    const newBusData = snapshot.data()
    if (newBusData.hasOwnProperty('created')) {
        const type = typeof newBusData.created
        console.log(`newBusData has a property of created and it is ${newBusData.created} and type is ${type}`)

        if (newBusData.created instanceof String || type === 'string')
            await snapshot.ref.set({ created: admin.firestore.Timestamp.fromMillis(Date.parse(newBusData.created as string)) }, { merge: true })
    }
})

If the created field is a string, it will convert it to a date.

It should be quite obvious how much people are struggling. This topic is in the top viewed topics of this forum.

1 Like

Yeah, that feels dirty, but nice hack.